MySQL command line common commands

Source: Internet
Author: User

1. Display the list of databases.
show databases;
2. Display the data table in the library:
Use MySQL;
Show tables;
3, display the structure of the data table:
describe table name;
4, build the library:
Create database name;
5, build the table:
Use library name;
CREATE TABLE table name (field settings list);
6. Deleting the library and deleting the table:
drop database name;
drop table name;
7. Empty the records in the table:
Delete from table name;
8. Display the records in the table:
SELECT * FROM table name

9, the change shows:

ALTER TABLE table_name rename Table_new_name;

10. Copy the table

1?? Copy table structure and data to a new table

CREATE Table New Table SELECT * from old table

This method will copy all the contents of oldtable, of course, we can use the delete from newtable; To delete. But one of the worst things about this approach is that the new table has no properties such as primary key, Extra (auto_increment), and so on. Need to use "alter&quot, add, and easy to mistake.

2?? Copy table structure to new table only

CREATE table new table SELECT * from old table WHERE 1=2 or CREATE table new tables like old table

3?? Copy data from old table to new table (assuming two table structure)

INSERT into new table SELECT * from old table

MySQL command line common commands

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.