MySQL 如何将root密码设置为空
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2101694/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to set root password to null
提问by Stormshadow
How can I change the password for root
user of MySQL to null
-- meaning no password or ''
-- from the MySQL command line client?
如何root
将 MySQL 用户的密码更改为null
-- 意味着没有密码或''
-- 从 MySQL 命令行客户端?
采纳答案by Vladislav Rastrusny
You can recover MySQL database server password with following five easy steps.
您可以通过以下五个简单步骤恢复 MySQL 数据库服务器密码。
Step # 1: Stop the MySQL server process.
第 1 步:停止 MySQL 服务器进程。
Step # 2: Start the MySQL (mysqld) server/daemon process with the --skip-grant-tables option so that it will not prompt for password.
第 2 步:使用 --skip-grant-tables 选项启动 MySQL (mysqld) 服务器/守护进程,这样它就不会提示输入密码。
Step # 3: Connect to mysql server as the root user.
第 3 步:以 root 用户身份连接到 mysql 服务器。
Step # 4: Setup new mysql root account password i.e. reset mysql password.
第 4 步:设置新的 mysql 根帐户密码,即重置 mysql 密码。
Step # 5: Exit and restart the MySQL server.
第 5 步:退出并重新启动 MySQL 服务器。
Here are commands you need to type for each step (login as the root user):
以下是您需要为每个步骤键入的命令(以 root 用户身份登录):
Step # 1: Stop mysql service
第 1 步:停止 mysql 服务
# /etc/init.d/mysql stop
Output:
输出:
Stopping MySQL database server: mysqld.
Step # 2: Start to MySQL server w/o password:
第 2 步:启动没有密码的 MySQL 服务器:
# mysqld_safe --skip-grant-tables &
Output:
输出:
[1] 5988
Starting mysqld daemon with databases from /var/lib/mysql
mysqld_safe[6025]: started
Step # 3: Connect to mysql server using mysql client:
第 3 步:使用 mysql 客户端连接到 mysql 服务器:
# mysql -u root
Output:
输出:
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>
Step # 4: Setup new MySQL root user password
第 4 步:设置新的 MySQL 根用户密码
mysql> use mysql;
mysql> update user set password=PASSWORD("NEW-ROOT-PASSWORD") where User='root';
mysql> flush privileges;
mysql> quit
Step # 5: Stop MySQL Server:
第 5 步:停止 MySQL 服务器:
# /etc/init.d/mysql stop
Output:
输出:
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
Step # 6: Start MySQL server and test it
第 6 步:启动 MySQL 服务器并进行测试
# /etc/init.d/mysql start
# mysql
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
# mysql -u root -p
Source: http://www.cyberciti.biz/tips/recover-mysql-root-password.html
来源:http: //www.cyberciti.biz/tips/recover-mysql-root-password.html
回答by Stanislav Karakhanov
Worked for me and "5.7.11 MySQL Community Server":
为我和“5.7.11 MySQL 社区服务器”工作:
use mysql;
update user set authentication_string=password(''), plugin='mysql_native_password' where user='root';
I had to change the 'plugin' field as well because it was set to 'auth_socket'.
我也必须更改“插件”字段,因为它被设置为“auth_socket”。
After that I could connect as mysql -u root
without a password.
之后,我可以在mysql -u root
没有密码的情况下进行连接。
回答by user64141
If you want an empty password, you should set the password to null and not use the Password hash function, as such:
如果你想要一个空密码,你应该将密码设置为空,而不是使用密码哈希函数,例如:
On the command line:
在命令行上:
sudo service mysql stop
sudo mysqld_safe --skip-grant-tables --skip-networking &
mysql -uroot
In MySQL:
在 MySQL 中:
use mysql;
update user set password=null where User='root';
flush privileges;
quit;
回答by bsd
- connect to mysql as user root (use one of the two following methods)
- login as root and start mysql using
mysql -p
, enter current root password - login as self and start mysql using
mysql -u root -p
, enter current root password
- login as root and start mysql using
mysql> set password = password('');
- 以 root 用户身份连接到 mysql(使用以下两种方法之一)
- 以 root 身份登录并使用 启动 mysql
mysql -p
,输入当前的 root 密码 - 以 self 身份登录并使用 启动 mysql
mysql -u root -p
,输入当前的 root 密码
- 以 root 身份登录并使用 启动 mysql
mysql> set password = password('');
Done! No root password.
完毕!没有root密码。
回答by kta
SET PASSWORD FOR 'root'@'localhost' = PASSWORD('');
回答by djordjea
This worked for me on Ubuntu 16.04 with v5.7.15 MySQL:
这在 Ubuntu 16.04 和 v5.7.15 MySQL 上对我有用:
First, make sure you have mysql-client installed (sudo apt-get install mysql-client
).
首先,确保你已经安装了 mysql-client ( sudo apt-get install mysql-client
)。
Open terminal and login:
打开终端并登录:
mysql -uroot -p
(then type your password)
(然后输入您的密码)
After that:
在那之后:
use mysql;
update user set authentication_string=password(''), plugin='mysql_native_password' where user='root';
(tnx @Stanislav Karakhanov)
(tnx @Stanislav Karakhanov)
And the very last important thing is to reset mysql service:
最后一件重要的事情是重置 mysql 服务:
sudo service mysql restart
You should now be able to login (without passsword) also by using MySQL Workbench.
您现在应该也可以使用 MySQL Workbench 登录(无需密码)。
回答by Nicolas Rivas
For MySQL 8.0 just:
对于 MySQL 8.0,只需:
SET PASSWORD FOR 'root'@'localhost' = '';
SET PASSWORD FOR 'root'@'localhost' = '';
回答by Zendo June
It's not a good idea to edit mysql
database directly.
mysql
直接编辑数据库不是一个好主意。
I prefer the following steps:
我更喜欢以下步骤:
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '';
mysql> flush privileges;
回答by bitfishxyz
This is from MySQL 8.0.13:
这是来自 MySQL 8.0.13:
use mysql;
update user set authentication_string=null where user='root';
quit;
回答by user9903233
It works for me.
这个对我有用。
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password'
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password'