Get the App
SLTechnology News&Howtos  ›  Database  › 

MySQL cases of adding accounts, granting permissions, and deleting users

Shulou Source: shulou.com Published: 2022-06-01 02:41:09 10月01日 Update

MySQL cases of adding accounts, granting permissions, and deleting users? This problem may be often seen in our daily study or work. I hope you can gain a lot from this question. The following is the reference content that the editor brings to you, let's take a look at it!

1. Add account:

# create a testuser account with a password of 123456 # if you do not write [identified by '123456'], create a testuser account with an empty password mysql > create user testuser identified by' 123456 account # refresh permission change mysql > flush privileges

two。 Grant authority

# Grant all local access to all databases to the testuser account mysql > grant all privileges on *. * to 'testuser'@'localhost' identified by' 123456 permissions MySQL > flush privileges

Command format:

Grant privilegesCode on dbName.tableName to username@host identified by "password"

PrivilegesCode indicates the type of permission granted. The following types are commonly used:

All privileges: all permissions

Select: read permission

Delete: delete permission

Update: update permissions

Create: create permission

Drop: delete database and data table permissions.

The complete permission types are as follows:

Select_priv: Y Insert_priv: Y Update_priv: Y Delete_priv: Y Create_priv: Y Drop_priv: Y Reload_priv: Y Shutdown_priv: Y Process_priv: Y File_priv: Y Grant_priv: Y References_priv: Y Index_ Priv: Y Alter_priv: Y Show_db_priv: Y Super_priv: Y Create_tmp_table_priv: Y Lock_tables_priv: Y Execute_priv: Y Repl_slave_priv: Y Repl_client_priv: Y Create_view_priv: Y Show_view_priv: Y Create_routine_priv: Y Alter_routine_priv: Y Create_user _ priv: Y Event_priv: Y Trigger_priv: YCreate_tablespace_priv: Y

Detailed introduction of readable MySQL official documents

DbName.tableName represents a specific library or table that grants permissions. The following options are commonly used:

*. *: grant permissions to all tables in all databases of this database server

Permissions granted by dbName.*: to all tables in the dbName database

DbName.dbTable: Grant permissions to the dbTable table in the database dbName.

Username@host represents the granted user and the IP address that the user is allowed to log on to. There are several types of host:

Localhost: only this user is allowed to log in locally, not remotely.

%: allow remote login on any machine other than this machine.

192.168.1.11: a specific IP indicates that only this user is allowed to log in from a specific IP.

Identified by "password": indicates the password of the access user. Without this statement, the default password is empty.

View commands granted by permissions:

Mysql > show grants for 'testuser'

3. Delete user

# delete the testuser user with local access that you just created, drop user testuser@'localhost';. Thank you for reading! After reading the above, do you have a general understanding of MySQL's cases of adding accounts, granting permissions, and deleting users? I hope the content of the article will be helpful to all of you. If you want to know more about the relevant articles, you are welcome to follow the industry information channel.

Tags: Permissions users data accounts databases logins content passwords types cases commands frequently used articles questions addresses official datasheets documents more server Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology OPPO Reno Shulou Information Redmi Linux