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)