How can I grant database permissions to a user in MySQL?

To grant database access to a user, you can use the GRANT statement in MySQL.

Here is the general syntax for granting users access to a database:

Grant permission on the database.table to the username at the specified host.

Among them, the permissions can be one of the following options:

  1. Granting users all privileges.
  2. SELECT: Only grant users the permission to query.
  3. Grant users the permission to insert.
  4. Grant users update permission.
  5. Grant users the permission to delete.
  6. Grant users the permission to create.
  7. DROP: Granting users permission to delete
  8. ALTER: Granting users the permission to modify table structures.

The database name can be a specific database name or * to represent all databases.

Table name can either be a specific table name or “*” to represent all tables.

Username is the name of the user you want to authorize.

The host is the hostname or IP address allowed to access the database.

Here are some examples:

Grant user ‘john’ the permission to query and insert.

Give John the permission to select and insert data into all tables within the database named database_name when connecting from the localhost.

Grant all permissions to user ‘jane’.

Give Jane all privileges for the specified database on the localhost.

Grant all permissions to user ‘jack’ and allow access from any host.

Give all permissions on the specified database to the user ‘jack’ from any host.

After completing the authorization, you need to use the following statement to make the changes take effect.

Refresh privileges.

In this way, users are authorized to access the specified database.

Leave a Reply 0

Your email address will not be published. Required fields are marked *


广告
Closing in 10 seconds
bannerAds