MySQL Cheat Sheet

·

2 min read

Introduction

MySQL is a DBMS (Database Management System) using SQL (Structured Query Language) commands that are widely used today in making web-based applications. MySQL is divided into two licenses, the first is Free Software where the software can be accessed by anyone. And second is Shareware where proprietary software has limitations in its use.

MySQL is included in the RDBMS (Relational Database Management System). So, using tables, columns, rows, in its database structure. So, in the process of data collection using the relational database method. And also a liaison between the software and the database server.

Cheat Sheet

This article will discuss cheat sheets related to mysql, can be used as a guide when you forget mysql commands, of course this also makes me want to have a mysql cheat sheet, so when I forget I can open this article and if I don't find it here, I'll google it and add it here.

Create a New User

CREATE USER 'new_user'@'localhost' IDENTIFIED BY 'your_password';
GRANT ALL PRIVILEGES ON * . * TO 'new_user'@'localhost';
FLUSH PRIVILEGES;

Grant User Permissions

Here is a short list of other common possible permissions that users.

  • ALL PRIVILEGES- as we saw previously, this would allow a MySQL user full access to a designated database (or if no database is selected, global access 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

Example

GRANT type_of_permission ON database_name.table_name TO 'new_user'@'localhost';

Revoke User Permissions

REVOKE type_of_permission ON database_name.table_name FROM 'username'@'localhost';

Show Grant User

SHOW GRANTS FOR 'new_user'@'localhost';

Delete User

DROP USER 'new_user'@'localhost';

Created Database

CREATE DATABASE db_name;