我进入了/usr/share/mysql执行mysql -uroot -p好像不行: root@wantianwen-desktop:/usr/share/mysql# mysql -uroot -p Enter password: ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES) root@wantianwen-desktop:/usr/share/mysql# mysql -uroot -p Enter password: ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
用这种方法的确进入了MySQL,发现mysql.user表中没有root用户,我现在运行这个语句出错: mysql> GRANT ALL PRIVILEGES ON *.* TO root@localhost IDENTIFIED BY '123' WITH GRANT OPTION; ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement
我又用另外一种方法:向mysql.user表中插入了一条记录(超级用户),如下: INSERT INTO user VALUES('%','root','123','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','','','','',0,0,0,0);然后去掉了my.cnf中的skip-grant-table,重启MySQL,登录的时候还是报错: root@wantianwen-desktop:/home/wantianwen# mysql -uroot -p123 ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
上面密码忘记加密了,Sql语句应该是这样的: INSERT INTO user VALUES('%','root',PASSWORD('123'),'Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','','','','',0,0,0,0); 再次感谢 ydage 的帮助。
root@wantianwen-desktop:/usr/share/mysql# mysql -uroot -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
root@wantianwen-desktop:/usr/share/mysql# mysql -uroot -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
重启mysql服务(或者重启机器)后,就可以不用密码进入mysql
用这种方法的确进入了MySQL,发现mysql.user表中没有root用户,我现在运行这个语句出错:
mysql> GRANT ALL PRIVILEGES ON *.* TO root@localhost IDENTIFIED BY '123' WITH GRANT OPTION;
ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement
INSERT INTO user VALUES('%','root','123','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','','','','',0,0,0,0);然后去掉了my.cnf中的skip-grant-table,重启MySQL,登录的时候还是报错:
root@wantianwen-desktop:/home/wantianwen# mysql -uroot -p123
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
上面密码忘记加密了,Sql语句应该是这样的:
INSERT INTO user VALUES('%','root',PASSWORD('123'),'Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','','','','',0,0,0,0);
再次感谢 ydage 的帮助。