1.数据库设置密码
[root@db02 scripts]# mysqladmin -uroot password 123
2.使用密码登录
#1.正确的方式(不规范) [root@db02 scripts]# mysql -uroot -p123 [root@db02 scripts]# mysql -u root -p123 #2.错误的方式 [root@db02 scripts]# mysql -uroot -p 123 #官网上说-p或者--password参数与密码之间不能有间隔或多于字符 #3.正确且规范的方式 [root@db02 scripts]# mysql -u root -p Enter password:
3.查询用户
mysql> select user,host from mysql.user; +------+-----------+ | user | host | +------+-----------+ | root | 127.0.0.1 | | root | ::1 | | | db02 | | root | db02 | | | localhost | | root | localhost | +------+-----------+ 6 rows in set (0.00 sec)
4.删除用户(优化)
删除无关的用户,安全基线中的一项。
mysql> drop user root@'::1'; Query OK, 0 rows affected (0.00 sec) mysql> select user,host from user; +------+-----------+ | user | host | +------+-----------+ | root | 127.0.0.1 | | | db02 | | root | db02 | | | localhost | | root | localhost | +------+-----------+ 5 rows in set (0.00 sec)