MySql 创建用户并授权
1.查看所有用户,需要在root用户下查看
select host,user,password from mysql.user;
2.查看用户权限
show grants for root@%;
select * from mysql.user where user='tomcat171_1'\G;
3.创建用户
create user 'tomcat171_uc'@'172.16.102.31' identified by 'b#*N0dxl';
username:用户名;host:指定在哪个主机上可以登录,本机可用localhost,%通配所有远程主机;password:用户登录密码;
4.授权
grant all privileges on *.* to 'tomcat171_uc'@'172.16.102.31' identified by 'b#*N0dxl';
格式:grant 权限 on 数据库名.表名 to 用户@登录主机 identified by "用户密码";*.*代表所有权;
@ 后面是访问MySQL的客户端IP地址(或是 主机名) % 代表任意的客户端,如果填写 localhost 为本地访问(那此用户就不能远程访问该mysql数据库了)。
5.刷新权限
FLUSH PRIVILEGES;