数据库创建用户和受权限

# 在数据库创建一个luffy用户,密码是Luffy123?,只能对luffy_api库有操作权限
    -查看数据库的用户:select user,host,authentication_string from mysql.user;
    -创建用户;grant 权限(create, update) on 库.表 to '账号'@'host' identified by '密码'
  
    grant all privileges on luffy_api.* to 'luffy'@'%' identified by 'Luffy123';
    grant all privileges on luffy_api.* to 'luffy'@'localhost' identified by 'Luffy123';
    
"""
如MySQL版本在5.7以上时,创建用户和权限要分开设不然会报错:
ip地址
     create user luffy@"%" identified by "Luffy123";
     grant all on luffy_api.* to luffy@"%" with grant option;
 本地localhost
     create user luffy@"localhost" identified by "Luffy123";
     grant all on luffy_api.* to luffy@"localhost" with grant option;
"""
posted @ 2022-07-05 21:45  Mr_胡萝卜须  阅读(61)  评论(0)    收藏  举报