The following statement grants SELECT privilege to crm_read role: GRANT SELECT ON crm.* The following statement grants all privileges to crm_dev role: GRANT ALL ON crm.* To grant privileges to a role, you use GRANT statement. If you omit the host part, it defaults to ‘%’ that means any host. The role name is similar to the user account that consists of two parts: the name and host: Code language: SQL (Structured Query Language) ( sql ) To create new roles, you use CREATE ROLE statement: CREATE ROLEĬrm_write Code language: SQL (Structured Query Language) ( sql ) To avoid granting privileges to each user account individually, you create a set of roles and grant the appropriate roles to each user account. In addition, you need to create accounts for users who need only read access and others who need both read/write access. To interact with the CRM database, you need to create accounts for developers who need full access to the database. Suppose you develop an application that uses the CRM database. VALUES( 'John', 'Doe', '(408)-987-7654', 'Lily', 'Bush', '(408)-987-7985', language: SQL (Structured Query Language) ( sql )įinally, verify the insert by using the following SELECT statement: SELECT * FROM customers Ĭode language: SQL (Structured Query Language) ( sql ) Creating roles INSERT INTO customers(first_name,last_name,phone,email) CREATE TABLE customers(Īfter that, insert data into the customers table. Then, create customer table inside the CRM database. CREATE DATABASE crm Ĭode language: SQL (Structured Query Language) ( sql ) MySQL role exampleįirst, create a new database named CRM, which stands for customer relationship management. The changes will take effect to all users to which the role granted. In case you want to change the privileges of the users, you need to change the privileges of the granted role only. If you want to grant the same set of privileges to multiple users, you follow these steps: Like user accounts, you can grant privileges to roles and revoke privileges from them. A role is a named collection of privileges. To make it easier, MySQL provided a new object called role. Previously, the only way to grant and revoke privileges to multiple users is to change the privileges of each user individually, which is time-consuming. Typically, you have multiple users with the same set of privileges. Summary: in this tutorial, you will learn how to use MySQL roles to simplify the privilege managements.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |