Mysql record copy import and export _ MySQL

Source: Internet
Author: User
Mysql record copy import and export bitsCN.com


Mysql record copy import and export

Copy record

Lower case-insensitive function

Password encryption function

Create table employee

> Create table employee (id int, name char (10), agi int, sex enum ('M', 'F'), department char (10 ));

> Insert into employee values (23, 'John', 27, 'M', 'engi '), (31, 'Sue', 31, 'F ', 'Fiance '), (113, 'David', 26, '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 (10), upass char (10 ));

Copy record

> 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 |

+ ----- + ------- + ------------ +

You can add the where condition when copying a record.

> 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 |

+ ----- + ------- + ------------ +

Certificate -----------------------------------------------------------------------------------------------------------------------------------------------------

Import data

Load data infile...

Syntax:

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

Example:

> Load data infile '/tmp/a.txt' into table t20 fields terminated by ': 'Lines terminated by'/N ';

Export data

Select... into outfile...

Syntax:

Select field from table name into outfile' absolute path of the file 'Fields terminated by' field segmentation server 'lines terminated by' record delimiter ';

Example:

> Select * from t20 into outfile '/tmp/B .txt' fields terminated by ': 'Lines terminated by'/N ';

BitsCN.com

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.