I know some other administrator who has forgotten the password of the root of MySQL, this can be a real inconvenience, right?
Imagine that you need to create a new database, do anything and you can't because you don't remember the password of the administrator (root) of the MySQL server, a real problem.
Here I will show you how to access the MySQL server through the terminal WITHOUT setting the root password, so that once inside you can change the root password.
The first thing will be to stop the mysql service:
service mysql stop
This stopped the service, now we are going to start it but in a different way, a way that will not ask us for a password later:
mysqld_safe --skip-grant-tables &
Ready, now let's access the MySQL terminal:
mysql -u root
They will see that it did not ask for a password, they will see that they have already entered the MySQL console or terminal and can do whatever they want, let's proceed to change the MySQL root password.
First we will enter the MySQL database as such:
use mysql;
Then, let's change the password:
update user set password=PASSWORD("ElNuevoPassword") where user='root';
Now let's refresh the privileges:
flush privileges;
And finally we go out:
quit;
Ready, we have changed the password of the MySQL root user, now we are going to stop the service and start it as it should be:
service mysql stop
service mysql start
End
This is all, they have regained control of their own MySQL server
Very good tip, thanks
Excellent, great!
to wait for it to happen to me to try it, nothing good tips
Excellent
very good article, a hug !!
Very useful, you just got me out of a tight spot. Thank you.
Very useful, you got me out of a tight spot, thanks!
This solution has worked for me many times, but now I have a newly installed mysql engine and I tried to set the password, however it tells me that the "password" field does not exist, check the structure and the field does not really exist. Any idea how to fix it?
Thank you, you have saved me by being able to regain control of my mysql ...
I worked out of ten thousand thanks.
Well, you have solved my problem. Thank you!
The last 4 steps make a difference thank you very much
Thanks it worked very well for me however I had an error after the first command with the following message:
mysqld_safe Directory '/ var / run / mysqld' for UNIX socket file don't exist
Creating the directory solved the problem and I was able to complete the change of password, I share the commands in case it happens to someone.
mkdir -p / var / run / mysqld
chown mysql: mysql / var / run / mysqld
Too good
Thank you very much for the article.
It helped me to recover the test databases of a raspberry pi in which I have installed a LAMP server for a long time.