头像如何上传到mysql_MySQL->导出/导入资料[20180521]

MySQL 导出

INTO OUTFILE将资料导出至文件中

mysqldump工具导出资料和数据结构,并且可以针对数据库、数据表、索引的结构。

INTO OUTFILE测试

select * from seq_test into outfile '/tmp/backup_v0.txt';

9067832.html

d6e8b7605ec31f0227317d02018433c5.png

生成一个文件,各值用逗号隔开

select *  into outfile '/tmp/backup_v1.txt' fields terminated by ',' enclosed by '"' lines terminated by '\n' from seq_test;

9067832.html

1364803020eb48312fa4ee517a37ebd3.png

select * from seq_test into outfile '/tmp/backup_v2.txt' fields terminated by ',' enclosed by '"' lines terminated by '\r\n' ;

9067832.html 

4e59a5b032ff051bda528a9a7e7a13be.png

mysqldump工具导出原始资料

mysqldump -u root -p runoob seq_test|gzip > backup_data.zip

9067832.html

f7ec71cdcfb12213ddb1404bc3bd42be.png

也可以使用以下命令将导出的数据直接导入到远程的服务器上,但请确保两台服务器是相通的,是可以相互访问的:

$ mysqldump -u root -p database_name \

| mysql -h other-host.com database_name

资料导入

针对使用INTO OUTFILE方式导出的资料,可以使用LOAD DATA LOCAL INFILE方式导入资料。

LOAD DATA LOCAL INFILE '/tmp/backup_v0.txt' INTO TABLE seq_test;

mysql> select count(*) fromseq_test;+----------+

| count(*) |

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

| 111 |

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

1 row in set (0.00sec)

mysql> truncate tableseq_test;

Query OK,0 rows affected (0.00sec)

mysql> LOAD DATA LOCAL INFILE '/tmp/backup_v0.txt' INTO TABLEseq_test;

Query OK,111 rows affected (0.00sec)

Records:111 Deleted: 0 Skipped: 0 Warnings: 0mysql> select count(*) fromseq_test;+----------+

| count(*) |

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

| 111 |

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

1 row in set (0.00sec)

9067832.html

f47d43d9615bc214a4b14582336499eb.png

还可以使用mysqlimport工具导入

[root@t-xi-mysql01 tmp]# cp backup_v0.txt seq_test.txt

[root@t-xi-mysql01 tmp]#  mysqlimport -u root -p --local runoob seq_test.txt

Enter password:

runoob.seq_test: Records: 111  Deleted: 0  Skipped: 111  Warnings: 0

将mysqldump导出的资料进行导入

gunzip  -c backup_data.zip>backup_data.sql

mysql -u root -p

mysql> source backup_data.sql

[root@t-xi-mysql01 tmp]# mysqldump -u root -p runoob seq_test|gzip >backup_data.zip

Enter password:[root@t-xi-mysql01 tmp]# gunzip -c backup_data.zip>backup_data.sql[root@t-xi-mysql01 tmp]#[root@t-xi-mysql01 tmp]# mysql -u root -p

Enter password:

Welcometo the MySQL monitor. Commands end with ; or\g.

Your MySQL connection idis 18Server version:5.1.71Source distribution

Copyright (c)2000, 2013, Oracle and/or its affiliates. Allrights reserved.

Oracleis a registered trademark of Oracle Corporation and/orits

affiliates. Other names may be trademarksoftheir respective

owners.

Type'help;' or '\h' for help. Type '\c' to clear the currentinput statement.

mysql> userunoob;

Readingtable information for completion of table and columnnames

You can turnoff this feature to get a quicker startup with -ADatabasechanged

mysql>source backup_data.sql

Query OK,0 rows affected (0.00sec)

Query OK,0 rows affected (0.00sec)

Query OK,0 rows affected (0.00sec)

Query OK,0 rows affected (0.00sec)

Query OK,0 rows affected (0.00sec)

Query OK,0 rows affected (0.00sec)

Query OK,0 rows affected (0.00sec)

Query OK,0 rows affected (0.00sec)

Query OK,0 rows affected (0.00sec)

Query OK,0 rows affected (0.00sec)

Query OK,0 rows affected (0.00sec)

Query OK,0 rows affected (0.00sec)

Query OK,0 rows affected (0.00sec)

Query OK,0 rows affected (0.01sec)

Query OK,0 rows affected (0.00sec)

Query OK,0 rows affected (0.00sec)

Query OK,0 rows affected (0.00sec)

Query OK,111 rows affected (0.00sec)

Records:111 Duplicates: 0 Warnings: 0Query OK,0 rows affected (0.00sec)

Query OK,0 rows affected (0.00sec)

Query OK,0 rows affected (0.00sec)

Query OK,0 rows affected (0.00sec)

Query OK,0 rows affected (0.00sec)

Query OK,0 rows affected (0.00sec)

Query OK,0 rows affected (0.00sec)

Query OK,0 rows affected (0.00sec)

Query OK,0 rows affected (0.00sec)

Query OK,0 rows affected (0.00sec)

mysql> select count(*) fromseq_test;+----------+

| count(*) |

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

| 111 |

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

1 row in set (0.00 sec)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值