MySQL Study Notes (1)

Source: Internet
Author: User

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)

);

 

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.