Mysql批量导出与批量导入

本文介绍如何使用SQL语句进行MySQL数据库的数据批量导出和导入操作,并提供了具体的示例代码。文中还讲解了如何通过修改my.ini配置文件来支持自定义文件路径的导入。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

①批量导出

1)如果想把云服务器上的mysql数据库数据导出到本地 只能使用 客户端语句

在终端使用mysql -u root -p test -e 'SELECT loid FROM ana_customer WHERE localnet_id='101000';' > 101000_loid.txt 将表中数据导出到本地

 2)如果使用Mysql的 CAPI接口 的话 那么只能是同实现同一台机器上的数据导出

char sql[1024]

  sprintf_s(sql,"select * into outfile '%s' fields terminated by '%c'LINES TERMINATED BY '\r\n' from %s ", filepath.c_str(), c, tablename.c_str());

②批量导入

char sql[1024]

char c = '"';
 sprintf_s(sql, "load data local infile'%s' into table %s fields terminated by ',' optionally enclosed by'%c'escaped by'%c'lines terminated by'\r\n'", filepath.c_str(), tablename.c_str(), c, c);

 

想用sql语句导入到自己定义的文件下 就需要修改mysql的my.ini配置

使 secure-file-priv=""

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值