[root@localhost bin]# mysql
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
运行mysql时提示如上错误,百度下是密码不匹配,试着删除重新安装依然无法解决。所以想初始化数据库的密码,方法如下。
1.停止服务
service mysqld stop
2.mysqld_safe --user=mysql --skip-grant-tables --skip-networking &
提示: 160511 10:22:55 mysqld_safe Logging to '/var/log/mysqld.log'.
160511 10:22:55 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
3. mysql -u root mysql
4.mysql> update user set password=PASSWORD("rootadmin") where user='root';
rootadmin为新密码
5.mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> quit
6.[root@localhost /]# mysql -uroot -p
Enter password:
新密码登录 oK.
阅读(1513) | 评论(0) | 转发(0) |