This article will introduce you to the user management in MySQL and introduce the methods of adding users, authorizing and deleting users. I hope it will be helpful to you!
Do not directly use theroot
user to manage application data. [Related recommendations:mysql video tutorial]
Log in to the database as root user and run the following command:
create user zhangsan identified by 'zhangsan';
The above command creates userzhangsan
, the password iszhangsan
. You can view the new user information in themysql.user
table:
select User, Host, Password from mysql.user where User = 'zhangsan';
Command format:grant privilegesCode on dbName.tableName to username@host identified by "password";
grant all privileges on zhangsanDb.* to zhangsan@'%' identified by 'zhangsan'; flush privileges;
The above The statement authorizes all operation permissions of thezhangsanDb
database to the userzhangsan
.
You can view the new additions in themysql.db
table Database permission information:
select User, Db, Host, Select_priv, Insert_priv, Update_priv, Delete_priv from mysql.db where User = 'zhangsan';
You can also view the command executed by permission grant through theshow grants
command:
show grants for 'zhangsan';
privilegesCode
indicates the type of permission granted. , the following types are commonly used [1]: All privileges
: Read privileges
: Delete permission
: Update permission
: Create permission
: Delete database and data table permissions
indicates the specific library or table to which permissions are granted. Commonly used ones include the following Several options
: Grant permissions to all databases on this database server
: Grant dbName database Permissions on all tables
: Grant permissions to the dbTable table in database dbName
means The granted user and the IP address that allows the user to log in. The Host has the following types
: The user is only allowed to log in locally, not remotely.
: Allow remote login from any machine except this machine
: Specific
IPIndicates that the user is only allowed to log in from a specific IP.
Specifies the password for the user to log in
Indicates refresh permission changes
update mysql.user set password = password('zhangsannew') where user = 'zhangsan' and host = '%'; flush privileges;
drop user zhangsan@'%';
drop userThe command will delete the user and the corresponding permissions. After executing the command, you You will find that the corresponding records of the
mysql.usertable and
mysql.dbtable have disappeared.
create user zhangsan identified by 'zhangsan'; grant all privileges on zhangsanDb.* to zhangsan@'%' identified by 'zhangsan'; flush privileges;
zhangsanand assign the database# All permissions of ##zhangsanDB
are granted tozhangsan
. If you wantzhangsan
to be able to log in from this machine, you can givelocalhost
additional permissions:
grant all privileges on zhangsanDb.* to zhangsan@'localhost' identified by 'zhangsan';
Copy after login
[Related recommendations: mysql video tutorialThe above is the detailed content of A brief discussion on how to add, delete users and authorize in MySQL. For more information, please follow other related articles on the PHP Chinese website!
Related labels:
source:cnblogs.com
Previous article:A brief analysis of how to regularly back up mysql data in CentOS 7?
Next article:MySQL advanced learning: in-depth understanding of the three algorithms of join
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
Latest Articles by Author
-
2023-04-26 17:59:18
-
2023-04-26 17:47:48
-
2023-04-26 17:41:42
-
2023-04-26 17:37:05
-
2023-04-26 17:31:25
-
2023-04-26 17:27:32
-
2023-04-25 19:57:58
-
2023-04-25 19:53:11
-
2023-04-25 19:49:11
-
2023-04-25 19:41:54
Latest Issues
-
About us
Disclaimer
Sitemap
-
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!