简体   繁体   English

在 MySQL 8 中重置 root 密码

[英]Reset root password in MySQL 8

When I use the method to reset the root password described on How to Reset the Root Password , starting the server with mysqld --init-file=/home/username/init-file doesn't work.当我使用如何重置根密码中描述的方法重置根密码时,使用mysqld --init-file=/home/username/init-file启动服务器不起作用。

It gives the following error.它给出了以下错误。

[Server] Could not open /var/log/mysqld.log file for error logging: Permission denied. [服务器] 无法打开 /var/log/mysqld.log 文件以进行错误记录:权限被拒绝。

Permissions are correct.权限是正确的。

Server starts when I use service mysqld start .当我使用service mysqld start时服务器service mysqld start

I am using MySQL 8.0.12 on Fedora 28.我在 Fedora 28 上使用 MySQL 8.0.12。

If you can log in to your MySQL server and you want to change your password by query you can do it this queries:如果您可以登录到您的 MySQL 服务器并且您想通过查询更改您的密码,您可以执行以下查询:

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456';

or removing the root password:或删除root密码:

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '';

Thanks to this blog: https://juejin.im/entry/5b06698cf265da0db3501fdd感谢这个博客: https : //juejin.im/entry/5b06698cf265da0db3501fdd

Also answered the same question here: https://stackoverflow.com/a/54511940/1157720也在这里回答了同样的问题: https : //stackoverflow.com/a/54511940/1157720

只需在您的 PHPmysql shell 中键入以下命令。

ALTER USER 'root'@'localhost' IDENTIFIED BY 'password'

You need to be the owner or group of /var/log/mysqld.log before you can do this.在执行此操作之前,您需要成为 /var/log/mysqld.log 的所有者或组。 It's crashing because it can't write to it's log file.它崩溃了,因为它无法写入它的日志文件。

If you do ls -l /var/log/mysqld.log you can see who owns it, then do su - username before attempting to start mysql.如果你执行ls -l /var/log/mysqld.log你可以看到谁拥有它,然后在尝试启动 mysql 之前执行su - username

You may need to become root (OS root user, not mysql root) to do this, depending on how your system was setup.您可能需要成为 root(操作系统 root 用户,而不是 mysql root)才能执行此操作,具体取决于您的系统设置方式。

Here is what the permissions and ownership is supposed to be:以下是权限和所有权应该是什么:

https://dev.mysql.com/doc/mysql-secure-deployment-guide/5.7/en/secure-deployment-permissions.html https://dev.mysql.com/doc/mysql-secure-deployment-guide/5.7/en/secure-deployment-permissions.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM