14

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

比如说,我怎样才能将用户名更改root为另一个用户名admin?最好从命令行。

4

2 回答 2

40

连接到 MySQL 后运行

use mysql;
update user set user='admin' where user='root';
flush privileges;

而已。

如果您还想更改密码,在 MySQL < 5.7 中,运行

update user set password=PASSWORD('new password') where user='admin';

之前flush privileges;。在 MySQL >= 5.7password中,表中的字段user被重命名为authentication_string,所以上面的行变成了:

update user set authentication_string=PASSWORD('new password') where user='admin';
于 2013-10-23T10:22:32.703 回答
1

我只是想说,对我来说,没有“密码”列。

要更改密码,正确的字段是 authentication_string

所以命令是

update user set authentication_string=PASSWORD('new password') where user='admin';

我不是 MySQL 专家,所以我不确定为什么,但我说的是正确的,至少在我的情况下。

于 2016-05-24T02:41:06.190 回答