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.
sudo service mysql stop
Find mysqld_safe location
To find the mysqld_safe location run the below command.
Start MySQL in Safe Mode
To start mysql in safe mode run the below command.
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:
mysql -u root -p
You don’t have to provide a password here, nice isn’t it!!
update mysql.user set authentication_string=password('myPassword') where user='xxx' and host='xxx';
(replace xxx with your own userID and password)
Start MySQL server
sudo service mysql start
Now you should be able to connect to root with your new password :
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.