Home Database Mysql Tutorial Detailed explanation of MySQL database creation, user creation and authorization

Detailed explanation of MySQL database creation, user creation and authorization

Jun 21, 2017 pm 01:25 PM
mysql create database user

1. View user related information through the user table of the mysql database

mysql> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> select host,user,password from user ;+-----------+------+-------------------------------------------+
| host      | user | password                                  |
+-----------+------+-------------------------------------------+
| localhost | root | *87F2746835A04895BB77E12AA5054A767******* |
| qxyw      | root |                                           |
| 127.0.0.1 | root |                                           |
| localhost |      |                                           |
| qxyw      |      |                                           |
+-----------+------+-------------------------------------------+
5 rows in set (0.00 sec)
Copy after login


2. Create a database

mysql> create database [databasename] default character set utf8 collate utf8_general_ci;
Query OK, 1 row affected (0.00 sec)
Copy after login


3. Create a user

mysql> create user 'dba'@'%' identified by '*******';
Query OK, 0 rows affected (0.00 sec)
Copy after login

The meaning of the value of the host column in the user table
% Matches all hosts
localhost localhost will not be parsed into an IP address and will be connected directly through UNIX socket
127.0.0.1 will be connected through TCP/IP protocol and can only be accessed locally;
::1 ::1 is compatible with ipv6, which means the same as 127.0.0.1 of ipv4


4. Give the dba user the permission to add, delete, modify and check the specified database

mysql> grant select,insert,update,delete,create on [databasename].* to dba;
Query OK, 0 rows affected (0.00 sec)
Copy after login


Note: After modifying the permissions, you must refresh the service or restart the service. To refresh the service, use: FLUSH PRIVILEGES

5. You can check the permissions through the show grants command. If you want to update the service based on the original To increase the permissions, continue to execute grant

mysql> grant drop on [databasename].* to dba;
Query OK, 0 rows affected (0.00 sec)
mysql> show grants for dba;+----------------------------------------------------------------------------------------------------+
| Grants for dba@%                                                                                   |
+----------------------------------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'dba'@'%' IDENTIFIED BY PASSWORD '*****************************************' |
| GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP ON `[databasename]`.* TO 'dba'@'%'              |
+----------------------------------------------------------------------------------------------------+
2 rows in set (0.00 sec)
Copy after login

6. The user’s relevant permissions can be removed through the revoke command

mysql> revoke drop on [databasename].* from dba;
Query OK, 0 rows affected (0.00 sec)
mysql> show grants for dba;+----------------------------------------------------------------------------------------------------+
| Grants for dba@%                                                                                   |
+----------------------------------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'dba'@'%' IDENTIFIED BY PASSWORD '*****************************************' |
| GRANT SELECT, INSERT, UPDATE, DELETE, CREATE ON `[databasename]`.* TO 'dba'@'%'                    |
+----------------------------------------------------------------------------------------------------+
2 rows in set (0.00 sec)
Copy after login

The above is the detailed content of Detailed explanation of MySQL database creation, user creation and authorization. For more information, please follow other related articles on the PHP Chinese website!

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

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to optimize MySQL query performance in PHP? How to optimize MySQL query performance in PHP? Jun 03, 2024 pm 08:11 PM

How to optimize MySQL query performance in PHP?

How to use MySQL backup and restore in PHP? How to use MySQL backup and restore in PHP? Jun 03, 2024 pm 12:19 PM

How to use MySQL backup and restore in PHP?

How to insert data into a MySQL table using PHP? How to insert data into a MySQL table using PHP? Jun 02, 2024 pm 02:26 PM

How to insert data into a MySQL table using PHP?

How to fix mysql_native_password not loaded errors on MySQL 8.4 How to fix mysql_native_password not loaded errors on MySQL 8.4 Dec 09, 2024 am 11:42 AM

How to fix mysql_native_password not loaded errors on MySQL 8.4

How to use MySQL stored procedures in PHP? How to use MySQL stored procedures in PHP? Jun 02, 2024 pm 02:13 PM

How to use MySQL stored procedures in PHP?

How to create a MySQL table using PHP? How to create a MySQL table using PHP? Jun 04, 2024 pm 01:57 PM

How to create a MySQL table using PHP?

Detailed tutorial on establishing a database connection using MySQLi in PHP Detailed tutorial on establishing a database connection using MySQLi in PHP Jun 04, 2024 pm 01:42 PM

Detailed tutorial on establishing a database connection using MySQLi in PHP

iOS 18 adds a new 'Recovered' album function to retrieve lost or damaged photos iOS 18 adds a new 'Recovered' album function to retrieve lost or damaged photos Jul 18, 2024 am 05:48 AM

iOS 18 adds a new 'Recovered' album function to retrieve lost or damaged photos

See all articles