mysql - 忘记临时mysql密码

标签 mysql authentication

我无法登录 mysql,因为我忘记了(我丢失了!)安装 mysql 后收到的临时密码。所以我尝试了以下步骤,但它们没有帮助我:

  1. 我停止了 mysql 服务器
  2. 然后我在 /usr/local/mysql/support-files/ 中创建了一个名为 restore 的文件,在其中写入了以下行: SET PASSWORD为了 root@localhost=PASSWORD('');
  3. 最后我运行了这个命令:sudo mysqld_safe --init-file=/usr/local/mysql/support-files/restore 但它停留在 mysqld_safe 使用/usr/local/mysql/data 中的数据库启动 mysqld 守护进程。但是我从系统偏好设置中检查了 mysql,它已经启动(显示“mysql 正在运行”)
  4. 我尝试使用此命令 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/

相关文章:

authentication - 通过 JNDIRealm 引用问题对 tomcat 进行事件目录身份验证

php - 从列表中列出一类

php - Mysql查询插入使用等号

angular - Angular 7 和 CAS 身份验证的提示?

使用本地用户帐户在 Windows 上进行基于 PHP 表单的身份验证

php - 管理员用户名/密码不适用于 PHP

php - 如何在 phpMyAdmin 中编写存储过程?

mysql - Node.js - 如何通过 AJAX 传递多个 MySQL 查询参数

mysql - SQL Server Management Studio 查看和更改表

php - 无法访问或分配登录用户名变量 - mysql - php