欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

MySql数据库的ERROR1044(42000)错误问题解决办法

程序员文章站 2022-04-12 21:54:21
mysql> use mysql ERROR 1044 (42000): Access denied for user ''@'localhost&...

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