the linux root password forgotten how to log in mysql

First, make sure the server is in secure mode, because during the change password database in the state is not password protected.
Proceed as follows:
 
1, shut down mysql service sc stop mysql
 
2, mysql start in Safe Mode
mysqld -- skip-grant-tables
Recommended for secure start by modifying the configuration file:
we /etc/my.cnf
Plus one in the [mysqld] paragraph: skip-grant-tables
Save and Exit
 
3. Restart mysqld
service mysqld restart
 
4, landing mysql
Direct input mysql -u root -p Enter, (ignoring password) and then press Enter;
 
5, change the root password
UPDATE mysql.user SET Password=PASSWORD('xxx') where USER='root';
There was an error change your password:
ERROR 1054 (42S22): Unknown column 'Password' in 'field list'
The reason : no Password field below Database
Solution :
Find a mysql database user table
      show databases;
      use mysql;
      show tables;
      select * from user;   
I found no Password field, Password field into a authentication_string
Use this field to change the root password again:
update mysql.user set authentication_string=password('xxx') where user='root' ;
Note: mysql version for the new store a user's password field named authentication_string instead of password, and new password must be encrypted using the password function
 
6, after completion and then change the password to open the configuration file, the skip-grant-tables commented.
we /etc/my.cnf
#skip-grant-tables
 
7, re-run mysql, you can use the new password to login.
service mysqld restart
 
 

Guess you like

Origin www.cnblogs.com/hupoykitty/p/11608481.html