Created
July 27, 2023 10:31
-
-
Save ayoubjamouhi/c679e9442ee26f2902d268fb068f9c96 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
step1. Stop your databases | |
service mysqld stop | |
step2. Modify /etc/my.cnf file add "skip-grant-tables" | |
vi /etc/my.cnf | |
[mysqld] | |
skip-grant-tables | |
step3. Start mysql | |
service mysqld start | |
step4. Select mysql default database | |
mysql -u root | |
mysql>use mysql; | |
step4. Set a new password | |
mysql> update user set authentication_string=PASSWORD("yourpassword") where User='root'; | |
step5. Remove skip-grant-tables from /etc/my.cnf file. | |
step6. Restart mysql database | |
service mysqld restart | |
mysql -u root -p | |
//////// | |
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. | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment