After installing the MySql server and setting the root user password of MySql, we started using it directly. In fact, there are still some insecure factors in such a MySql server, this article demonstrates how to use the command mysql_secure_installation to safely initialize our MySql server.
01 [root @ test ~] #/Usr/bin/mysql_secure_installation
02 NOTE: running all parts of this script is recommended for all MySQL
03 servers in production use! Please read each step carefully!
04
05 In order to log into MySQL to secure it, we'll need the current
06 password for the root user. If you 've just installed MySQL, and
07 you haven't set the root password yet, the password will be blank,
08 so you shoshould just press enter here.
09
10 Enter current password for root (enter for none): <--- Enter the current root password, because we have not set it, press enter.
11 OK, successfully used password, moving on...
12
13 Setting the root password ensures that nobody can log into the MySQL
14 root user without the proper authorisation.
15
16 Set root password? [Y/n] Y <--- whether to set the root password. Of course, enter Y and press Enter.
17 New password: <--- enter the root password and press Enter. No display is displayed during the input.
18 Re-enter new password: <--- enter the root password again and press enter.
19 Password updated successfully!
20 Reloading privilege tables ..
21... Success!
22
23 By default, a MySQL installation has an anonymous user, allowing anyone
24 to log into MySQL without having to have a user account created
25 them. This is intended only for testing, and to make the installation
26 go a bit smoother. You shoshould remove them before moving into
27. production environment.
28
29 Remove anonymous users? [Y/n] Y <--- whether to delete anonymous users, delete, enter Y and press ENTER
30... Success!
31
32 Normally, root shoshould only be allowed to connect from 'localhost'. This
33 ensures that someone cannot guess at the root password from the network.
34
35 Disallow root login remotely? [Y/n] Y <--- whether to delete or disable remote logon by the root user. Of course, disable remote logon by entering Y and press Enter.
36... Success!
37
38 By default, MySQL comes with a database named 'test' that anyone can
39 access. This is also intended only for testing, and shocould be removed
40 before moving into a production environment.
41
42 Remove test database and access to it? [Y/n] <--- whether to delete the test database, delete it, and enter Y and press Enter.
43-Dropping test database...
44... Success!
45-Removing privileges on test database...
46... Success!
47
48 Reloading the privilege tables will ensure that all changes made so far
49 will take effect immediately.
50
51 Reload privilege tables now? [Y/n] Y <--- refresh permission, enter Y and press ENTER
52... Success!
53
54 Cleaning up...
55
56 All done! If you 've completed all of the above steps, your MySQL
57 installation shoshould now be secure.
58
59 Thanks for using MySQL!