语法如下,将Root @localhost重命名
UPDATE MySQL.user SET user = ‘yourNewRootName’ WHERE user = 'root';
要了解上述概念,让我们检查所有用户名和主机。查询如下
mysql> select user,host from MySQL.user;
以下是输出
+------------------+-----------+ | user | host | +------------------+-----------+ | Bob | % | | Manish | % | | User2 | % | | mysql.infoschema | % | | mysql.session | % | | mysql.sys | % | | root | % | | @UserName@ | localhost | | Adam Smith | localhost | | John | localhost | | John Doe | localhost | | User1 | localhost | | am | localhost | | hbstudent | localhost | | mysql.infoschema | localhost | | mysql.session | localhost | +------------------+-----------+ 16 rows in set (0.00 sec)
以下是将用户“ root”重命名为其他名称的查询
mysql> UPDATE mysql.user set user = 'MyRoot' where user = 'root'; Rows matched: 1 Changed: 1 Warnings: 0
让我们检查用户“ root”是否已使用新名称“ MyRoot”更新。查询如下
mysql> select user,host from MySQL.user;
以下是输出
+------------------+-----------+ | user | host | +------------------+-----------+ | Bob | % | | Manish | % | | MyRoot | % | | User2 | % | | mysql.infoschema | % | | mysql.session | % | | mysql.sys | % | | @UserName@ | localhost | | Adam Smith | localhost | | John | localhost | | John Doe | localhost | | User1 | localhost | | am | localhost | | hbstudent | localhost | | mysql.infoschema | localhost | | mysql.session | localhost | +------------------+-----------+ 16 rows in set (0.00 sec)
查看示例输出,根已成功成功更新为新名称“ MyRoot”。