等保有一个建议,不使用root。因此,处于一些主观原因,只能将root@localhost用户进行改名,
使得用户无法通过
mysql -uroot -p
登录数据库
以下为可以参考的一个方法:
以最高权限用户登录
mysql -uroot -p'password_tmp'
后,执行:
切换数据库
use mysql;
改名
update user set user='new_username' where user='old_username';
刷新权限
flush privileges;
退出
exit;
验证
mysql -uold_username -p'password_tmp'
Enter password:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
再用新用户验证登录
mysql -unew_username -p'password_tmp'
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 23
Server version: 8.0.34 MySQL Community Server - GPL
Copyright (c) 2000, 2023, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
至此,修改完毕