我不懂为什么我在网上找的解决方案千篇一律全是:
1、停止当前MysqL服务
/etc/init.d/MysqLd stop
或
service MysqLd stop
2、用户 --skip-grant-tables 选项启动MysqL
MysqLd_safe --user=MysqL --skip-grant-tables --skip-networking &
md,这命令有毒呀,执行之后,MysqL这个进程根本杀不死啦(害我回滚了好几次)。。。
还有些人执行这条命令:
sudo MysqLd_safe --skip-grant-tables &
虽然比上一个命令好一点,但是每次执行这条语句就会有多出3个与MysqL相关的进程,他还要我再kill这些进程,然后再执行这条
语句,这不是恶性循环吗???
还有人说:如果运行此语句没有回到上一级shell,则另外打开一个终端继续执行以下步骤即可。。。
然而仍然报如下错:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
3、登录
MysqL -u root MysqL
4、修改登录密码:修改yourPassword处即可
解决方案:
1、跳过密码进行登录
(2)重新启动MysqL:
update user set password=PASSWORD("yournewpassword") where User='root';
flush privileges;
exit
5、重启服务
/etc/init.d/MysqL restart6、此时即可正常登录
MysqL -u root -p然而我卡在第二步一直报如下错误:
MysqLd_safe Can't log to error log and syslog at the same time. Remove all --log-error configuration options for --syslog to take effect. MysqLd_safe Logging to '/var/log/MysqL/error.log'. MysqLd_safe A MysqLd process already exists
解决方案:
1、跳过密码进行登录
vim /etc/MysqL/my.cnf(1)在[MysqLd]的段中加上两句:
skip-name-resolve skip-grant-tables例如:
[MysqLd] datadir=/var/lib/MysqL socket=/var/lib/MysqL/MysqL.sock skip-name-resolve skip-grant-tables保存并且退出vim。
(2)重新启动MysqL:
service MysqL restart(3)登录并修改MysqL的root密码 :
/usr/bin/MysqL2、修改密码
use MysqL ;
update user set password=password("yournewpassword") where user='root';
flush privileges;
quit
3、将MysqL的登录设置修改回来
vim /etc/MysqL/my.cnf将刚才在[MysqLd]的段中加上的skip-name-resolve 、skip-grant-tables 删除 。
保存并且退出vim。
4、重新启动MysqL
skip-name-resolve
此语句用于跳过dns域名解析,在局域网连接时会更快捷。不过使用此命令,MysqL库的user表中的host须由原来localhost改为%,
否则不能连接数据库。
skip-grant-tables
此语句用于跳过user表权限检查,在忘记密码时可以直接登录数据库。
skip-grant-tables
此语句用于跳过user表权限检查,在忘记密码时可以直接登录数据库。