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!