What is the method for creating a table in MySQL using …
The method to create a table using MySQL command line is as follows:
- Open the command line tool (such as Command Prompt in Windows or Terminal in Linux).
- Enter the following command to connect to the MySQL server:
mysql -u username -p
“username” is your MySQL username. After pressing the Enter key, the system will prompt you to enter your password.
- After entering the password, press the Enter key to log in to the MySQL server.
- Create a database (if it has not already been created):
CREATE DATABASE database_name;
The database_name is the name of the database you want to create.
- Choose the database to use:
USE database_name;
database_name is the name of the database you want to use.
- Create a table:
CREATE TABLE table_name (
column1 datatype constraint,
column2 datatype constraint,
...
);
table_name is the name of the table you want to create, column1, column2, etc. are the names of the columns in the table, datatype is the data type of the columns, and constraint refers to any constraints on the columns (e.g. primary key constraint, foreign key constraint, etc.). You can add more columns as needed.
- You can use the following commands to view the tables that have been created:
SHOW TABLES;
The above is the method of creating a table using MySQL command line. Please note that after executing each command, press enter to run that command.