Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reset root password in MySQL 8

Tags:

mysql

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.

like image 540
Alexound Avatar asked Sep 27 '18 16:09

Alexound


2 Answers

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

like image 172
sajjadG Avatar answered Nov 15 '22 21:11

sajjadG


Just type the below command in your Phpmysql shell.

ALTER USER 'root'@'localhost' IDENTIFIED BY 'password'
like image 2
suvojit_007 Avatar answered Nov 15 '22 21:11

suvojit_007