Wednesday, 27 April 2022

Reset Mysql root Password Ubuntu 22.04


systemctl status mysql.service

systemctl stop mysql.service

ps -eaf|grep mysql


If mysqld_safe Directory '/var/run/mysqld' for UNIX socket file don't exists

sudo mkdir -p /var/run/mysqld

sudo chown mysql:mysql /var/run/mysqld


sudo mysqld_safe --skip-grant-tables &

[1] 28088

 2022-05-09T18:18:53.504935Z mysqld_safe Logging to '/var/log/mysql/error.log'.

2022-05-09T18:18:53.533285Z mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql

mysql -u root
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 8.0.29-0ubuntu0.22.04.2 (Ubuntu)

Copyright (c) 2000, 2022, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

mysql> UPDATE mysql.user SET authentication_string=null WHERE User='root';

Query OK, 1 row affected (0.01 sec)

Rows matched: 1  Changed: 1  Warnings: 0


mysql> flush privileges;

Query OK, 0 rows affected (0.00 sec)


mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'root_password';

Query OK, 0 rows affected (0.02 sec)


mysql> flush privileges;

Query OK, 0 rows affected (0.00 sec)


mysql> exit

Bye


sudo systemctl restart mysql.service 


mysql --version

mysql  Ver 8.0.29-0ubuntu0.22.04.2 for Linux on x86_64 ((Ubuntu))


No comments:

Post a Comment