CREATE DATABASE database_name;
The CREATE DATABASE command in MySQL is used to create a new database.
Notes:
CREATE DATABASE IF NOT EXISTS database_name;
This version only creates the database if it does not already exist, avoiding errors.
SHOW DATABASES;
The SHOW DATABASES; command in MySQL is used to list all the databases available on the MySQL server instance you are connected to.
Example output:
+--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | sys | | library_games | +--------------------+
Explanation:
This command is useful for checking which databases are available to manage or query.
USE database_name;
The USE database_name; command in MySQL is used to select a specific database and set it as the active database for the current session.
The CREATE TABLE command is used in MySQL to create a new table within a database. The basic syntax of the command defines the names of the fields (columns) and their respective data types.
CREATE TABLE table_name ( field1 data_type, field2 data_type, ... fieldN data_type );
Components:
Practical example:
Suppose you are creating a table called games to store information about games, where each game has an ID, a title, a genre, and a release date:
CREATE TABLE games ( id INT AUTO_INCREMENT PRIMARY KEY, title VARCHAR(100), gender VARCHAR(50), release_date DATE );
Explanation:
Notes:
The DESC command (or its full form DESCRIBE) is used in MySQL to display the structure of a table. It shows the column names, their data types, and other relevant information, such as whether the column allows null values or is part of a primary key.
CREATE DATABASE database_name;
ou
CREATE DATABASE IF NOT EXISTS database_name;
Example:
Suppose you want to see the structure of the games table created earlier:
SHOW DATABASES;
Example output:
+--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | sys | | library_games | +--------------------+
Output Explanation:
This command is useful for quickly checking the structure of a table without having to look at the original creation code.
The above is the detailed content of MySQL Terminal: Create Databases, Tables and more.. For more information, please follow other related articles on the PHP Chinese website!