我一直在尝试重置MySQL的密码,但我找到的所有解决方案似乎都没有用。我正在使用OSX Yosemite和MAMP以及MySQL 5.6.20
我尝试通过MAMP将密码重置为pass
但不起作用
$mysql -u root -p
Enter password: pass
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
$
并且这一切都不起作用
$mysql -uroot
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
$mysql -u root
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
$mysql -u root@localhost
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 62
Server version: 5.6.20 Homebrew
Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> use magento
ERROR 1044 (42000): Access denied for user ''@'localhost' to database 'magento'
mysql> SET PASSWORD FOR 'root' = PASSWORD('pass');
ERROR 1044 (42000): Access denied for user ''@'localhost' to database 'mysql'
mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('pass');
ERROR 1044 (42000): Access denied for user ''@'localhost' to database 'mysql'
mysql> SET PASSWORD FOR 'root'@'::1' = PASSWORD('pass');
ERROR 1044 (42000): Access denied for user ''@'localhost' to database 'mysql'
答案 0 :(得分:5)
您可以使用--skip-grant-tables选项停止mysql服务器并重新启动它。这样,在打开mysql shell时它不会查看凭据
之后,
mysql> UPDATE mysql.user SET Password=PASSWORD('MyNewPass')
-> WHERE User='root';
mysql> FLUSH PRIVILEGES;
停止mysql服务器,然后重新启动
答案 1 :(得分:1)
只需在Justin的Kiang回答中添加一些细节(这对我有所帮助,谢谢!)。 在我的OS X机器上:
sudo /usr/local/mysql/support-files/mysql.server stop
sudo /usr/local/mysql/support-files/mysql.server start --skip-grant-tables
mysql -u root
然后根据Justin的回答SQL代码:
UPDATE mysql.user SET Password=PASSWORD('newpassword') WHERE User='root';
FLUSH PRIVILEGES;
bye
再次重启MySQL服务器:
sudo /usr/local/mysql/support-files/mysql.server stop
sudo /usr/local/mysql/support-files/mysql.server start
根据需要调整mysql文件夹的路径。