![]() CREATE USER IDENTIFIED BY 'StrongPassword!' Now that the database is created, you can start with a nonadmin user with the CREATE USER MySQL statement. It then makes a new user in the MySQL service and grants that user all privileges for the new database schema (testdb.*). ![]() This SQL code creates a new database named testdb. Replace the placeholder value testdb with your database name. Replace the placeholder value db_user with your intended new user name. Although we touched upon a lot of ways in which we can grant privileges to the users, you have now enough knowledge to start experimenting yourself on the GRANT Command.If you're not sure how to connect, see connect and query data for Single Server or connect and query data for Flexible Server.Įdit and run the following SQL code. In this tutorial, we learn how to create a user in MySQL, the types of privileges, and how to grant the privilege. In the above command, *.* refers that the privilege given for all the databases and tables, respectively. Let’s see the SQL query for the same: GRANT ALL PRIVILEGES ON *.* TO 'localhost' IDENTIFIED BY 'root' Code language: SQL (Structured Query Language) ( sql ) Usually, we don’t assign any user all privileges as this user will have all privileges like a root user, therefore, it must not be given lightly. When we want to grant all the privileges to the user, we’ll use GRANT ALL PRIVILEGE command. ![]() If you want to grant privilege to a user only for a certain column on a table, then you can use the below query: GRANT SELECT (col1), INSERT (col1, col2) ON databaseName.tableName TO 'localhost' IDENTIFIED BY 'root' Code language: SQL (Structured Query Language) ( sql ) Grant privilege for a particular database, see the below query: GRANT ALL on database.* TO 'localhost' IDENTIFIED BY 'root' Code language: SQL (Structured Query Language) ( sql ) GRANT SELECT on *.* TO 'localhost' IDENTIFIED BY 'root' Code language: SQL (Structured Query Language) ( sql ) If we want to grant a read-only privilege to a user, then we can use the below query: Let’s see an example: GRANT CREATE on *.* TO 'localhost' IDENTIFIED BY 'root' Code language: SQL (Structured Query Language) ( sql ) If we want to grant privilege for operations such as insert, delete, update, drop, etc, we can use the GRANT operation as below. In this section, we’ll learn how to grant privileges to the users, open the MySQL command line, or use the command prompt to log into MySQL with a specific user. We will touch upon these pointers in the next section, we will see how to grant privilege for different operations as well as on particular databases and tables.įor more information on privileges, you can read the official documentation.
0 Comments
Leave a Reply. |