1..删除掉不需要的用户
查看用户表
mysql> SELECT User,Host FROM mysql.user; +------+-------------------------+ | User | Host | +------+-------------------------+ | root | 127.0.0.1 | | | izwz9cl4i8oy1reej7o8pmz | | root | izwz9cl4i8oy1reej7o8pmz | | | localhost | | root | localhost | +------+-------------------------+ 5 rows in set (0.00 sec)
删除用户最好再SELECT一次,以免删除错误 mysql> SELECT User,Host FROM mysql.user WHERE User=""; +------+-------------------------+ | User | Host | +------+-------------------------+ | | izwz9cl4i8oy1reej7o8pmz | | | localhost | +------+-------------------------+ 2 rows in set (0.00 sec)
删除用户 mysql> DELETE FROM mysql.user WHERE User=""; Query OK, 2 rows affected (0.00 sec) mysql>
2..设置密码
对root用户设置密码
mysql> UPDATE mysql.user SET PASSWORD=PASSWORD("syj2FBZ") WHERE User='root'; Query OK, 3 rows affected (0.00 sec) Rows matched: 3 Changed: 3 Warnings: 0
刷新权限 mysql> mysql> FLUSH PRIVILEGES; Query OK, 0 rows affected (0.00 sec)
退出 mysql> quit Bye
测试无密码登录 [root@iZwz9cl4i8oy1reej7o8pmZ ~]# mysql ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO) [root@iZwz9cl4i8oy1reej7o8pmZ ~]#
测试使用密码登录 [root@iZwz9cl4i8oy1reej7o8pmZ ~]# mysql -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 5 Server version: 5.1.73 Source distribution Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved. 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. mysql>