Simple mysql database operations

Source: Internet
Author: User

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.

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.