Mysql导出导入数据的方法介绍
这篇文章主要介绍“Mysql导出导入数据的方法介绍”,在日常操作中,相信很多人在Mysql导出导入数据的方法介绍问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”Mysql导出导入数据的方法介绍”的疑惑有所帮助!接下来,请跟着小编一起来学习吧!
导出数据
**直接在系统执行命令:
导出为cvs格式:
[root@slave ~]# mysql -u root -p密码 -e "select * from mydb.name into outfile '/tmp/12.cvs' character set utf8" --character set utf8 指定相应编码规则,不然可能乱码
导出为txt格式:
[root@slave ~]# mysql -u root -p密码 -e "select * from mydb.name into outfile '/tmp/12.txt' character set utf8 lines terminated by '\r\n' " --导出为txt文件时,不加lines terminated by '\r\n' (结尾符)在windows下会像一团麻一样.....
在mysql内:
导出为cvs格式:
mysql>selec t * from mydb.name into outfile '/tmp/12.cvs' character set utf8; - --character set utf8 指定相应编码规则,不然可能乱码
导出为txt格式:
mysql> select * from mydb.name into outfile '/tmp/12.txt' character set utf8 lines terminated by '\r\n'; --导出为txt文件时,不加 lines terminated by '\r\n' (结尾符)在windows下会像一团麻一样.....
导出为cvs格式后,用WPS打开,相当的完美!
导入数据
mysql内导入:
mysql>load data infile '/tmp/12.txt' into table name character set uft8; --character set utf8 指定相应编码规则,不然可能乱码
直接在系统执行命令:
[root@slave ~]# mysql -u root -p密码 -e load data infile '/tmp/12.txt' into table name character set uft8; --character set utf8 指定相应编码规则,不然可能乱码
遇到一个问题:emun类型的字段,导不入数据 ???
解决方法:
导入,导出时添加两个参数: fields terminated by 和 optionally enclosed by
mysql> select * from name into outfile '/tmp/11.txt' character set utf8 fields terminated by '\、' optionally enclosed by '\"' ;
mysql> load data infile '/tmp/11.txt' into table nn character set utf8 fields terminated by '\、' optionally enclosed by '\"' ;
到此,关于“Mysql导出导入数据的方法介绍”的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注网站,小编会继续努力为大家带来更多实用的文章!