Student ID: 2 Name: Li Si Age: 23 Nationality: Shanxi |
Student ID: 1 Name: James Age: 22 Local place: Beijing |
In the above cases, we found that the space for using paper is wasted.
Table
Student ID |
Name |
Age |
Nationality |
1 |
Zhang San |
22 |
Beijing |
2 |
Li Si |
23 |
Shanxi |
The table can only delete rows, but cannot delete columns.
Server-database-table-row (minimum operation unit: Row)
MySQL entry statement:
1. How to connect to the server
Server address (available IP address and domain name): Port (3306)
User Name
Password
Mysql-H localhost-u uername-P passwd
For example, MySQL-H localhost-u root-P
Enter Password: 870210
Or: mysql-uroot-p870210 is hard to write and the password is easy to leak.
-H if this parameter is not set, localhost is used by default.
Exit command: Exit
If an error occurs, \ C can be used to complete the event and the statement is like a new statement.
For example, mysql> show databases (the score is missing)
-> \ C
Mysql>
2. Check the number of databases on the server.
Show databases;
Command end with a semicolon (;)
3. Create a database
Create Database mydatabase;
Create a database named mydatabase
4. Select a database
Use mydatabase; (this statement can be left blank)
Mydatabase
5. View tables under the database
Show tables;
6. delete a database
Drop database mydatabase;
Delete database mydatabase
Note: The database name cannot be modified.
7. Create a table
Mysql> Create Table class (
-> Stu int,
-> Name varchar (20 ),
-> Age int,
-> Area varchar (20)
-> );
Note that the last column does not need to be separated by commas (,)
Add another table:
Mysql> Create Table score (
-> Stu int,
-> Name varchar (20 ),
-> Ke varchar (10 ),
-> Fen int
-> );
8. Modify the table name
Syntax: rename table oldname to newname
For example, rename table score to newscore;
9. Delete table name
Drop table newscore;
Delete table newscore
10. view the table structure
Desc class;
View the (description) class Table Structure
Create a comment table:
Create Table MSG (
Id int,
Title varchar (60 ),
Name varchar (10 ),
Content varchar (1, 1000)
);