MySQL database operation commands and mysql commands

Source: Internet
Author: User
Tags mysql commands

MySQL database operation commands and mysql commands

Note: MySQL databases are case-insensitive.

1. Create a database:Create database Thinkgamer;

2. delete a database:Drop database Thinkgamer;

3. Select a database:Use Thinkgamer;

4. Create a data table:

Mysql> create table cyan

-> (
-> Student ID int (3) not null primary key,

-> Name char (3 );

-> Gender char (1) not null default 1
->) Engine = innodb;

Press enter. not null indicates that this field cannot be blank. primary key indicates that the primary key is set and default name is 1 by default.

5. delete a table:Drop table cyan;

6. add columns to the table:Alter table cyan add char (20 );

7. display information about the table:Describe cyan;

8. display the information of a column:Select student ID from cyan;

9. add information to the table:Insert cyan values ("111", "Thinkgamer", "female", "dance ");

10. Modify the information of a table row:

Mysql> update cyan
-> Set gender = "male", hobbies = "badminton"

-> Where student no. = 111;

Press enter.

1. Modify the information of multiple tables:

Mysql> update table_name1, table_name2
-> Set table_name1. Gender = "male", table_name2. Gender = "female"

-> Where table_name1.id = table_name2.id;

Press enter.

12. delete a row:Delete from cyan where student ID = 111;

13. remove a person with a gender:Delete from cyan where gender = female;

14. Delete multiple rows from multiple tables:

Mysql> delete table1, table2

-> From table1, table2, table3

-> Where table1.id = table2.id and table2.id = table3.id;

Press enter.

15. Clear table data:Truncate table cyan;

Note: once the data is cleared, it cannot be recovered.

Others:

Select user (); displays the current user.

Select @ version; displays the database version.

Show cyan status; displays the status of the currently used table

Show character set; displays the character sets supported by the database

Show variables like '% char %' view default Character Set

Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

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.