如何在MySQL中更改root用户名 [英] How can I change root username in MySQL

查看:1089
本文介绍了如何在MySQL中更改root用户名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm running MySQL in Ubuntu, default installation.

如何将用户名从root更改为另一个用户名,例如admin?最好从命令行.

How can I change the username from root to another one, let's say admin? Preferably from the command line.

推荐答案

连接到MySQL后运行

After connecting to MySQL run

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

就是这样.

如果您还想更改密码,请使用MySQL< 5.7,运行

If you also want to change password, in MySQL < 5.7, run

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

flush privileges;之前.在MySQL> = 5.7中,user表中的password字段已重命名为authentication_string,因此上一行变为:

before flush privileges;. In MySQL >= 5.7, the password field in the user table was renamed to authentication_string, so the above line becomes:

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

这篇关于如何在MySQL中更改root用户名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆