Indonesia Website Awards
Indonesia Website Awards

Hello everyone, I want to share some tips regarding MySQL / MariaDB user privileges settings. If you have read my post about Tips for Creating MySQL / MariaDB Database Users, there I have explained a little about the importance of managing database user privileges. Why is privilege setting important? because if we don’t manage it, aka give full access to the user, we are afraid that there will be abuse of the database user itself. As an example, there is a new developer, he is not very good at querying the database, so he accidentally deletes data or even tables and databases, which is very dangerous. Therefore MySQL / MariaDB provides privilege rules for the user to minimize errors that can occur.

For that, just go ahead, here are the privileges rules in MySQL / MariaDB:

PrivilegesKeterangan
ALL [PRIVILEGES]Grants all access rights, except GRANT OPTION
ALTERPrivilege to change table (query ALTER TABLE)
ALTER ROUTINEPrivileges to modify stored routines
CREATEPrivileges to create tables and databases
CREATE ROUTINEPrivilege for creating and deleting stored routines
CREATE TABLESPACEPrivilege to create, modify and delete tablespaces and log files
CREATE TEMPORARYTABLESPrivilege to create temporary tables
CREATE USERPrivilege to create, delete, and modify users (query: CREATE USER, DROP USER, RENAME USER and REVOKE ALL PRIVILEGES)
CREATE VIEWPrivilege to create and modify views
DELETEPrivilege to delete data (query DELETE)
DROPPrivilege to delete databases, tables and views
EVENTPrivilege to create events
EXECUTEPrivilege for running stored routines
FILEPrivilege to make the server read or create files
GRANT OPTIONPrivilege to grant access rights to other users.
INDEXPrivilege to create and delete index
INSERTPrivilege to add data (INSERT query)
LOCK TABLESPrivilege to lock tables (query LOCK TABLES)
PROCESSPrivilege to see the whole process (query SHOW PROCESSLIST)
PROXYPrivilege for the proxy process
REFERENCESPrivilege Creation of foreign key constraints
RELOADPrivilege for FLUSH operations
REPLICATION CLIENTPrivilege to change the order of master and slave servers
REPLICATION SLAVEPrivilege for replication servers to read binary event logs from the Master server
SELECTPrivilege to view data (SELECT query)
SHOW DATABASESPrivilege to view the entire database (query SHOW DATABASES)
SHOW VIEWPrivilege to view view creation (query SHOW CREATE VIEW)
SHUTDOWNPrivilege for mysqladmin shutdown
SUPERPrivilege for server administration functions, such as CHANGE MASTER TO, KILL, PURGE BINARY LOGS, SET GLOBAL, and mysqladmin debug commands
TRIGGERPrivilege for trigger operations
UPDATEPrivilege to update data (query UPDATE)
USAGEThe same means without access rights

then how to use it, just run a query like this:

GRANT privileges ON `databaseName`.`TableName` TO 'user'@'IPaddress';
GRANT privileges ON `databaseName`.`TableName` TO 'user'@'IPaddress';

example :

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
#1
GRANT ALL PRIVILEGES ON *.* TO 'admin'@'127.0.0.1';
#2
GRANT SELECT, SHOW VIEW ON `myDatabase`.* TO 'admin'@'127.0.0.1';
#3
GRANT SELECT, INSERT, UPDATE, DELETE ON `myDatabase`.`myTable` TO 'admin'@'127.0.0.1';
#1 GRANT ALL PRIVILEGES ON *.* TO 'admin'@'127.0.0.1'; #2 GRANT SELECT, SHOW VIEW ON `myDatabase`.* TO 'admin'@'127.0.0.1'; #3 GRANT SELECT, INSERT, UPDATE, DELETE ON `myDatabase`.`myTable` TO 'admin'@'127.0.0.1';
#1
GRANT ALL PRIVILEGES ON *.* TO 'admin'@'127.0.0.1';
#2
GRANT SELECT, SHOW VIEW ON `myDatabase`.* TO 'admin'@'127.0.0.1';
#3
GRANT SELECT, INSERT, UPDATE, DELETE ON `myDatabase`.`myTable` TO 'admin'@'127.0.0.1';

Little explanation :

#1 for the

*.*
*.* Part means that we give that access to all databases and their tables.

#2 we can use a sign

,
, a comma to specify more than one privileges and for the
`myDatabase`.*
`myDatabase`.* Section means that we grant access only to the myDatabase database with access to all the database tables.

#3 we can also grant access only to certain tables in one database with this example

`myDatabase.`myTable`
`myDatabase.`myTable`

a tip from me, set the privileges according to the level and needs of each developer. If at my place of work, for example like this:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
#Privileges for Senior development / Senior Database Administrators (DBA)
GRANT ALL PRIVILEGES ON *.* TO 'superAdmin'@'127.0.0.1';
#Privileges for DBAs in charge of analyzing / patching data
GRANT SELECT, SHOW VIEW, SHOW DATABASES, PROCESS, INSERT, UPDATE, DELETE ON *.* TO 'adminDBA'@'127.0.0.1';
#Privileges for Data Backup users
GRANT SELECT, LOCK TABLES, CREATE VIEW, SHOW VIEW, CREATE ROUTINE ON *.* TO 'backupUser'@'127.0.0.1';
#Privileges for user only read one of the databases
GRANT SELECT, SHOW VIEW ON `databaseX`.* TO 'userX'@'127.0.0.1';
#Privileges for Senior development / Senior Database Administrators (DBA) GRANT ALL PRIVILEGES ON *.* TO 'superAdmin'@'127.0.0.1'; #Privileges for DBAs in charge of analyzing / patching data GRANT SELECT, SHOW VIEW, SHOW DATABASES, PROCESS, INSERT, UPDATE, DELETE ON *.* TO 'adminDBA'@'127.0.0.1'; #Privileges for Data Backup users GRANT SELECT, LOCK TABLES, CREATE VIEW, SHOW VIEW, CREATE ROUTINE ON *.* TO 'backupUser'@'127.0.0.1'; #Privileges for user only read one of the databases GRANT SELECT, SHOW VIEW ON `databaseX`.* TO 'userX'@'127.0.0.1';
#Privileges for Senior development / Senior Database Administrators (DBA)
GRANT ALL PRIVILEGES ON *.* TO 'superAdmin'@'127.0.0.1';

#Privileges for DBAs in charge of analyzing / patching data
GRANT SELECT, SHOW VIEW, SHOW DATABASES, PROCESS, INSERT, UPDATE, DELETE ON *.* TO 'adminDBA'@'127.0.0.1';

#Privileges for Data Backup users
GRANT SELECT, LOCK TABLES, CREATE VIEW, SHOW VIEW, CREATE ROUTINE ON *.* TO 'backupUser'@'127.0.0.1';

#Privileges for user only read one of the databases
GRANT SELECT, SHOW VIEW ON `databaseX`.* TO 'userX'@'127.0.0.1';

Yep, that’s a few tips on MySQL / MariaDB user privileges settings that I can share, I hope my writing can be useful. Thank you ^^.

SOURCE:

6.2.2 Privileges Provided by MySQL

Categories: Database

0 Comments

Leave a Reply

Avatar placeholder

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