安装MySQL数据库: 注意:在安装过程中会几次要求你设置MySQL数据库的管理员用户密码,我们这里先不设置。(出现要求设置的页面时直接按“确定”即可。)linuxidc@leaf:~$ sudo apt-get install mysql-server mysql-client libmysqlclient-dev注意在你的系统上查看安装成功后的提示信息。 开启MySQL服务: linuxidc@leaf:~$ sudo service mysql start登陆到MySQL数据库中: linuxidc@leaf:~$ mysql -u root Welcome to the MySQL monitor. Commands end with ; or g. Your MySQL connection id is 7 Server version: 5.6.28-0ubuntu0.15.10.1 (Ubuntu)
Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners.
Type "help;" or "h" for help. Type "c" to clear the current input statement.
mysql>由于在安装的时候并没有为MySQL数据库的root用户设置密码,所以这里不用输入密码就可以进入到MySQL数据库中了。其实如果是非生产环境要求的话,像上面这样使用apt-get简单安装就可以了,当然如果是用于生产环境的,那么建议还是使用源码安装。2.MySQL安全优化至于为什么要安全优化,可以看博主写的用源码安装MySQL的博文:《在CentOS上源码安装MySQL+安装问题解决+安全优化》http://www.linuxidc.com/Linux/2016-03/129043.htm下面就直接给出操作的步骤。(注意:要确保MySQL服务已经开启,上面已经给出方法)(1)为root用户创建密码 linuxidc@leaf:~$ mysql -u root mysql> update mysql.user set password = password("123456") where User = "root"; mysql> update mysql.user set password = password("123456") where User = "root"; Query OK, 4 rows affected (0.00 sec) Rows matched: 4 Changed: 4 Warnings: 0
mysql> flush privileges; Query OK, 0 rows affected (0.00 sec)上面就为root用户创建了密码`123456`。 执行完之后再查看一下当前的账户信息: mysql> select User, Host, Password from mysql.user; +------------------+-----------+-------------------------------------------+ | User | Host | Password | +------------------+-----------+-------------------------------------------+ | root | localhost | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 | | root | leaf | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 | | root | 127.0.0.1 | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 | | root | ::1 | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 | | debian-sys-maint | localhost | *6A368D614E978D78292FC3257D3958C6A7B241EF | +------------------+-----------+-------------------------------------------+ 5 rows in set (0.00 sec)需要注意的是,由于我们已经为root用户设置了密码,所以在下次登陆的时候请指定-p参数:linuxidc@leaf:~$ mysql -u root -p Enter password:密码就是我们设置的`123456`。(2)删除test数据库或名字以test开头的数据库 操作如下:mysql> delete from mysql.db where db like "test%"; Query OK, 0 rows affected (0.00 sec)