我无法登录 mysql,因为我忘记了(我丢失了!)安装 mysql 后收到的临时密码。所以我尝试了以下步骤,但它们没有帮助我:
- 我停止了 mysql 服务器
- 然后我在
/usr/local/mysql/support-files/
中创建了一个名为restore
的文件,在其中写入了以下行:SET PASSWORD为了 root@localhost=PASSWORD('');
- 最后我运行了这个命令:
sudo mysqld_safe --init-file=/usr/local/mysql/support-files/restore
但它停留在mysqld_safe 使用/usr/local/mysql/data 中的数据库启动 mysqld 守护进程
。但是我从系统偏好设置中检查了 mysql,它已经启动(显示“mysql 正在运行”) - 我尝试使用此命令
mysql -u root
再次登录 mysql,但仍然收到相同的错误:ERROR 1045 (28000): Access Beenied for user 'root'@ 'localhost'(使用密码:NO)
有人可以帮我解决这个问题吗?
最佳答案
试试这个
1. stop mysql server
2. sudo mysqld_safe --skip-grant-tables &
3. mysql -u root //it should not ask password
4. use mysql; //change to mysql db
5. update user set password=PASSWORD("secure password") where user='root';
or (depending on mysql version)
update user set authentication_string=password('secure password') where user='root';
6. flush privileges;
7. logout from mysql (quit)
8. start mysql server (mysql -u root -p)
关于mysql - 忘记临时mysql密码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35992412/