Mysql的常见几种错误:
一.在进入
mysql
数据库时出错
# mysql -u root -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
或者
# mysql -u root -p password 'newpassword'
Enter password:
mysqladmin: connect to server at 'localhost' failed
error: 'Access denied for user 'root'@'localhost' (using password: YES)'
出现此错误时:
1.
关闭
# service mysqld stop
2.
屏蔽权限
# mysqld_safe
--skip-grant-table
屏幕出现:
Starting demo from 或者 光标....
3.
新开起一个终端输入
# mysql -u root mysql
mysql> UPDATE user SET Password=PASSWORD('newpassword') where USER='root'; //注意大小写
mysql>
FLUSH PRIVILEGES;
记得这句命令不能忘,否则如果关闭先前的终端,又会出现原来的错误
mysql> q
退出后
# mysql -u root -p
使用新密码登录
二.在创建数据库时报错
mysql> create database haha;
ERROR 1044 (42000): Access denied for user ''@'localhost' to database 'haha'
mysql>
解决方案:
这是因为在mysql的usr表中,存在用户名为空的账户,虽然登陆时用的是root ,但 是匿名登陆
删除 user.user中值为NULL 的 ,或更新NULL为test
1)delete from user where user is NULL
2)update user set user='test' where user is NUL