如何在 MySQL 中更改 root 用户名
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19539028/
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 can I change root username in MySQL
提问by Adrian Ber
I'm running MySQL in Ubuntu, default installation.
我在 Ubuntu 中运行 MySQL,默认安装。
How can I change the username from root
to another one, let's say admin
? Preferably from the command line.
我怎样才能将用户名从root
另一个更改,让我们说admin
?最好从命令行。
回答by Adrian Ber
After connecting to MySQL run
连接到 MySQL 后运行
use mysql;
update user set user='admin' where user='root';
flush privileges;
That's it.
就是这样。
If you also want to change password, in MySQL < 5.7, run
如果您还想更改密码,请在 MySQL < 5.7 中运行
update user set password=PASSWORD('new password') where user='admin';
before flush privileges;
. In MySQL >= 5.7, the password
field in the user
table was renamed to authentication_string
, so the above line becomes:
之前flush privileges;
。在 MySQL >= 5.7 中,表中的password
字段user
被重命名为authentication_string
,因此上面的行变为:
update user set authentication_string=PASSWORD('new password') where user='admin';
回答by electr0sheep
I just wanted to say that for me, there was no column 'password'.
我只想说,对我来说,没有“密码”列。
To change password, the correct field was authentication_string
要更改密码,正确的字段是 authentication_string
So the command is
所以命令是
update user set authentication_string=PASSWORD('new password') where user='admin';
I'm no MySQL expert, so I'm not sure exactly why, but what I said is correct, at least in my case.
我不是 MySQL 专家,所以我不确定确切原因,但我说的是正确的,至少在我的情况下。