Install MySQL + Security optimization with apt-get on Ubuntu
0. Description
The advantage of using apt-get for installation is that you don't have to solve the dependency problem between software by yourself. Basically, after apt is executed, the software has been installed, the following describes how to use apt to install MySQL and Security Optimization after installation.
Note: The following operations are demonstrated by the newly installed Ubuntu 15.10.
1. Use apt to install MySQL
Install MySQL database:
Note: You are required to set the administrator password of the MySQL database several times during the installation process. We will not set the password here. (When a page needs to be set appears, simply press "OK .)
Bkjia @ leaf :~ $ Sudo apt-get install mysql-server mysql-client libmysqlclient-dev
Check the prompt message after successful installation on your system.
Start the MySQL service:
Bkjia @ leaf :~ $ Sudo service mysql start
Log on to the MySQL database:
Bkjia @ 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,201 5, 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>
Because no password is set for the root user of the MySQL database during installation, you do not need to enter the password to enter the MySQL database.
In fact, if it is not required by the production environment, use apt-get for simple installation as above. Of course, if it is used in the production environment, we recommend that you use the source code for installation.
2. MySQL Security Optimization
For more information about the security optimization, see the blog post "Install MySQL with source code" written by the blogger: "Install MySQL with source code on CentOS + solve Installation Problems + Security optimization".
The following describes the procedure. (Note: Make sure that the MySQL service is enabled. The above method is provided)
(1) create a password for the root user
Bkjia @ leaf :~ $ Mysql-u root
Mysql> update mysql. user set password = password ('000000') where User = 'root ';
Mysql> update mysql. user set password = password ('000000') 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)
The above Code creates the password '000000' for the root user '.
After the execution, check the current account information:
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 | * 6a424d614e978d78292fc3257d3958c6a7b241ef |
+ ------------------ + ----------- + ------------------------------------------- +
5 rows in set (0.00 sec)
Note that because we have set a password for the root user, please specify the-p parameter during the next login:
Bkjia @ leaf :~ $ Mysql-u root-p
Enter password:
The password is set to '123 '.
(2) Delete the test database or the database whose name starts with test.
The procedure is as follows:
Mysql> delete from mysql. db where db like 'test % ';
Query OK, 0 rows affected (0.00 sec)
Mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
OK. Now, you can use apt-get to install MySQL and basic security Optimization of MySQL. There should be no major problems.