To be able to modify the root password of MySQL, you must be able to connect to it. However, if you have forgotten your current MySQL database password or for some unknown reason it no longer works, you then find yourself in a dramatic situation.
Well, don't panic, in this article I'll show you how to fix this little problem. so here's how to change a MySQL password.
Before you begin, you must be logged into your Linux session as root. Then, you should stop the MySQL server with the following command:
# / etc / init.d / mysql stop
Then we will restart MySQL without password with this command:
mysqld_safe --skip-grant-tables &
We will then connect to MySQL with the command line client
mysql -u root
Now enter the following commands to update the root password (obviously replacing newpassword with yours):
mysql> use mysql; mysql> update user set password = PASSWORD ("newpassword") where user = "root"; mysql> flush privileges; mysql> quit
Now all that remains is to stop and restart MySQL in “normal” mode. To do this, enter:
/etc/init.d/mysql stop /etc/init.d/mysql start
Then connect with the MySQL client
mysql -u root -p
Enter your new password and you're done. 😉
Need help ? Ask your question, FunInformatique will answer you.