如何将root密码设置为null
如何从MySQL命令行客户端将MySQL的root
用户的密码更改为null
(表示没有密码或''
)?
How can I change the password for root
user of MySQL to null
-- meaning no password or ''
-- from the MySQL command line client?
您可以通过以下五个简单步骤来恢复MySQL数据库服务器密码.
You can recover MySQL database server password with following five easy steps.
步骤1 :停止MySQL服务器进程.
Step # 1: Stop the MySQL server process.
第2步:使用--skip-grant-tables选项启动MySQL(mysqld)服务器/守护进程,使其不会提示输入密码.
Step # 2: Start the MySQL (mysqld) server/daemon process with the --skip-grant-tables option so that it will not prompt for password.
步骤3 :以root用户身份连接到mysql服务器.
Step # 3: Connect to mysql server as the root user.
步骤4 :设置新的mysql根帐户密码,即重置mysql密码.
Step # 4: Setup new mysql root account password i.e. reset mysql password.
第5步:退出并重新启动MySQL服务器.
Step # 5: Exit and restart the MySQL server.
以下是您需要为每个步骤键入的命令(以root用户身份登录):
Here are commands you need to type for each step (login as the root user):
步骤1 :停止mysql服务
Step # 1 : Stop mysql service
# /etc/init.d/mysql stop
输出:
Stopping MySQL database server: mysqld.
第2步:启动不带密码的MySQL服务器:
Step # 2: Start to MySQL server w/o password:
# mysqld_safe --skip-grant-tables &
输出:
[1] 5988
Starting mysqld daemon with databases from /var/lib/mysql
mysqld_safe[6025]: started
第3步:使用mysql客户端连接到mysql服务器:
Step # 3: Connect to mysql server using mysql client:
# mysql -u root
输出:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1 to server version: 4.1.15-Debian_1-log
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql>
第4步:设置新的MySQL root用户密码
Step # 4: Setup new MySQL root user password
mysql> use mysql;
mysql> update user set password=PASSWORD("NEW-ROOT-PASSWORD") where User='root';
mysql> flush privileges;
mysql> quit
第5步:停止MySQL服务器:
Step # 5: Stop MySQL Server:
# /etc/init.d/mysql stop
输出:
Stopping MySQL database server: mysqld
STOPPING server from pid file /var/run/mysqld/mysqld.pid
mysqld_safe[6186]: ended
[1]+ Done mysqld_safe --skip-grant-tables
第6步:启动MySQL服务器并对其进行测试
Step # 6: Start MySQL server and test it
# /etc/init.d/mysql start
# mysql
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
# mysql -u root -p
来源: http://www.cyberciti.biz/tips/recovery-mysql-root-password.html