使用mysqladmin无法更改mysql的root用户密码,报错内容如下:
[root@redhat6 mysql]# mysqladmin password 'password'
mysqladmin: connect to server at 'localhost' failed
error: 'Access denied for user 'root'@'localhost' (using password: NO)'
停止mysqld服务,service mysqld stop
使用参数跳过密码检测后台启动mysql,启动之后直接就停止了。
[root@redhat6 ~]# mysqld_safe --skip-grant-tables$
Starting mysqld daemon with databases from /var/lib/mysql
STOPPING server from pid file /var/run/mysqld/mysqld.pid
110517 14:16:11 mysqld ended
没办法只好启动到前台
[root@redhat6 ~]# mysqld_safe --skip-grant-tables
Starting mysqld daemon with databases from /var/lib/mysql
重新打开一个终端,连上mysql,这时不需要密码,可以顺利修改密码了。
[root@redhat6 ~]# mysql -u root
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.0.77 Source distribution
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> update user set password=PASSWORD('password') where user='root';
Query OK, 3 rows affected (0.00 sec)
Rows matched: 3 Changed: 3 Warnings: 0
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> exit
Bye
使用正常方式启动mysql,使用刚刚设置的密码可以登录
[root@redhat6 ~]# 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.0.77 Source distribution
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql>
转载于:https://blog.51cto.com/itlaowu/959747