ERROR 1045 (28000): Access denied for user 'root'@'localhost'

回复 收藏
1. 编辑mysql主配置文件 my.cnf
vim /etc/my.cnf  
在[mysqld]字段下添加参数  skip-grant  
2. 重启数据库服务
service mysqld restart
3. 这样就可以进入数据库不用授权了
mysql -uroot
4. 修改相应用户密码
use mysql;
update user set password=password('your password') where user='root';
(如果这时候这里显示为空值,{Empty set (0.00 sec} 则需要重新初使化一下数据库;)
flush privileges;
5.  修改/etc/my.cnf 去掉 skip-grant , 重启mysql服务
2016-07-12 09:30 举报
已邀请:
0

san liu

赞同来自:

先把 mysql库目录改个名  mv /data/mysql/ ./mysql.bak
然后再执行   ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql  
再重复之前的步骤
重启数据库服务
service mysqld restart
3. 这样就可以进入数据库不用授权了
mysql -uroot
4. 修改相应用户密码
use mysql;
update user set password=password('your password') where user='root';
(如果这时候这里显示为空值,{Empty set (0.00 sec} 则需要重新初使化一下数据库;)
flush privileges;
5.  修改/etc/my.cnf 去掉 skip-grant , 重启mysql服务

回复帖子,请先登录注册

退出全屏模式 全屏模式 回复
评分
可选评分理由: