Home > Database > Mysql Tutorial > body text

Introduction to the method of creating users and authorization in MySQl (code example)

不言
Release: 2019-01-26 11:23:36
forward
3398 people have browsed it

This article brings you an introduction to the method of creating users and authorization in MySQl (code examples). It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

Permission management:

  • How to create a user and password

  • Authorize the current user

  • Remove the permissions of the current user

First go to the mysql database:

mysql> use mysql
Database changed
Copy after login

Secondly, add, delete, and modify the new user:

1.创建用户:
# 指定ip:192.118.1.1的chao用户登录
create user 'chao'@'192.118.1.1' identified by '123';
# 指定ip:192.118.1.开头的chao用户登录
create user 'chao'@'192.118.1.%' identified by '123';
# 指定任何ip的chao用户登录
create user 'chao'@'%' identified by '123';
 
2.删除用户
drop user '用户名'@'IP地址';
 
 
3.修改用户
rename user '用户名'@'IP地址' to '新用户名'@'IP地址';
 
4.修改密码
set password for '用户名'@'IP地址'=Password('新密码');
Copy after login

Then, authorize the current user

#查看权限
show grants for '用户'@'IP地址'
 
#授权 chao用户仅对db1.t1文件有查询、插入和更新的操作
grant select ,insert,update on db1.t1 to "chao"@'%';
 
# 表示有所有的权限,除了grant这个命令,这个命令是root才有的。chao用户对db1下的t1文件有任意操作
grant all privileges  on db1.t1 to "chao"@'%';
#chao用户对db1数据库中的文件执行任何操作
grant all privileges  on db1.* to "chao"@'%';
#chao用户对所有数据库中文件有任何操作
grant all privileges  on *.*  to "chao"@'%';
  
#取消权限
  
# 取消chao用户对db1的t1文件的任意操作
revoke all on db1.t1 from 'chao'@"%"; 
 
# 取消来自远程服务器的chao用户对数据库db1的所有表的所有权限
 
revoke all on db1.* from 'chao'@"%"; 
 
取消来自远程服务器的chao用户所有数据库的所有的表的权限
revoke all privileges on *.* from 'chao'@'%';
Copy after login

The above is the detailed content of Introduction to the method of creating users and authorization in MySQl (code example). For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:cnblogs.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template