
You must specify the column or columns for each privilege, for example: GRANT SELECT (employeeNumner,lastName, firstName,email), If you skip the database name, MySQL uses the default database or issues an error if there is no default database.Ĭolumn privileges apply to single columns in a table. In this example, can delete rows from the table employees in the database classicmodels. To assign table-level privileges, you use the ON database_name.table_name syntax, for example: GRANT DELETE ON classicmodels.employees Table privileges apply to all columns in a table. In this example, can insert data into all tables in the classicmodels database. To assign database-level privileges, you use the ON database_name.* syntax, for example: GRANT INSERT ON classicmodels.* The account user can query data from all tables in all database of the current MySQL Server.ĭatabase privileges apply to all objects in a database. TO language: SQL (Structured Query Language) ( sql ) To assign global privileges, you use the *.* syntax, for example: GRANT SELECT ON *.* Global privileges apply to all databases in a MySQL Server. MySQL supports the following main privilege levels: Second, specify the privilege_level that determines the level to which the privileges apply. The following example grants UPDATE, DELETE, and INSERT privileges on the table employees to GRANT INSERT, UPDATE, DELETE ON employees
#Mysql create user code
TO Code language: SQL (Structured Query Language) ( sql ) This example grants the SELECT privilege on the table employees in the sample database to the user acount GRANT SELECT ON employees If you grant multiple privileges, you need to separate privileges by commas.

TO account_name Code language: SQL (Structured Query Language) ( sql )įirst, specify one or more privileges after the GRANT keyword.

The following illustrates the basic syntax of the GRANT statement: GRANT privilege. And the GRANT statement grants a user account one or more privileges. To allow user accounts to work with database objects, you need to grant the user accounts privileges. It means that the user accounts can log in to the MySQL Server, but cannot do anything such as selecting a database and querying data from tables. The CREATE USER statement creates one or more user accounts with no privileges. Introduction to the MySQL GRANT statement
#Mysql create user how to
Summary: in this tutorial, you will learn how to use the MySQL GRANT statement to grant privileges to user accounts.
