Loss of the MySql Root password can be solved, thanks to small and very simple manipulations. I know what I’m talking about, I forgot my password myself.
You must connect as root on your server.
1 – Connect to the SSH server as root
#login:toto #password:toto
toto@osn:#
Go to root with the command :
toto@osn:#su -
First of all, you must stop the Mysql server, with the following command.
root@osn:#service mysql stop
Check that MySql services are stopped. Enter the following line :
#ps aux|grep mysqld
You can have that :
mysql 1600 2.0 0.3 1274128 61960 pts/0 Sl 15:51 0:38 /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib/mysql/plugin --user=mysql --skip-grant-tables --log-error=/var/log/mysql/error.log --pid-file=/var/run/mysqld/mysqld.pid --socket=/var/run/mysqld/mysqld.sock --port=3306
To stop the service
you’re going to kill him.
root@osn:# killall mysqld
Here is the command to access MySql without root password.
root@osn:#mysqld_safe --skip-grant-tables &
Here’s what it says:
root@osn:# 161115 15:51:31 mysqld_safe Can't log to error log and syslog at the same time. Remove all --log-error configuration options for --syslog to take effect. 161115 15:51:31 mysqld_safe Logging to '/var/log/mysql/error.log'. 161115 15:51:31 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
Just below
161115 15:51:31 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
Put mysql – u root
root@osn:#mysql -u root
MySql opens :
Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 27 Server version: 5.5.53-0+deb8u1 (Debian) Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved. 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>
Go to the mysql database :
mysql>use mysql;
Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Database changed
Pour changer le mot de passe, taper la ligne suivante :
mysql> UPDATE user SET Password=PASSWORD('Votre nouveau mot de passe ici') WHERE user='root';
Query OK, 3 rows affected (0.00 sec)
Rows matched: 3 Changed: 3 Warnings: 0
ATTENTION: REPLACE Your new password here with your own
Don’t forget to restore privileges
mysql> flush privileges; Query OK, 0 rows affected (0.00 sec)
You can leave mysql.
mysql> quit Bye
Finally, we need to restart the server, so that it can be taken into account.
root@osn:#service mysql start
http://osnetworking.com
0 Comments