Scale up as you grow — whether you're running one virtual machine or ten thousand.

From GPU-powered inference and Kubernetes to managed databases and storage, get everything you need to build, scale, and deploy intelligent applications.

This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
This tutorial made my mysql database to not function. now I can’t even restart it, my site doesn’t even work now because it can’t connect to the database.
Thank you very much for this tutorial. On CentOS with MySQL 5.7.17 when I launch the mysqld_safe --skip-grant-tables --skip-networking I get the folloqing message: mysqld_safe Directory ‘/var/run/mysqld’ for UNIX socket file don’t exist. After this, MySQL doesn’t start so when I try mysql -u root I get as an answer ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock’ (2). I’m stuck there as I cannot restart MySQL with --skip-grant-tables oprion enabled… Any clue?
I didn’t omit any part, I found that when you are logged into the root account of the operating system, mysql no longer asks to enter the password of the root account of mysql.
Thanks for your article, This is a very useful post for us. For information only, Other may users also have a look at this link http://www.ipragmatech.com/forgot-mysql-root-password, this link also contains very easy step to reset the password.
I dunno, this didn’t work for me.
For Step 2, the server is using MariaDB but none of the mariadb-specific commands worked. Also it doesn’t know what ‘systemctl’ is. I figured out though that I could stop the database with ‘sudo service mysql stop’ - that definitely stopped the service.
In Step 3, ‘sudo mysqld_safe --skip-grant-tables --skip-networking &’ did something, but it didn’t kick me back to the command line. Although I didn’t have to ctrl-c it either, just when I tried typing the next bit was when the new line appeared. Don’t know if that’s a problem or not, I’m just not used to command line stuff.
In Step 4, ‘FLUSH PRIVELEGES;’ said the query was ok, but 0 rows affected. Then again, I don’t know if this is supposed to affect any rows. Next, the recommended way of changing the password did not work. I used the method where it says it’s indicative of bigger problems (whatever that means), and that did work and affect 1 row. Or it didn’t work because the guide says it should say 0 rows affected?
For Step 5, neither of the sudo kill commands worked. And of course the systemctl commands don’t work to restart the database, so I did ‘sudo service start mysql’. It said MariaDB started.
Then I tried the final step with ‘mysql -u root -p’ but it says the password is wrong. So I don’t know what I changed (if anything) but yeah, the guide didn’t work for me. At least I don’t have the same problems as NUCUTA?
Edit: I managed to change the password following Rackspace’s guide (https://support.rackspace.com/how-to/mysql-resetting-a-lost-mysql-root-password/). It’s almost the same, don’t know if the different order of mysql commands made a difference. I still used my own commands to start/stop the mysql service though - ‘sudo service mysql start’ or ‘sudo service mysql stop’
I had the same problem when I forgot one of my MySQL instance root password. I reset it using this guide.
https://www.fossgeek.org/server-configuration/reset-mysql-root-password/
It’s working fine & In my case I had a CentOS 6 box. :)
This comment has been deleted
Thank you the tutorial was actually very helpful.
I just have one question, in step 4 there is a note saying: “Note: If the ALTER USER command doesn’t work, it’s usually indicative of a bigger problem.”
What’s the bigger problem that’s mentioned and how can i solve it.
In Step 5, to prevent mysql> from freezing, it’s best to write: quit or \q and then restart: 'sudo systemctl start mysql, instead of writing: sudo kill cat /var/run/mysqld/mysqld.pid