创建账号
1.创建本地账号
create user 'egon1'@'localhost' identified by '123'
在本地登录
mysql -uegon1 -p123
- 创建远程账号
在服务端的cmd上,输入以下命令
create user 'egon2'@'192.168.31.10' identified by '123'
create user 'egon3'@'192.168.31.%' identified by '456'
客户端远程登录服务端的数据库,在cmd上输入以下命令
mysql -uegon2 -p123 -h 192.168.31.1
授权
权限控制表:
user: * . *
db:db1.*
tables_priv:db1.t1
columns_priv:id,name
查看权限
mysql>select * from mysql.user\G
mysql>select * from mysql.db\G
授权
grant all on *.* to 'egon1'@'localhost';
grant select on *.* to 'egon1'@'localhost';
回收权限
revoke select on *.* from 'egon1'@'localhost';
针对某个库授权
grant select on db1.* to 'egon1'@'localhost';
针对某个表授权
grant select on db1.t1 to 'egon1'@'localhost';
针对字段授权
grant select(id,name) ,update(age) on db1.t1 to 'egon1'@'localhost';