MySQL First knowledge 3

Source: Internet
Author: User

With the familiarity of MySQL, this time to summarize the MySQL database delete, backup and restore operations

1. Deletion of the database:

A. Command to delete a database: Drop DB dbname;

B. Deleting a table from a database:

Single table: Drop TABLE tablename;

Multiple tables: Drop table tablename1,tablename2,tablename2; (Note that there are no fewer commas here, but when backing up multiple tables, there is no comma between multiple tables, which is written below)

C. Deleting records from a table: Delete;truncate table Two methods

Delete command: Delete from tablename (WHERE ..... LIMIT ....)

Can delete all records, or according to the criteria to choose to delete some of the data, the use of more flexible;

TRUNCATE command: TRUNCATE TABLE tablename;

Delete all records, cannot attach conditional clauses;

There is also a small difference: Delete can return the number of records deleted, TRUNCATE returns the number of records is 0 (the specific application of the two differences is not familiar with, and then after the familiar and then fill in)

2. Backup & Restore

Single database backup command: Mysqldump-u root-p dbname >/home/wuliang/dbname_backup.sql (dbname is the name of the database that needs to be backed up,/home/wuliang these are required for backup files Saved paths,. SQL backup files are stored in this format)

Table Backup in database: Mysqldump-u root-p dbname table1 table2 table3 >/home/wuliang/name_backup.sql (Note: There is no need to separate commas between multiple tables)

Multiple database backup commands: Mysqldump-u root-p--databases dbname1 dbname2 dbname3 >/home/wuliang/bcakup.sql (--databases to declare multiple databases)

Full database backup: Mysqldump-u root-p-all-databases >/home/wuliang/backup.sql (-all-databases to declare all databases)

Database restore: Mysql-u root-p

Welcome to files in database: Mysql-u root-p dbname

MySQL First knowledge 3

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.