您现在的位置是: 首页> Mysql>为MySQL数据库添加新用户并为其分配权限 所属分类:Mysql
为MySQL数据库添加新用户并为其分配权限
初柒先生
2019-09-05 11:42
【mysql】
281人已围观
简介MySQL数据库在网站开发中,使用频率比较高,所以数据库的用户管理挺重要的。
MySQL数据库安装后,有一个超级管理root。数据库的使用过程中,需要多用户的管理。
1、MySQL数据库命令行登陆
mysql -u账号 -p密码
注:-u后面直接加账号不能留空;
-p后面的密码直接填是明文显示,可以先不填,后面再输入密码
2、查看用户列表
select user,host from mysql.user;
3、添加新用户
(1)添加用户命令(这种方式用户名不用加引号,如果加了会出错)
create user 用户名 identified by '密码';
(2)本地登陆新用户
create user '用户名'@'localhost' identified by '用户密码';
(3)远程登陆新用户
create user '用户名'@'%' identified by '密码';
(4)删除用户(删除本地登陆用户、删除远程登陆用户)
方法1:
drop user 'username'@'host';
drop user 'username'@'%';
方法2:
delete from mysql.user where user ='用户名';
4、添加权限
(1)本地登陆权限(管理指定数据库的使用权限)
grant all privileges on `数据库`.* to '用户名'@'localhost' identified by '密码' with grant option;
(2)远程登陆权限(管理指定数据库的使用权限)
grant all privileges on `数据库`.* to '用户名'@'%' identified by '密码' with grant option;
(3)不指定数据,即授权可以访问所有数据库
grant all privileges on *.* to '用户名'@'%'identified by '密码' with grant option;
(4)指定权限(查、插、更新)
grant select,insert,update on *.* to 用户名@'%' identified by '密码';
5、修改密码
update mysql.user set password=password('新密码') where User="用户名" and Host="localhost";
6、刷新权限
用户添加和权限配置后都需要刷新权限,才能生效。
flush privileges;
很赞哦! (1)
初柒先生
2019-09-05 11:42
【mysql】
281人已围观
上一篇:已经没有了