Frequent queries to the MySQL DBMS

2021.09.22  |  51

A set of popular queries for creating a base, user, etc.

Create DB
CREATE DATABASE sitename_ru;
Create a user
CREATE USER 'sitename_ru'@'localhost' IDENTIFIED WITH mysql_native_password BY 'YOUR_PASSWORD_HERE';
We give the user rights to the created database
GRANT ALL ON sitename_ru.* TO 'sitename_ru'@'localhost';
Refresh privileges
FLUSH PRIVILEGES;
Removing privileges and user:
REVOKE ALL PRIVILEGES, GRANT OPTION FROM 'sitename_ru'@'localhost';
DROP USER 'sitename_ru'@'localhost';
An example of creating a table with 3 columns:
CREATE TABLE `sitename_ru`.`test` ( `id` INT NOT NULL AUTO_INCREMENT , `user_id` INT NOT NULL , `data` MEDIUMTEXT NOT NULL , PRIMARY KEY (`id`)) ENGINE = InnoDB;