Programming/MySQL/Databases

From Dev Wiki
< Programming‎ | MySQL
Revision as of 20:36, 2 November 2020 by Brodriguez (talk | contribs) (Import from original mysql page)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Databases

MySQL splits things up into individual "databases". Generally speaking, each database is a cohesive, separate project.

Creating a New Database

From the MySQL Shell:

 CREATE DATABASE <database_name>; 
  • Where <database_name> is replaced by the desired name for the database. Must be unique from all other existing databases in the MySQL server.

To specify the database character set:

 CREATE DATABASE <database_name> DEFAULT CHARACTER SET utf8mb4 DEFAULT COLLATE utf8mb4_general_ci; 

Note that utf8mb4 is the preferred character set for most situations. See this link for details.

Loading a Database

From the MySQL Shell:

 USE <database_name>; 
  • Where <database_name> is replaced by the name of database you wish to select/load.
  • Note that only one database can be selected/loaded at a time.

Deleting a Database

From the MySQL Shell:

 DROP DATABASE <database_name>; 
  • Where <database_name> is replaced by the name of the database to delete. Note that this action cannot be undone.