Tutorial Series MySQL series: Basic concepts of MySQL relational database 1. User Management 1. User AccountThe user account consists of two parts: username and HOST ('USERNAME'@'HOST') HOST means:
You can use wildcards, % and _; 192.168.% means all hosts in this network segment 2. Add and delete accountsMain: After modifying the user information in the database, you need to execute FLUSH PRIVILEGES; to refresh the authorization table to make it effective create MariaDB [mysql]> CREATE USER 'user1'@'192.168.%'; MariaDB [mysql]> CREATE USER 'user2'@'192.168.%' IDENTIFIED BY 'your_password'; MariaDB [mysql]> SELECT user,host,password FROM user; +-------+-----------+-------------------------------------------+ | user | host | password | +-------+-----------+-------------------------------------------+ | root | localhost | *4A54C3F37C03C7FBACE31591D6A8C546F93DF5C5 | | root | centos7 | | | root | 127.0.0.1 | | | root | ::1 | | | | localhost | | | | centos7 | | | user1 | 192.168.% | | | user2 | 192.168.% | *9E72259BA9214F692A85B240647C4D95B0F2E08B | +-------+-----------+-------------------------------------------+ delete MariaDB [mysql]> DROP USER user2@'192.168.%'; MariaDB [mysql]> SELECT user,host,password FROM user; +-------+-----------+-------------------------------------------+ | user | host | password | +-------+-----------+-------------------------------------------+ | root | localhost | *4A54C3F37C03C7FBACE31591D6A8C546F93DF5C5 | | root | centos7 | | | root | 127.0.0.1 | | | root | ::1 | | | | localhost | | | | centos7 | | | user1 | 192.168.% | | +-------+-----------+-------------------------------------------+ Rename MariaDB [mysql]> RENAME USER user1@'192.168.%' TO testuser@'%'; MariaDB [mysql]> SELECT user,host,password FROM mysql.user; +----------+----------+-------------------------------------------+ | user | host | password | +----------+----------+-------------------------------------------+ | root | localhost | *4A54C3F37C03C7FBACE31591D6A8C546F93DF5C5 | | root | centos7 | | | root | 127.0.0.1 | | | root | ::1 | | | | localhost | | | | centos7 | | | testuser | % | | +----------+----------+-------------------------------------------+ Change Password MariaDB [mysql]> SET PASSWORD FOR testuser@'%' = PASSWORD('testpass'); MariaDB [mysql]> SELECT user,host,password FROM mysql.user; +----------+----------+-------------------------------------------+ | user | host | password | +----------+----------+-------------------------------------------+ | root | localhost | *4A54C3F37C03C7FBACE31591D6A8C546F93DF5C5 | | root | centos7 | | | root | 127.0.0.1 | | | root | ::1 | | | | localhost | | | | centos7 | | | testuser | % | *00E247AC5F9AF26AE0194B41E1E769DEE1429A29 | +----------+----------+-------------------------------------------+ Other ways to change your password: UPDATE user SET password=PASSWORD('testpass') WHERE user='testuser'; # mysqladmin -uroot -poldpass password 'newpass' 3. Crack the administrative account passwordRecovering passwords from an empty database # systemctl stop mariadb # rm -rf /var/lib/mysql/* #Delete the database and run away # systemctl start mariadb Recover password with data 1) Add the skip-grant-tables and skip-networking parameters under [mydqld] in the /etc/my.cnf configuration file 2) # systemctl restart mariadb restart service 3) Execute mysql to log in to the database 4) MariaDB [(none)]> UPDATE mysql.user SET password=PASSWORD('newpassword') WHERE user='root' AND host='localhost'; #Update password 5) MariaDB [(none)]> FLUSH PRIVILEGES; #Refresh the authorization table 6) Exit, modify the configuration file, delete the skip-grant-tables and skip-networking parameters, and restart the service. You can also use the following options for it when starting the mysqld process:
2. Authorization Management 1. Authorization Syntax: GRANT priv_type ON [object_type] priv_level TO user@'%' [IDENTIFIED BY 'password'] [WITH GRANT OPTION]; If the user does not exist during authorization, it will be created. Therefore, we usually do not create a user separately, but complete the authorization creation at the same time. priv_type authorization type
object_type Authorization object
priv_level authorization level
WITH GRANT OPTION
MariaDB [school]> GRANT SELECT(stuid,name) ON TABLE school.students TO admin@'%' IDENTIFIED BY 'admin'; #Authorize the query permission of the stuid and name fields of the students table to the admin@'%' userMariaDB [school]> FLUSH PRIVILEGES; #Refresh the authorization table 2. Query authorizationMariaDB [school]> SHOW GRANTS FOR admin@'%'\G #View the permissions of the specified user**************************** 1. row *************************** Grants for admin@%: GRANT USAGE ON *.* TO 'admin'@'%' IDENTIFIED BY PASSWORD '*4ACFE3202A5FF5CF467898FC58AAB1D615029441' *************************** 2. row *************************** Grants for admin@%: GRANT SELECT (stuid, name) ON `school`.`students` TO 'admin'@'%' [root@working ~]# mysql -uadmin -padmin -h192.168.0.7 MariaDB [(none)]> SHOW GRANTS FOR CURRENT_USER()\G #Query your own permissions**************************** 1. row *************************** Grants for admin@%: GRANT USAGE ON *.* TO 'admin'@'%' IDENTIFIED BY PASSWORD '*4ACFE3202A5FF5CF467898FC58AAB1D615029441' *************************** 2. row *************************** Grants for admin@%: GRANT SELECT (stuid, name) ON `school`.`students` TO 'admin'@'%' 3. Revocation of authorizationMariaDB [school]> REVOKE SELECT(stuid) ON school.students FROM admin@'%'; #Revoke the query permission of admin@'%' user on the stuid field SummarizeThis is the end of this article about MySQL users and authorization. For more relevant MySQL users and authorization content, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: Detailed explanation of setting Context Path in Web application
>>: Specific use of CSS front-end page rendering optimization attribute will-change
This article example shares the specific code of ...
When I configured mysql, I set the default storag...
Recently, due to business reasons, I need to acce...
Table of contents 1. Easy to read code 1. Unified...
Postfix is a free and open source MTA (Mail Tra...
Table of contents 1. Introduction 2. RC and RR is...
This article shares the specific code for Vue to ...
Table of contents explain: Summarize Replenish Un...
1. Description In MySQL, when we need to get the ...
First, a common question is, what is the relation...
I think editors are divided into two categories, ...
1. Introduction When writing animation effects fo...
Drop-shadow and box-shadow are both CSS propertie...
In actual development or production environments,...
Table of contents No slots Vue2.x Slots With slot...