Simple mysql database operations
First, go to mysql: mysql-u root-p
1. database creation:
Create database name;
For example, create database mydata; (create a database named "mydata );
2. Create a table:
Use the name of the database to store the table;
Create table Name (field setting list );
For example, use mydata;Enter the mydata Library
Create table mytable (num VARCHAR (20), name VARCAR (20), birth DATE, sex CHAR (1 ));Create a table named mytable, which contains the student ID, name, birthday, and gender.
3. display all databases:
Show databases;
4. display all tables in a database
Use: the name of the database to be queried;
Show tables;
5. Delete tables and databases:
Delete database: drop database name;
Delete table: drop table name;
6. Clear table records:
Delete from table name;
Truncate table name;
7. display the records in the table:
Select * from table name; * Indicates displaying all records in the table. You can also use different keywords to display them.
If the table contains too many records, only the first few rows can be displayed as follows:
Select * from table name limit number of rows;
For example, select * from mytable limit 100;Display the first 100 rows in the mytable table
8. rename table a to B:
Alter table A rename B;
Other basic SQL statements can be used.