This article contains information about mysql safe mode such as start mysql in safe mode, find mysqld_safe location, changing password.
MySQL Safe Mode
Sometime you want to connect to your DB server without password because:
- You forgot your password
- The server is not responding properly
- You get Access denied for user ‘xx’@’xxx’ (using password: YES)
- The mysql.user table is corrupt
- Take the database offline for all client
- Many more …
In this article let assume we forgot our userID password and would like to reset it.
Stop MySQL
1 | sudo service mysql stop |
Find mysqld_safe location
To find the mysqld_safe location run the below command.
1 | which mysqld_safe |
Start MySQL in Safe Mode
To start mysql in safe mode run the below command.
1 | sudo [/location_of_mysqld_safe]/mysqld_safe --skip-grant-tables--skip-networking |
–skip-grant-tables: This option causes the server to start without using the privilege system at all, which gives anyone with access to the server unrestricted access to all databases
–skip-networking : This option will block TCP/IP Connection to MySQL except local connection.
This will be an ongoing command until the process is finished so open another shell/terminal window, log in without a password:
1 | mysql -u root -p |
You don’t have to provide a password here, nice isn’t it!!
1 | update mysql.user set authentication_string=password('myPassword') where user='xxx' and host='xxx'; |
(replace xxx with your own userID and password)
1 2 3 | flush privileges; quit; |
Start MySQL server
1 | sudo service mysql start |
Now you should be able to connect to root with your new password :
1 | mysql -u root -p |
Give it a try in your development environment at first. Do not forget trying everything on development first.
You can find many more article about MySQL and many databases at dbtut. Use our navigation menu to reach every article you need or our search section on the upper right.