如何在 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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 19:12:29  来源:igfitidea点击:

How can I change root username in MySQL

mysql

提问by Adrian Ber

I'm running MySQL in Ubuntu, default installation.

我在 Ubuntu 中运行 MySQL,默认安装。

How can I change the username from rootto 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 passwordfield in the usertable 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 专家,所以我不确定确切原因,但我说的是正确的,至少在我的情况下。