配置只能访问指定数据库的账户

第一步:管理员连接数据库

mysql -uroot -p密码

 

第二步:创建账户能够访问的数据库

create database 数据库名 default charset=utf8;

 

第三步:查看用户

select user,host from mysql.user;

 

第四步:创建用户

# 授权账号命令:

grant 权限(create, update) on 库.表 to '账号'@'host' identified by '密码'

 

grant select on testdb.* to common_user@’%’    
grant insert on testdb.* to common_user@’%’
grant update on testdb.* to common_user@’%’
grant delete on testdb.* to common_user@’%’

  

两种配置方式:

1.配置任意ip都可以连入数据库的账户:

grant all privileges on 数据库名.* to '用户名'@'%' identified by '密码';

 

2.由于数据库版本的问题,可能本地还连接不上,就给本地用户单独配置

grant all privileges on 数据库名.* to '用户名'@'localhost' identified by '密码';

 

# 刷新权限:

flush privileges;

 

添加加root用户允许远程链接所有数据库

grant all privileges on *.* to 'root'@'%' identified by '密码';

 

第五步:使用新创建的用户,登录mysql

mysql -u创建的用户名 -p:密码

 

posted @ 2024-01-18 14:57  wellplayed  阅读(20)  评论(0编辑  收藏  举报