recover MySQL root password with mysqld_safe
2014-02-24 10:51
399 查看
http://newexception.com/recover-mysql-root-password
In order to recover MySQL root password you need to do this five easy steps.
1. Stop MySQL server
2. Start MySQL in safe mode
3. Change MySQL root password
4. Stop MySQL safe mode
5. Start MySQL server
Stop MySQL server
To stop MySQL server under Ubuntu / Debian use one of the following commands:
#service mysql stop
If that doesn't work, you can still kill the mysqld process
#killall mysql
or
#kill -9 PID
where PID is the process id of the MySQL daemon
Start MySQL in safe mode
#mysqld_safe --skip-grant-tables
or
#mysql_safe --skip-grant-tables &
The first command will start MySQL in safe mode and you will need to keep the terminal open. The second command will put MySQL in background.
Change MySQL root password
Login to MySQL as root
#mysql -u root -p
mysql> USE mysql;
mysql> UPDATE user SET password = PASSWORD("new_password") WHERE User = 'root';
What we have done here is we told MySQL that we are going to use the MySQL database, because all settings regarding MySQL are stored in this database.
Stop MySQL safe mode
Go back to the terminal where you started MySQL in safe mode and press CTRL + C. If you used the second command, you will need to kill the process.
#killall mysqld_safe
Note: Before proceeding, be sure that MySQL is not running.
Start MySQL server
#sudo service mysql start
You are done. Now you can login to MySQL with your new password.
Recover MySQL root password with debian-sys-maint user
Another way to recover the root password is by login with the debian-sys-maint user, which will work only in Ubuntu / Debian. You can find this info in the debian.cnf file which is located under /etc/mysql.
# Automatically generated for Debian scripts. DO NOT TOUCH!
[client]
host = localhost
user = debian-sys-maint
password = PASSWORD
socket = /var/run/mysqld/mysqld.sock
[mysql_upgrade]
host = localhost
user = debian-sys-maint
password = PASSWORD
socket = /var/run/mysqld/mysqld.sock
basedir = /usr
Simply login with debian-sys-maint user and enter the password which is specified in the debian.cnf file
#mysql -u debian-sys-maint -p
Thanks to Regis Caspar for pointing this out.
In order to recover MySQL root password you need to do this five easy steps.
1. Stop MySQL server
2. Start MySQL in safe mode
3. Change MySQL root password
4. Stop MySQL safe mode
5. Start MySQL server
Stop MySQL server
To stop MySQL server under Ubuntu / Debian use one of the following commands:
#service mysql stop
If that doesn't work, you can still kill the mysqld process
#killall mysql
or
#kill -9 PID
where PID is the process id of the MySQL daemon
Start MySQL in safe mode
#mysqld_safe --skip-grant-tables
or
#mysql_safe --skip-grant-tables &
The first command will start MySQL in safe mode and you will need to keep the terminal open. The second command will put MySQL in background.
Change MySQL root password
Login to MySQL as root
#mysql -u root -p
mysql> USE mysql;
mysql> UPDATE user SET password = PASSWORD("new_password") WHERE User = 'root';
What we have done here is we told MySQL that we are going to use the MySQL database, because all settings regarding MySQL are stored in this database.
Stop MySQL safe mode
Go back to the terminal where you started MySQL in safe mode and press CTRL + C. If you used the second command, you will need to kill the process.
#killall mysqld_safe
Note: Before proceeding, be sure that MySQL is not running.
Start MySQL server
#sudo service mysql start
You are done. Now you can login to MySQL with your new password.
Recover MySQL root password with debian-sys-maint user
Another way to recover the root password is by login with the debian-sys-maint user, which will work only in Ubuntu / Debian. You can find this info in the debian.cnf file which is located under /etc/mysql.
# Automatically generated for Debian scripts. DO NOT TOUCH!
[client]
host = localhost
user = debian-sys-maint
password = PASSWORD
socket = /var/run/mysqld/mysqld.sock
[mysql_upgrade]
host = localhost
user = debian-sys-maint
password = PASSWORD
socket = /var/run/mysqld/mysqld.sock
basedir = /usr
Simply login with debian-sys-maint user and enter the password which is specified in the debian.cnf file
#mysql -u debian-sys-maint -p
Thanks to Regis Caspar for pointing this out.
相关文章推荐
- Mysql初始安装(解压版)在运行mysqld --initialize初始化数据库后,再用root登陆报using password: no异常解决
- windows环境中mysql忘记root密码的解决办法 (不用mysqld-nt.exe)+找不到password
- Recover lost root password in mysql
- Recover MySQL root Password
- mysql集群:1045-Access denied for user 'root'@'localhost'(using password:YES)
- 解决MySql登录错误ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
- MySQL彻底删除,且重装时跳过current root password输入
- MySQL 5.6 root密码丢失,使用mysqld --skip-grant-tables
- mysql问题ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
- MySQL改密码报错:ERROR 1045: Access denied for user: 'root@localhost' (Using password: YES)
- windows mysql提示:1045 access denied for user 'root'@'localhost' using password yes 和ERROR 1820解决办法wan
- MySQL问题 Access denied for user 'root'@'localhost' (using password: YES)
- MySql Access denied for user 'root'@'localhost' (using password: YES)
- mysql启动提示 access denied for user root@localhost(using password:YES)
- MYSQL安装时解决要输入current root password的解决方法
- Linux mysql 5.6: ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
- Mysql没有初始密码(ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO))
- mysql中Access denied for user 'root'@'localhost' (using password:YES)
- MySQL 5.7版 解决密码登录失败Access denied for user 'root'@'localhost' (using password: NO)
- mysql / mysqld_safe / mysqld 常见错误处理