首先结束mysql进程,利用ps aux | grep mysql命令得到进程ID号,kill ID号,结束进程
其次,运行mysqld --skip-grant-tables
然后,再开一个终端,输入mysql -u root mysql
进去后,执行UPDATE user SET Password=PASSWORD('my_password') where USER='root';
再执行,FLUSH PRIVILEGES;
退出,重启mysql,然后你再运行mysql -u root -p输入你的密码,应该就OK了

注意:root用户进行强制启动;在启动过程中,加入参数:

--user=root

linux mysql access denied for user root

如果mysql不支持远程连接,会出现提示:错误代码是1130,ERROR 1130: Host * is not allowed to connect to this MySQL server ,

解决此问题有以下2个方法:

localhost改成%

进入mysql的BIN目录

 代码如下 复制代码

mysql -u root -p

mysql>use mysql;

mysql>update user set host =’%'where user =’root’;

mysql>flush privileges;

相关文章: