MySql ERROR 1044 (42000) 错误解决

mysql> use mysql
ERROR 1044 (42000): Access denied for user ''@'localhost' to database 'mysql'


原因:mysql数据库的user表里,存在用户名为空的账户即匿名账户,导致登录的时候是虽然用的是root,但实际是匿名登录的,通过错误提示里的''@'localhost'可以看出来


方法一:
1.关闭mysql
# service mysql stop
2.屏蔽权限登陆,修改密码
# mysqld_safe --skip-grant-table
140729 00:10:28 mysqld_safe Logging to '/home/mysql/error.log'.
140729 00:10:28 mysqld_safe Starting mysqld daemon with databases from /home/mysql/data
# mysql -u root mysql
mysql> UPDATE user SET Password=PASSWORD('newpassword') where USER='root';
mysql> FLUSH PRIVILEGES;
mysql> \q


方法二:
1.关闭mysql
# service mysqld stop
2.屏蔽权限登陆,删除空用户
# mysqld_safe --skip-grant-table
140729 00:10:28 mysqld_safe Logging to '/home/mysql/error.log'.
140729 00:10:28 mysqld_safe Starting mysqld daemon with databases from /home/mysql/data
# mysql -u root mysql
mysql> delete from user where USER='';
mysql> FLUSH PRIVILEGES;
mysql> \q 

你可能感兴趣的:(mysql,mysql,ERROR,1044,42000,错误解决)