Home > Database > Mysql Tutorial > body text

How to set MySQL permissions in Linux system

PHPz
Release: 2023-04-21 11:48:44
Original
1215 people have browsed it

In Linux systems, MySQL is one of the most commonly used relational database management systems. MySQL permission settings allow us to control which databases and tables users can use, which operations they can perform, which data they can modify, etc. Below, this article will introduce how to set MySQL permissions in a Linux system.

  1. Login to MySQL

First, we need to log in to the MySQL system. In Linux systems, you can use the following command:

$ mysql -u [username] -p
Copy after login

where [username] is the user name in the MySQL system.

  1. View the current MySQL users and permissions

Next, we need to check the users and permissions in the current MySQL system. You can use the following command:

mysql> SELECT user, host, password FROM mysql.user;
Copy after login

This will return the username, hostname and encrypted password of all users. If you want to check the permissions of a certain user, you can use the following command:

mysql> SHOW GRANTS FOR [username]@[host];
Copy after login

where, [username] is the user name in the MySQL system, [host] Is the host name or IP address of the user.

  1. Create a new user

If you want to create a new user for MySQL, you can use the following command:

mysql> CREATE USER '[username]'@'[host]' IDENTIFIED BY '[password]';
Copy after login

Where, [username] is the username of the new user, [host] is the host name or IP address of the user, [password] is the user's password. Next, we need to grant permissions to this user.

  1. Authorization

In order to authorize, we need to use the GRANT command. The following example grants user "testuser" all permissions on the "testdb" database:

mysql> GRANT ALL PRIVILEGES ON testdb.* TO 'testuser'@'localhost' IDENTIFIED BY '[password]';
Copy after login

In this example, [password] is testuser's password. If you need to grant other permissions, you can use specific permissions after "ALL PRIVILEGES", for example:

mysql> GRANT SELECT, INSERT, UPDATE ON testdb.* TO 'testuser'@'localhost';
Copy after login

After granting permissions, don't forget to refresh MySQL:

mysql> FLUSH PRIVILEGES;
Copy after login
  1. Revoke permissions

If you need to revoke permissions, you can use the REVOKE command. For example, the following command will revoke all permissions to the "testdb" database from the user "testuser":

mysql> REVOKE ALL PRIVILEGES ON testdb.* FROM 'testuser'@'localhost';
Copy after login
  1. Delete user

Finally, if you need to delete the user, you can Use the following command:

mysql> DROP USER '[username]'@'[host]';
Copy after login

For example, the following command will delete the user "testuser":

mysql> DROP USER 'testuser'@'localhost';
Copy after login

Summary

Setting the permissions of MySQL in a Linux system is a necessary process. By understanding MySQL authorization and revocation commands, we can master the management method of MySQL users in Linux. At the same time, we can use these commands to create, delete and grant permissions to different MySQL users to better manage and protect the MySQL server.

The above is the detailed content of How to set MySQL permissions in Linux system. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!