Simple use of MySQL (iii)

Source: Internet
Author: User

Simple use of MySQL above (ii)

Merge two tables with the same structure in MySQL: (note the structure of two tables is the same)

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

The steps for merging are:

1. The person table and the Father table two tables are combined to output to the TEMP table tmp.

The command is:>create temporary table tmp SELECT * from person Union select *from Father;

2. Create a result table and create a primary key.

The command is: >create table resu(name varchar) primary key, age int, high int, Address varchar (20));

3. Filter and write duplicate data in temporary table to ResU.

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

4. Delete the temp table tmp.

The command is: >drop table tmp;

Thinking: ① can use only one of the following commands:>create table tmp SELECT * from person Union select *from Father; to create a new table?

② The two tables above are all from the same database, how are two tables from different databases merged?

③ above is two tables up and down merge, then the left and right merge?

——————————————————————————————————————————————————————————

For MySQL database backup, there are a number of methods, which are chosen to use the command parameter backup.

It is important to note that the backup of the database needs to be done under the system command line, not under the MySQL command.

1. Export the entire database.

Command: $mysqldump-u user name -P password database name > exported file name

Note: A. Password can be entered in the second line in an invisible form, which is the safest.

B. The exported file needs to be built on its own, preferably ending in. sql format.

2. Export a table.

Command:$mysqldump-u user name -P Password database name > exported file name

As seen above, exporting a table is much the same as exporting a database.

——————————————————————————————————————————————————————————————————————————

Simple use of MySQL (iii)

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.