I am trying to reset the root password following MysqlPasswordReset but when I try to start the server with --skip-grant-tables the server doesn\'t start
For Ubuntu 19 with MySQL 8.0.17-0ubuntu2, what ended up working for me was a combination of many answers:
In the MySQL's configuration file (/etc/mysql/mysql.conf.d/mysqld.cnf
on my machine), under [mysqld]
, add:
skip-grant-tables = 1
plugin-load-add = auth_socket.so
Restart the MySQL Service;
Connect to MySQL: mysql -uroot
;
Run:
UPDATE mysql.user SET authentication_string=null WHERE User='root'; FLUSH PRIVILEGES; ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'pass123';
Stop MySQL and comment skip-grant-tables
in the configuration file;
Start MySQL again and this should now work: mysql -u root -ppass123
.
I found that the mysql.sock is deleted when the mysql service is stoped and mysqld_safe can't create it (I couldn't find the reason), so my solution was back up the sock folder and restore before start mysqld_safe
Start server
$ sudo service mysql start
Go to sock folder
$ cd /var/run
Back up the sock
$ sudo cp -rp ./mysqld ./mysqld.bak
Stop server
$ sudo service mysql stop
Restore the sock
$ sudo mv ./mysqld.bak ./mysqld
Start mysqld_safe
$ sudo mysqld_safe --skip-grant-tables --skip-networking &
Init mysql shell
mysql -u root
Change password
FLUSH PRIVILEGES;
SET PASSWORD FOR root@'localhost' = PASSWORD('my_new_password');
pedronalbert's answer above worked for me but the last step is now deprecated and throws the following warning:
Warning | 1287 | 'SET PASSWORD FOR = PASSWORD('')' is deprecated and will be removed in a future release. Please use SET PASSWORD FOR = '' instead
Use this command instead:
SET PASSWORD FOR root = '<plaintext_password>';
I tried many ways including @pedronalbert 's but still not working.
The way I solved it is adding "skip-grant-tables" in /etc/my.cnf then start mysql service and connecting mysql with "mysql -u root" as https://www.codero.com/knowledge-base/content/33/296/en/how-to-reset-your-root-mysql-password.html
It works in my VM CentOS 7.