MySQL is a widely used relational database management system. Many websites and applications use MySQL to store and manage data. In MySQL, setting up users is very important because user management can control access and operation permissions to the database. In this article, we will explain how to set up a MySQL user.
Create MySQL user
In MySQL, you can use the following command to create a new user:
CREATE USER 'username'@'localhost' IDENTIFIED BY 'password';
In the above command, username
is the new user The user name, localhost
means that the user can only access the database from the local host, and password
is the user's password.
Please note that the above command does not provide permission to access and operate the database. To grant permissions to a new user, use the GRANT
command.
Grant MySQL user permissions
GRANT
command is used to grant MySQL users permission to access and operate the database. In MySQL, you can use the following command to grant user permissions:
GRANT permission1, permission2, ... ON database_name.* TO 'username'@'localhost';
In the above command, permission1
, permission2
, etc. indicate the permissions to be granted to the user, such as SELECT
, DELETE
, UPDATE
, etc. database_name
indicates the name of the database to which the user is to be granted permissions, and *
indicates that the user is granted permissions to all tables in the database. username
and localhost
are the same as those used when creating the user.
For example, if you want to grant user user1
SELECT
permissions and INSERT
permissions to all tables in the mydb
database , you can use the following command:
GRANT SELECT, INSERT ON mydb.* TO 'user1'@'localhost';
Delete MySQL user
In MySQL, you can use the following command to delete an existing user:
DROP USER 'username'@'localhost';
In the above command,username
and localhost
are the same as those used when creating the user.
Summary
In MySQL, setting up users is very important. We can use the CREATE USER
command to create a new user, the GRANT
command to grant the user database access and operation permissions, and the DROP USER
command to delete the user. Properly setting up database users will help protect your database and control access to it.
The above is the detailed content of mysql user settings. For more information, please follow other related articles on the PHP Chinese website!