mysql导入导出指定数据脚本(含远程)及弊端

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/LGHunter/article/details/83501856

有时候,需要导出表中的指定列的数据,拼接成INSERT语句。如下:
Code(远程导出需要加入参数"-h+ip";本地则去掉该参数,或者将ip换为本地ip即可)

mysql -h+ip -uusername -ppassword -e "select concat('insert into tablename(id,high,link,is_enabled,platformid) values(\"',id,'\",\"',high,'\",\"',link,'\",\"',is_enabled,'\",\"',platformid,'\");') from tablename" dbname>./filename.sql

使用concat()函数拼接数据语句。
导入语句一样,都是执行SQL。如下(远程导入需要加入参数"-h+ip";本地则去掉该参数,或者将ip换为本地ip即可):

mysql -h127.0.0.1 -uroot -ppassword tableName <bak_data.sql

弊端:使用指定列的方式导出数据,对于某些字段值为null的,而不是’’,那么导出的记录就是一条NULL。

猜你喜欢

转载自blog.csdn.net/LGHunter/article/details/83501856