mysql8学习笔记③数据库的授权操作
mysql8学习笔记③数据库的授权操作
Python连接mysql数据库
# yum install -y python-setuptools python-devel
# 安装pip工具
# curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
# python get-pip.py
# pip install --upgrade setuptools
# pip install PyMySQL
数据库的授权
查看创建用户的帮助
# mysql -uroot -p'Jad(2020'
mysql> help create user;
查看插件
设置密码策略,创建用户,为了测试方便修改密码策略,生产环境不建议这么操作
set global validate_password.policy=low;
set global validate_password.length=6;
create user mc_test@'10.11.0.%' identified by '123456' with max_user_connections 1;
mysql8.0创建账号,添加账户、权限等常用操作
1.授予某个用户多个数据库的所有权限,包括授权权限 WITH GRANT OPTION;
CREATE USER 'online_video_user'@'%' IDENTIFIED BY 'pass';
grant all privileges on vidcloud_res_oa.* TO 'online_video_user'@'%' WITH GRANT OPTION;
grant all privileges on ove.* TO 'online_video_user'@'%' WITH GRANT OPTION;
2.添加root账号
CREATE USER 'root'@'127.0.0.1' IDENTIFIED BY 'pass';
grant all privileges on *.* TO 'root'@'127.0.0.1' WITH GRANT OPTION;
3.添加某个账户对库有增删改查权限
CREATE USER 'ove_user'@'172.30.0.%' IDENTIFIED BY 'pass';
grant select,insert,update,delete ON ove.* TO 'ove_user'@'172.30.0.%';
4.修改数据库密码
# 修改root密码
mysql> update mysql.user set authentication_string = password('pass'), password_expired = 'N', password_last_changed = now() where user = 'root';
mysql> flush privileges;
授予和回收权限
mysql> grant select,delete,insert,update on mysql.* to mc_test@'10.11.0.%';
mysql> revoke delete,insert,update on mysql.* from mc_test@'10.11.0.%';