Reset root password in MySQL 8

余生长醉 提交于 2021-02-07 17:55:14

问题


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.

It gives the following error.

[Server] Could not open /var/log/mysqld.log file for error logging: Permission denied.

Permissions are correct.

Server starts when I use service mysqld start.

I am using MySQL 8.0.12 on Fedora 28.


回答1:


If you can log in to your MySQL server and you want to change your password by query you can do it this queries:

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

or removing the root password:

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

Thanks to this blog: https://juejin.im/entry/5b06698cf265da0db3501fdd

Also answered the same question here: https://stackoverflow.com/a/54511940/1157720




回答2:


Just type the below command in your Phpmysql shell.

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



回答3:


You need to be the owner or group of /var/log/mysqld.log before you can do this. 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.

You may need to become root (OS root user, not mysql root) to do this, depending on how your system was setup.

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://stackoverflow.com/questions/52541700/reset-root-password-in-mysql-8

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!