Simple Mysql tutorial (3) and simple mysql tutorial

Source: Internet
Author: User
Tags mysql tutorial

Simple Mysql tutorial (3) and simple mysql tutorial

In the previous article, I introduced a simple mysql tutorial (2)

Merge two tables with the same structure in mysql: (Note that the structure of the two tables must be the same)

There are two tables with the following structure: father and person.

Merge steps:

1. output the tables "person" and "father" to the temporary table "tmp.

Command:> create temporary table tmp select * from person union select * from father;

2. Create a result table and a primary key.

Command:> create table resu (name varchar (20) primary key, age int, high int, address varchar (20 ));

3. Filter duplicate data in the temporary table and write it to resu.

Command:> insert into resu (name, age, high, address) select distinct name, age, high, address from tmp;

4. Delete the temporary table tmp.

Command:> drop table tmp;

Think: ① can I use only the following command:> create table tmp select * from person union select * from father; to create a new table?

② If the two tables are from the same database, how can we merge the two tables from different databases?

③ The above two tables are merged up and down. What about the left and right tables?

There are many methods for backing up mysql databases. Here we will use command parameters for backup.

Note that database backup must be performed under the system command line, rather than under the mysql command.

1. Export the entire database.

Command: $ mysqldump-u username-p Password Database Name> exported file name

Note: a. The password can be entered in invisible form in the second line, which is the safest.

B. the exported file needs to be created by yourself. It is best to end with a. SQL format.

2. Export a table.

Command: $ mysqldump-u username-p Password Database Name Table Name> exported file name

As shown above, exporting a table is similar to exporting a database.

The above is a simple Mysql tutorial (iii). I hope it will be helpful to you. If you have any questions, please leave a message, the editor will reply to you in a timely manner. Thank you very much for your support for the help House website!

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.