Exit MySQL Method
Quit or exit
Set up and modify Mysqlroot user password
After installing MySQL, the default administrator root password is empty, which is not secure, you need to set a password, after installing MySQL Single instance, there are some initial optimization of the security measures:
- Password was set for root
- Delete the user account in the useless MySQL library.
- Delete the test database that exists by default
In addition to the above methods, for MySQL database user processing, we also have more stringent practices as follows:
Add system and promote to Super Administrator, that is, the user with root equivalent, but the name is different.
Mysql>grant all Privileges "to [e - mail protected] ' localhost ' identified by ' 123456 ' with GRANT option;
Query OK, 0 rows Affected (0.00 sec)
Delete all users in MySQL, including root super user.
Mysql>delete from Mysql.user;
Query OK, 2 rows Affected (0.00 sec)
To set the password method for the administrator root user
Modify Administrator root password method one: command-line Modification method
- Mysqladmin-u root-p ' 123456 ' password ' dc123456 '
- Mysqladmin-u root-p ' 123456 ' password ' dc123456 '-s/data/3306/mysql.sock <----suitable for multi-instance mode
Modify Administrator root password method two: SQL statement modification method
Modify Administrator root Password method three
After the MySQL installation is complete, the root default password is empty and the root password needs to be changed immediately:
After modifying the password operation, flush privileges should be performed;
Recover lost MySQL root user password start modify missing MySQL Single instance root password method
- Stop MySQL First
- [[email protected] ~]#/etc/init.d/mysqld stop
- Use--skip-grant-tables to log in to MySQL, ignoring authorization login verification.
- [Email protected] ~]# mysqld_safe--skip-grant-tables--user=mysql &
- [[email protected] ~]# MySQL <----login time password
- Use update to modify the root password, you cannot use Mysqladmin password to modify, because the original password needs to be provided.
- Mysql>update Mysql.user Set Password=password ("dc123456") where user= ' root ' and host= ' localhost '; <----Change Password
- Flush privileges; <----Refresh Permissions
- Mysql>quit
- mysqladmin-uroot-pdc123456 Shutdown <----close MSYQL
- /etc/init.d/mysqld Start <----must be restarted
- mysql-uroot-pdc123456 <-----New Password Login
提示:在启动时加--skip-grant-tables参数,表示忽略授权表验证。
Multi-instance MySQL startup modify lost root password method
- Turn off MySQL
- Add--skip-grant-tables parameter at startup
- Mysqld_safe--defaults-file=/data/3306/my.cnf--skip-grant-table &
- Mysql-uroot-p-s/data/3306/mysql.sock <----login time password
- Modify Password method
- Mysql>update Mysql.user Set Password=password ("dc123456") where user= ' root ' and host= ' localhost '; <----Change Password
- Flush privileges; <----Refresh Permissions
- Mysql>quit
- [[email protected] ~]# mysqladmin-uroot-pdc123456 shutdown <----close MSYQL
- [[email protected] ~]#/ETC/INIT.D/MYSQLD Start <----must be rebooted to start normally.
- [[email protected] ~]# mysql-uroot-pdc123456 <-----new Password Login
2018-03-28 set up and modify MySQL user password learning notes