MySQL DDL Operations: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
 
(17 intermediate revisions by the same user not shown)
Line 1: Line 1:
=Internal=
=Internal=
* [[MySQL Operations#Subjects|MySQL Operations]]
* [[MySQL Operations#Subjects|MySQL Operations]]
=Server Version=
<syntaxhighlight lang='sql'>
SELECT VERSION();
</syntaxhighlight>
=Users=
=Users=
==Display Users==
==Display Users==
Line 7: Line 11:
</syntaxhighlight>
</syntaxhighlight>
==Create User==
==Create User==
<syntaxhighlight lang='sql'>
CREATE USER 'someuser'@'localhost' IDENTIFIED BY 'somepassword';
</syntaxhighlight>
==Grant to User All Privileges on a Database==
<syntaxhighlight lang='sql'>
GRANT ALL PRIVILEGES ON some_database.* TO 'someuser'@'localhost';
FLUSH PRIVILEGES;
</syntaxhighlight>
==Show Privileges==
<syntaxhighlight lang='sql'>
SHOW GRANTS FOR 'someuser'@'localhost';
</syntaxhighlight>
==Delete User==
<syntaxhighlight lang='sql'>
DROP USER 'someuser'@'localhost';
</syntaxhighlight>
=Database=
==Display Databases==
<syntaxhighlight lang='sql'>
SHOW DATABASES;
</syntaxhighlight>
=Check if a Database Exists=
<syntaxhighlight lang='sql'>
SHOW DATABASES LIKE 'some_database';
</syntaxhighlight>
<syntaxhighlight lang='sql'>
SELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME='some_database'"
</syntaxhighlight>
==Create Database==
<syntaxhighlight lang='sql'>
CREATE DATABASE some_database;
</syntaxhighlight>
==Delete Database==
<syntaxhighlight lang='sql'>
DROP DATABASE some_database;
</syntaxhighlight>
=Tables=
==Show Tables==
Show the tables in the database.
<syntaxhighlight lang='sql'>
SHOW TABLES;
</syntaxhighlight>
==Create Table==
{{Internal|SQL_CREATE_ALTER_DROP_TABLE#CREATE|Standard SQL Syntax}}
=Views=
==Create View==
{{Internal|SQL_CREATE_ALTER_DROP_VIEW#CREATE|Standard SQL Syntax}}

Latest revision as of 17:08, 23 May 2024

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