MySQL DDL Operations

From NovaOrdis Knowledge Base
Revision as of 17:08, 23 May 2024 by Ovidiu (talk | contribs) (→‎Tables)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Internal

Server Version

SELECT VERSION();

Users

Display Users

SELECT USER FROM mysql.user;

Create User

CREATE USER 'someuser'@'localhost' IDENTIFIED BY 'somepassword';

Grant to User All Privileges on a Database

GRANT ALL PRIVILEGES ON some_database.* TO 'someuser'@'localhost';
FLUSH PRIVILEGES;

Show Privileges

SHOW GRANTS FOR 'someuser'@'localhost';

Delete User

DROP USER 'someuser'@'localhost';

Database

Display Databases

SHOW DATABASES;

Check if a Database Exists

SHOW DATABASES LIKE 'some_database';
SELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME='some_database'"

Create Database

CREATE DATABASE some_database;

Delete Database

DROP DATABASE some_database;

Tables

Show Tables

Show the tables in the database.

SHOW TABLES;

Create Table

Standard SQL Syntax

Views

Create View

Standard SQL Syntax