今天早上开机进入mysql就出问题了
# mysql -uroot -p Enter password: ERROR 1045 (28000): Access denied for user ‘root‘@‘localhost‘ (using password: YES) # mysql mysql> use mysql #不能用mysql ERROR 1044 (42000): Access denied for user ‘root‘@‘%‘ to database ‘mysql‘ mysql> use test #能用test Database changed mysql> SELECT user,host,password FROM user; ERROR 1044 (42000): Access denied for user ‘root‘@‘%‘ to database ‘mysql‘
好吧,退出,关闭mysql,使用安全模式
# service mysqld stop # mysqld_safe --user=mysql --skip-grant-tables --skip-networking & # mysql -u root mysql mysql> use mysql Database changed mysql> SELECT user,host,password FROM user; +-------------+----------------+-------------------------------------------+ | user | host | password | +-------------+----------------+-------------------------------------------+ | root | % | | | root | www.crwolf.com | *DF216F57F1F2066124E1AA5491D995C3CB57E4C2 | +-------------+----------------+-------------------------------------------+
那我之前的用户去哪了?
有主机:127.0.0.1,用户:root,密码为空
主机:::1,用户:root,密码为空
主机:localhost,用户为空,密码为空
这三个怎么给我自动删除了?
就像之前http24调用mysql的时候一样,我的root用户,密码为welcome,自动没了。
唉,删除匿名用户吧。这mysql怎么这么变幻无常呢。
mysql> drop user ‘root‘@‘%‘; #错误又来了 ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement mysql> flush privileges; Query OK, 0 rows affected (0.01 sec) mysql> drop user ‘root‘@‘%‘; #好了 Query OK, 0 rows affected (0.00 sec) mysql> SELECT user,host,password FROM user; +-------------+----------------+-------------------------------------------+ | user | host | password | +-------------+----------------+-------------------------------------------+ | root | www.crwolf.com | *DF216F57F1F2066124E1AA5491D995C3CB57E4C2 | +-------------+----------------+-------------------------------------------+ mysql> \q Bye
问题还没解决
# service mysqld start Starting MySQL [确定] # mysql -uroot -p Enter password: ERROR 1045 (28000): Access denied for user ‘root‘@‘localhost‘ (using password: YES)
再用一次安全模式
# service mysqld stop # mysqld_safe --user=mysql --skip-grant-tables --skip-networking & # mysql -u root mysql mysql> delete from user where USER=‘‘; Query OK, 0 rows affected (0.00 sec) mysql> flush privileges; Query OK, 0 rows affected (0.01 sec) mysql> \q Bye # service mysqld start Starting MySQL [确定] # mysql -uroot -p Enter password: ERROR 1045 (28000): Access denied for user ‘root‘@‘localhost‘ (using password: YES) # mysqladmin -uroot -p password ‘welcome‘ #改密码都不能改,要哭了 Enter password: mysqladmin: connect to server at ‘localhost‘ failed error: ‘Access denied for user ‘root‘@‘localhost‘ (using password: YES)‘
解决了,找了个高手帮忙
还是要进入安全模式
# service mysqld stop # mysqld_safe --user=mysql --skip-grant-table --skip-networking &
这边就先不动了,再新开一个终端
# mysql -uroot -pmysql mysql> use mysql Database changed
因为之前登录mysql出错时不是总显示
ERROR 1045 (28000): Access denied for user ‘root‘@‘localhost‘ (using password: YES)
既然你显示,那就创建一个root用户,主机为localhost,密码为welcome
mysql> insert user(host,user,password) VALUES (‘localhost‘,‘root‘,PASSWORD(‘welcome‘)); Query OK, 1 row affected, 3 warnings (0.00 sec) #我这创建成功了 mysql> select user,host,password FROM user; +-------------+----------------+-------------------------------------------+ | user | host | password | +-------------+----------------+-------------------------------------------+ | root | | *81F5E21E35407D884A6CD4A731AEBFB6AF209E1B | | root | localhost | *DF216F57F1F2066124E1AA5491D995C3CB57E4C2 | +-------------+----------------+-------------------------------------------+
如果这里显示错误的话
ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement
执行一下flush privileges,然后再创建
mysql> flush privileges;
然后再授权,一定要授权
mysql> GRANT all privileges ON *.* TO ‘root‘@‘localhost‘; Query OK, 0 rows affected (0.00 sec) mysql> flush privileges;
可以退出了
回到之前的终端
# service mysqld start # mysql -uroot -pwelcome Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 1 Server version: 5.5.36-log Source distribution Copyright (c) 2000, 2014, 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. mysql>
问题解决,我决定以后在mysql里面执行任何命令以后,都执行一下flush privileges这个命令,免得出错。反正每次执行命令后按两下向上的箭头,命令就出来了,也不耽误时间,还能避免出错。
时间: 2024-10-28 19:46:00