1. Close the mysql service
Whether you use /etc/init.d/mysqld stop or ps -ef|grep mysqld with the kill command, you must ensure that the mysql service is completely shut down.
Two, start the mysql service
Start the mysql service using the following command
mysqld --user=root --skip-grant-tables
After entering the command and pressing Enter, it will be stuck forever. Even if the current window is closed, use ps -ef|grep mysqld to check from other command line windows, the process is still there, normal.
3. Modify the root user password of mysql
1>Log in to the mysql database
Use the command mysql -uroot -p to log in to the database. At this time, you do not need to use a password to log in directly.
2> View the mysql.user table after login
3> Delete the root user
delete from mysql.user where user=’root’;
flush privileges;
commit;
4> Create a new root user
create user root;
5> Set a password for the root user
alter user 'root'@'%' identified by 'new password';
6> Empower the root user
grant all on *.* to ‘root’@’%’;
7>Update the permissions of the root user to empower other users
At this time, if the authorization operation is performed for other users, an error will be reported, indicating that the root user has no authorization authority.
select * from mysql.user where user = ‘root’\G;
You will find that the value of the Grant_priv field is N, and then you need to update the value of this field to Y
update mysql.user set Grant_priv=’Y’ where user=’root’;