Mysql record replication Import and export

Source: Internet
Author: User

Copying records
Lower case-insensitive functions
Password encryption function

CREATE TABLE Employee
> CREATE TABLE employee (ID int,name char (), AGI int,sex enum (' M ', ' F '), Department char (10));
> INSERT into employee values (g, ' John ', ', ' m ', ' Engi '), ("Sue", "F", ' fiance '), (113, ' David ', num, ' m ', ' Admin ');
> select * from Employee;
+------+-------+------+------+------------+
| ID | name | AGI | sex | Department |
+------+-------+------+------+------------+
| 23 | John | 27 | M | Engi |
| 31 | Sue | 31 | F | Fiance |
| 113 | David | 26 | M | Admin |
+------+-------+------+------+------------+

CREATE TABLE User
> CREATE table User (UID int primary key Auto_increment,uname char (), UPass char (10));

Copying records
> INSERT into User (Uname,upass) select lower (name), password (lower (name)) from employee;
> select * from User;
+-----+-------+------------+
| UID | uname | UPass |
+-----+-------+------------+
| 1 | John | *dacde7f57 |
| 2 | Sue | *934b89788 |
| 3 | David | *8201e0c1b |
+-----+-------+------------+


When you copy a record, you can add a where condition
> INSERT into User (Uname,upass) Select (name), password (name) from employee where department= ' fiance ';
> select * from User;
+-----+-------+------------+
| UID | uname | UPass |
+-----+-------+------------+
| 1 | John | *dacde7f57 |
| 2 | Sue | *934b89788 |
| 3 | David | *8201e0c1b |
| 4 | Sue | *287E48EAA |
+-----+-------+------------+

--------------------------------------------------------------------------------------------------------------- -----------------------------------------


Import data
Load Data infile ...

Grammar:

Load data infile ' file absolute path ' into table name fields terminated by ' field delimiter ' lines terminated by ' record separator ';

Sample Example:

> Load Data infile '/tmp/a.txt ' into table T20 fields terminated by ': ' Lines terminated by ' n ';


Export data
Select...into outfile ...

Grammar:

Select field from table name into outfile ' File absolute path ' fields terminated by ' field segmentation service ' lines terminated by ' record delimiter ';

Sample Example:

> select * from T20 to outfile '/tmp/b.txt ' fields terminated by ': ' Lines terminated by ' n ';

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.