Set root password after linux install mysql

After installing a new mysql in red hat 6.3, I found that the initial password root could not log in, and an error occurred

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

The solution is as follows:

#service mysqld stop  
#mysqld_safe --user=mysql --skip-grant-tables --skip-networking &

#mysql -u root mysql

mysql> UPDATE user SET Password=PASSWORD('newpassword') where USER='root';
mysql> FLUSH PRIVILEGES;
mysql> quit

service mysqld restart

# mysql -uroot -p
Enter password: <Enter the new password newpassword>

 

mysql> quit
Bye
[root@localhost Desktop]# mysql -u root -p;
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.1.73-log Source distribution

Copyright (c) 2000, 2013, 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.

 

 

Password change completed

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326847127&siteId=291194637