[{"createTime":1735734952000,"id":1,"img":"hwy_ms_500_252.jpeg","link":"https://activity.huaweicloud.com/cps.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=V1g3MDY4NTY=&utm_medium=cps&utm_campaign=201905","name":"华为云秒杀","status":9,"txt":"华为云38元秒杀","type":1,"updateTime":1735747411000,"userId":3},{"createTime":1736173885000,"id":2,"img":"txy_480_300.png","link":"https://cloud.tencent.com/act/cps/redirect?redirect=1077&cps_key=edb15096bfff75effaaa8c8bb66138bd&from=console","name":"腾讯云秒杀","status":9,"txt":"腾讯云限量秒杀","type":1,"updateTime":1736173885000,"userId":3},{"createTime":1736177492000,"id":3,"img":"aly_251_140.png","link":"https://www.aliyun.com/minisite/goods?userCode=pwp8kmv3","memo":"","name":"阿里云","status":9,"txt":"阿里云2折起","type":1,"updateTime":1736177492000,"userId":3},{"createTime":1735660800000,"id":4,"img":"vultr_560_300.png","link":"https://www.vultr.com/?ref=9603742-8H","name":"Vultr","status":9,"txt":"Vultr送$100","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":5,"img":"jdy_663_320.jpg","link":"https://3.cn/2ay1-e5t","name":"京东云","status":9,"txt":"京东云特惠专区","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":6,"img":"new_ads.png","link":"https://www.iodraw.com/ads","name":"发布广告","status":9,"txt":"发布广告","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":7,"img":"yun_910_50.png","link":"https://activity.huaweicloud.com/discount_area_v5/index.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=aXhpYW95YW5nOA===&utm_medium=cps&utm_campaign=201905","name":"底部","status":9,"txt":"高性能云服务器2折起","type":2,"updateTime":1735660800000,"userId":3}]
在这里提供2中方式:
建议:可以使用方式二,就不使用方式一。
方式一:
在linux下支持,window下不支持。
进入到mysql的bin目录,或者已经给mysql配置了环境变量就不用进入bin目录。
原理:
通过mysql工具的-e参数,可以执行select、update、delete、insert语句。
通过mysql -u用户名 –p密码 数据库 –esql语句 > 文件路径/文件名
利用linux的>写入操作,将mysql通过-e参数执行的语句结果输出到文件中去。
通过mysql 导出方式:
./mysql -uliuxioali -p1452liu www -e " SELECT
a.phone
FROM
user_info a
LIMIT 10" > phone.txt
讲解:
./mysql -uliuxioali -p1452liu www -e " SELECT
a.phone
FROM
user_info a
LIMIT 10"
执行查询,正常情况会将结果输出到控制台。
> phone.txt
获取上一句的结果输出到phone.txt文件中
方式二:
需要设置mysql只读参数:
默认值为:
secure_file_priv=NULL
必须在my.ini(window默认路径:C:\Windows)或my.cnf(linux默认路径/etc/my.cnf) 中设置
secure_file_priv=’’或secure_file_priv=’/tmp’
secure_file_priv=’’ 可以任意指定文件输出路径
secure_file_priv=’/tmp’ 生成文件都输出到了/tmp文件路径下
并且重启mysql服务,如果是在生产环境必须晚上配置重启服务。
在mysql内部执行。
原理:
就是mysql提供的导出数据的一种语法。
语法:
SELECT ... FROM TABLE_A INTO OUTFILE "/path/to/file.csv" FIELDS TERMINATED
BY ',' OPTIONALLY ENCLOSED BY '"' LINES TERMINATED BY '\n';
语法解析:FIELDS TERMINATED BY ',' 指定字段之间的分割符
OPTIONALLY ENCLOSED BY '"' 指定每个字段值得前后符号 结果为 "12"
LINES TERMINATED BY '\n' 指定换行符,因为window和linux换行符不一样。Window是\r\n linux是\n
例句:
SELECT phone FROM user_info WHERE phone is NOT NULL LIMIT 10 INTO OUTFILE
'F:\\txt.txt' FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' LINES
TERMINATED BY '\n' ;
输出结果如下:
"13519000118"
"13519000122"
"13519000151"
"13519000187"
"13519000216"
"13519000248"
"13519000303"
"13519000364"
"13519000401"
"13519000492"