SELECT [INTO OUTFILE 'file_name' [CHARACTER SET charset_name] export_options | INTO DUMPFILE 'file_name' | INTO var_name [, var_name]]3 测试表结构及数据
mysql> create database loaddata; mysql> use loaddata; mysql> create table loadtest (c1 int(10), c2 varchar(20), c3 varchar(20), c4 varchar(20));3.2 插入测试数据
mysql> insert into loadtest values (100, 'column2', 'column3', 'column4'); mysql> insert into loadtest values (200, 'line2', 'line3', 'line4');4 语法解释及实例验证
[root@localhost /]# mysql -h192.168.1.94 -ujesse -pjesse -P3306 mysql> select * into outfile '/tmp/outfile.txt' from loadtest; ERROR 1086 (HY000): File '/tmp/outfile.txt' already exists
[root@localhost /]# mysql -h192.168.1.94 -ujesse -pjesse -P3306 -e"select * into outfile '/tmp/outfile.txt' from loaddata.loadtest;" Warning: Using a password on the command line interface can be insecure. ERROR 1086 (HY000) at line 1: File '/tmp/outfile.txt' already exists我们只能用类似mysql -e "SELECT ..." > file_name的命令将文件输出到客户机上。
[root@localhost /]# mysql -h192.168.1.94 -ujesse -pjesse -P3306 -e"select * from loaddata.loadtest;" > /tmp/loadtest.txt指定格式输出:
mysql> select * into outfile '/tmp/outfile.txt' from loadtest; mysql> select * into outfile '/tmp/outfile.txt' FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' ESCAPED BY '#' LINES TERMINATED BY '\n' from loadtest;SELECT***INTO var_name [, var_name]:
mysql> select * into @a, @b, @c, @d from loadtest limit 1; mysql> select c1, c2, c3, c4 into @a, @b, @c, @d from loadtest limit 1;
mysql> select c1, c2, c3, c4 into @a, @b, @c from loadtest limit 1; ERROR 1222 (21000): The used SELECT statements have a different number of columns mysql> select c1, c2, c3 into @a, @b, @c, @d from loadtest limit 1; ERROR 1222 (21000): The used SELECT statements have a different number of columns
mysql> select c1, c2, c3, c4 into @a, @b, @c, @d from loadtest; ERROR 1172 (42000): Result consisted of more than one row
mysql> select * into dumpfile '/tmp/dumpfile.txt' from loadtest;5 一些错误
[root@localhost /]# /home/ACTIONTECH-HA/mysql-install/bin/mysql -h192.168.1.94 -ujesse -pjesse -P3306 Warning: Using a password on the command line interface can be insecure. ERROR 2003 (HY000): Can't connect to MySQL server on '192.168.1.94' (113)
解决办法:关闭服务器端防火墙或开放mysql端口。
****************************************************************************************
原文地址:http://blog.csdn.net/jesseyoung/article/details/41346861
博客主页:http://blog.csdn.net/jesseyoung
****************************************************************************************