查看用户:
select host,user from mysql.user; //mysql库中user表,host为主机地址,user为用户名
mysql> select host,user from mysql.user; +-----------+------+ | host | user | +-----------+------+ | 127.0.0.1 | root | | ::1 | root | | localhost | root | +-----------+------+ 3 rows in set (0.00 sec)
创建用户:
create user 'test1'@'%' identified by 'test1'; //%为通配符,表示所有IP都有连接权限(192.168.1.%限制网段访问)
mysql> create user 'test1'@'%' identified by 'test1'; Query OK, 0 rows affected (0.00 sec) mysql> select host,user from mysql.user; +-----------+-------+ | host | user | +-----------+-------+ | % | test1 | | 127.0.0.1 | root | | ::1 | root | | localhost | root | +-----------+-------+ 4 rows in set (0.00 sec)
修改用户密码:
set password for root=password('123456'); //修改root账号密码
mysql> set password for test1=password('123456'); Query OK, 0 rows affected (0.00 sec)
删除用户:
drop user testuser;
mysql> drop user testuser; Query OK, 0 rows affected (0.00 sec) mysql> select host,user from mysql.user; +-----------+------+ | host | user | +-----------+------+ | 127.0.0.1 | root | | ::1 | root | | localhost | root | +-----------+------+ 3 rows in set (0.00 sec)