centos7 mysql怎么添加权限

2022-08-11 科技 111阅读
创建新的用户名和密码
create user username identified by password

给用户分配权限
GRANT privileges ON databasename.tablename TO 'username'@'host'
grant all privileges on *.* to 'username'@'localhost' identified by 'password'

删除权限
REVOKE ALL PRIVILEGES ON *.* FROM 'username'@'localhost';

分配指定库的权限
GRANT ALL PRIVILEGES ON database1.* TO 'username'@'localhost' IDENTIFIED BY 'password';

分配指定操作的权限
GRANT SELECT, UPDATE ON database1.* TO 'username'@'localhost' IDENTIFIED BY 'password';

刷新权限
FLUSH PRIVILEGES

删除用户
DROP USER username@localhost;

设置默认的编码
修改/etc/my.cnf配置文件,在[mysqld]下添加编码配置,如下所示
character_set_server=utf8
init_connect='SET NAMES utf8'

重启mysql
systemctl restart mysqld

更新用户的密码
SET PASSWORD FOR 'username'@'localhost' = PASSWORD("123456");
声明:你问我答网所有作品(图文、音视频)均由用户自行上传分享,仅供网友学习交流。若您的权利被侵害,请联系fangmu6661024@163.com