问题
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