Membuat User dan Grant Akses User di MySQL DB CLI

Akses MySQL via linux command line, ketik command di bawah kemudian masukan password:
mysql -u root -p
Membuat user baru di MySQL DB via Command Line Interface:
CREATE USER 'newuser'@'localhost' IDENTIFIED BY 'password';
Grant access dari user yang baru di buat ke database yang sudah ada:
GRANT ALL PRIVILEGES ON * . * TO 'newuser'@'localhost';
Setelah itu ketik command di bawah untuk melihat effeknya:
FLUSH PRIVILEGES;
Berikut adalah beberapa perbedaan grant akses user:
- ALL PRIVILEGES- as we saw previously, this would allow a MySQL user all access to a designated database (or if no database is selected, across the system)
- CREATE- allows them to create new tables or databases
- DROP- allows them to them to delete tables or databases
- DELETE- allows them to delete rows from tables
- INSERT- allows them to insert rows into tables
- SELECT- allows them to use the Select command to read through databases
- UPDATE- allow them to update table rows
- GRANT OPTION- allows them to grant or remove other users' privileges
To provide a specific user with a permission, you can use this framework:
GRANT [type of permission] ON [database name].[table name] TO ‘[username]’@'localhost’;
Berikut adalah cara untuk merevoke user permission:
REVOKE [type of permission] ON [database name].[table name] FROM ‘[username]’@‘localhost’;
Berikut adalah cara untuk drop database:
DROP USER ‘demo’@‘localhost’;