用户工具

站点工具


liux:mysql_access_denied_for_user_root_localhost错误解决方法总结

问题描述

在ubuntu系统通过命令“mysql -u root -p nccs < idste.sql”还原数据库时会出现以下错误:

“Access denied for user 'root'@'localhost' (using password:YES)”

直接输入“mysql” 也回报类似的错误:应该是:

“Access denied for user 'ODBC'@'localhost' (using password:NO)”。

解决步骤

1、打开MySQL目录下的配置文件(我的目录是/etc/mysql/mysql.conf.d/mysqld.cnf, 可能有的系统是my.ini),在文件的最后添加一 行“skip-grant-tables”,保存并关闭文件。

2、重启MySQL服务(我用命令 service mysql restart)。

3、在命令行中输入“mysql -uroot -p”(不输入密码),回车即可进入数据库。

4、执行,“use mysql;”使用mysql数据库。

5、执行,“update user set authentication_string=PASSWORD(“iDste1057Hello”) where user='root';”(修改root的密码, 有的 mysql表列名可能是password, 需要是命令:“update user set password=PASSWORD(“iDste1057Hello”) where user='root';”)

6、打开MySQL目录下的配置文件文件,删除最后一行的“skip-grant-tables”,保存并关闭文件。

7、重启MySQL服务。( service mysql restart)

8、在命令行中输入“mysql -uroot -piDste1057Hello”,问题搞定!

liux/mysql_access_denied_for_user_root_localhost错误解决方法总结.txt · 最后更改: 2025/09/08 22:51 (外部编辑)