How to set mysql permissions in linux

PHPz
Release: 2023-04-21 17:05:50
Original
1216 people have browsed it

Under Linux systems, MySQL database is a very common and important data management tool. When using MySQL, we usually need to set relevant permissions to achieve better data security management. The following are some commonly used MySQL permission setting methods.

  1. Create a new user

Before setting the MySQL permissions, we first need to create a new user. You can use the following command to create a user named "newuser" with the password "password":

CREATE USER 'newuser'@'localhost' IDENTIFIED BY 'password';
Copy after login

The user "newuser" here can only be used locally. If remote access is required, you need to change "localhost" Change to remote IP address.

  1. Grant permissions

After the user is created, we need to grant the corresponding permissions. The following are some commonly used authorization commands:

  • Give the user "newuser" permissions and allow them to access the database "exampledb" from anywhere:
GRANT ALL PRIVILEGES ON exampledb.* TO 'newuser'@'%';
Copy after login
  • Give the user "newuser" permission, allowing it to access all databases from the local area:
GRANT ALL PRIVILEGES ON *.* TO 'newuser'@'localhost';
Copy after login
  • Give the user "newuser" permission, allowing it to access the database "exampledb" from the local area, and only allow SELECT and INSERT operations :
GRANT SELECT,INSERT ON exampledb.* TO 'newuser'@'localhost';
Copy after login
  1. Revoke permissions

If you need to revoke the permissions of a user, you can use the following command:

  • Revoke user All permissions for "newuser" to access database "exampledb" from anywhere:
REVOKE ALL PRIVILEGES ON exampledb.* FROM 'newuser'@'%';
Copy after login
  • Revoke permissions for user "newuser" to access all databases locally:
REVOKE ALL PRIVILEGES ON *.* FROM 'newuser'@'localhost';
Copy after login
  • Revoke the SELECT and INSERT permissions of user "newuser" to access the database "exampledb" locally:
REVOKE SELECT,INSERT ON exampledb.* FROM 'newuser'@'localhost';
Copy after login

When setting MySQL permissions, you also need to pay attention to the following points:

  • When authorizing users, you should try to grant the minimum necessary permissions to reduce risks.
  • When using "%" to specify remote access, you should try to limit the scope to reduce security risks.
  • After authorizing users, permission audits should be performed regularly to ensure the security of permissions.

In summary, MySQL permission settings are very important and are also part of database security management. Basic permission settings can be made through the above commands, but in specific use, they need to be flexibly adjusted according to the actual situation.

The above is the detailed content of How to set mysql permissions in linux. 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
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!