The commands commonly used in the MySQL database process are listed below:
- use database name : Select the MySQL database you want to manipulate, and all MySQL commands are only for that database after using this command.
- SHOW DATABASES: lists a list of databases for the MySQL database management system.
- Show TABLES: Displays all tables for the specified database and uses the use command to select the database to manipulate before using the command.
- show COLUMNS from data table : Displays data table properties, property types, primary key information, whether null, default value, and other information.
- Show index from data table : displays detailed index information for the data table, including primary key (primary key).
- SHOW table STATUS like datasheet \g: This command will output the performance and statistics of the MySQL database management system.
Database operations:
Login database:
Mysql-u root-p ' passwd '-P 3306
To exit the database:
Ctrl+d or quit
To modify the database login password (shell command line):
mysqladmin-u root-p Password New password
To create a database:
CREATE DATABASE Mysql_name;
To delete a database:
DROP DATABASE Mysql_name;
View all databases:
SHOW DATABASES;
Open the database:
Use Mysql_name;
Displays the database that was opened;
SELECT Databas ();
Table Operation:
To create a table:
CREATE TABLE table_name (column declaration);
Example: CREATE TABLE student (
ID INT UNSIGNED not NULL PRIMARY KEY auto_increment,
Name CHAR (Ten) is not NULL,
Age TINYINT Not NULL
);
View all the tables:
SHOW TABLES;
To delete a table:
DROP TABLE table_name;
To view the data table structure:
SHOW COLUMNS from table_name;
To rename a table:
ALTER TABLE old_table_name RENAME new_table_name;
Insert data:
INSERT TABLE table_name (column name) values (value);
Delete data:
DELETE from table name [where condition];
To query the data in a table:
SELECT column name from table name [where condition];
Updating data in a table
UPDATE table name SET column name = new value [Where condition];
Querying all data in a table (using wildcard characters)
SELECT * FROM table_name;
The ALTER TABLE statement is used to modify the table after it is created, using the following basic usage
Adding columns
ALTER table name add column Name column data type [after ...] ;
Delete Column
ALTER table name DROP column name;
modifying columns
ALTER table name change column name new column name new data type;
Adjustments to constraints:
MySQL Basic operations Summary