我在 Ubuntu 中运行 MySQL,默认安装。
比如说,我怎样才能将用户名更改root
为另一个用户名admin
?最好从命令行。
连接到 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';
我只是想说,对我来说,没有“密码”列。
要更改密码,正确的字段是 authentication_string
所以命令是
update user set authentication_string=PASSWORD('new password') where user='admin';
我不是 MySQL 专家,所以我不确定为什么,但我说的是正确的,至少在我的情况下。