不知怎样说明白,以下我演示一下吧:
C:\>bcp "select ltrim(rtrim(isnull(replace([Color],'\','\\'),'\N'))) [Color] from db_tank..cyf" queryout z:\\t_u_item_20111025 -T -a 65535 -w开始复制...已复制 15 行。
网络数据包大小(字节): 32576
总时钟时间(毫秒) : 1 平均值: (每秒 15000.00 行。)
#在linux下查看:
[root@localhost MsBCPData]# cat t_u_item_20111025 -v
M-^?M-~^@^@^M^@
^@^@^@^M^@
^@^@^@^M^@
^@^@^@^M^@
^@^@^@^M^@
^@^@^@^M^@
^@^@^@^M^@
^@^@^@^M^@
^@^@^@^M^@
^@d^@s^@a^@f^@d^@s^@a^@f^@^M^@
^@1^@2^@3^@2^@3^@4^@^M^@
^@^@^@^M^@
^@^@^@^M^@
^@^@^@^M^@
^@^@^@^M^@[root@localhost MsBCPData]# iconv -f unicode -t utf8 t_u_item_20111025 > t_u_item_20111025_utf8
[root@localhost MsBCPData]# cat t_u_item_20111025_utf8 -v
^@^M
^@^M
^@^M
^@^M
^@^M
^@^M
^@^M
^@^M
^@^M
dsafdsaf^M
123234^M
^@^M
^@^M
^@^M
^@^M#我们把这文件导入mysql去
[root@localhost MsBCPData]# mysql -uroot -p7roaddba -P3306 --default-character-set=utf8 db_tank_2 -vvv -e "load data local infile '/root/MsBCPData/t_u_item_20111025_utf8' into table cyf (\`Color\`) ; show warnings;" #在mysql里查看:
mysql> select * from cyf;
+----------+
| Color |
+----------+
| |
| |
| |
| |
| |
| |
| |
| |
| |
| dsafdsaf |
| 123234 |
| |
| |
| |
| |
+----------+
15 rows in set (0.00 sec)#上面看到好像是正常的,我们把它导出来看看:
[root@localhost MsBCPData]# mysql -uroot -p7roaddba -P3306 --default-character-set=utf8 db_tank_2 -e "select * from cyf;" > cyf
[root@localhost MsBCPData]# cat cyf
Color
\0
\0
\0
\0
\0
\0
\0
\0
\0
dsafdsaf
123234
\0
\0
\0
\0#问题出现了,每个空记录都会有一个“\0”!
#为了验证这不是mysql把空值(''值)默认为“\0”我们再做几个insert:mysql> insert into cyf values('');
Query OK, 1 row affected (0.00 sec)mysql> insert into cyf values('');
Query OK, 1 row affected (0.01 sec)mysql> insert into cyf values('');
Query OK, 1 row affected (0.00 sec)mysql> insert into cyf values('');
Query OK, 1 row affected (0.00 sec)mysql> insert into cyf values('cyf');
Query OK, 1 row affected (0.00 sec)mysql> select * from cyf;
+----------+
| Color |
+----------+
| |
| |
| |
| |
| |
| |
| |
| |
| |
| dsafdsaf |
| 123234 |
| |
| |
| |
| |
| |
| |
| |
| |
| cyf |
+----------+
20 rows in set (0.00 sec)
#我们看到最后一条记录的前几条也是没值的,OK,我们导出来看看:
[root@localhost MsBCPData]# mysql -uroot -p7roaddba -P3306 --default-character-set=utf8 db_tank_2 -e "select * from cyf;" > cyf
[root@localhost MsBCPData]# cat cyf
Color
\0
\0
\0
\0
\0
\0
\0
\0
\0
dsafdsaf
123234
\0
\0
\0
\0
cyf
[root@localhost MsBCPData]#
#发现刚才的insert进去的空值真的是空值(''值)现在的问题是,怎样才能把sql server原有的空值(''值)转到mysql时也是空值(''值)?
C:\>bcp "select ltrim(rtrim(isnull(replace([Color],'\','\\'),'\N'))) [Color] from db_tank..cyf" queryout z:\\t_u_item_20111025 -T -a 65535 -w开始复制...已复制 15 行。
网络数据包大小(字节): 32576
总时钟时间(毫秒) : 1 平均值: (每秒 15000.00 行。)
#在linux下查看:
[root@localhost MsBCPData]# cat t_u_item_20111025 -v
M-^?M-~^@^@^M^@
^@^@^@^M^@
^@^@^@^M^@
^@^@^@^M^@
^@^@^@^M^@
^@^@^@^M^@
^@^@^@^M^@
^@^@^@^M^@
^@^@^@^M^@
^@d^@s^@a^@f^@d^@s^@a^@f^@^M^@
^@1^@2^@3^@2^@3^@4^@^M^@
^@^@^@^M^@
^@^@^@^M^@
^@^@^@^M^@
^@^@^@^M^@[root@localhost MsBCPData]# iconv -f unicode -t utf8 t_u_item_20111025 > t_u_item_20111025_utf8
[root@localhost MsBCPData]# cat t_u_item_20111025_utf8 -v
^@^M
^@^M
^@^M
^@^M
^@^M
^@^M
^@^M
^@^M
^@^M
dsafdsaf^M
123234^M
^@^M
^@^M
^@^M
^@^M#我们把这文件导入mysql去
[root@localhost MsBCPData]# mysql -uroot -p7roaddba -P3306 --default-character-set=utf8 db_tank_2 -vvv -e "load data local infile '/root/MsBCPData/t_u_item_20111025_utf8' into table cyf (\`Color\`) ; show warnings;" #在mysql里查看:
mysql> select * from cyf;
+----------+
| Color |
+----------+
| |
| |
| |
| |
| |
| |
| |
| |
| |
| dsafdsaf |
| 123234 |
| |
| |
| |
| |
+----------+
15 rows in set (0.00 sec)#上面看到好像是正常的,我们把它导出来看看:
[root@localhost MsBCPData]# mysql -uroot -p7roaddba -P3306 --default-character-set=utf8 db_tank_2 -e "select * from cyf;" > cyf
[root@localhost MsBCPData]# cat cyf
Color
\0
\0
\0
\0
\0
\0
\0
\0
\0
dsafdsaf
123234
\0
\0
\0
\0#问题出现了,每个空记录都会有一个“\0”!
#为了验证这不是mysql把空值(''值)默认为“\0”我们再做几个insert:mysql> insert into cyf values('');
Query OK, 1 row affected (0.00 sec)mysql> insert into cyf values('');
Query OK, 1 row affected (0.01 sec)mysql> insert into cyf values('');
Query OK, 1 row affected (0.00 sec)mysql> insert into cyf values('');
Query OK, 1 row affected (0.00 sec)mysql> insert into cyf values('cyf');
Query OK, 1 row affected (0.00 sec)mysql> select * from cyf;
+----------+
| Color |
+----------+
| |
| |
| |
| |
| |
| |
| |
| |
| |
| dsafdsaf |
| 123234 |
| |
| |
| |
| |
| |
| |
| |
| |
| cyf |
+----------+
20 rows in set (0.00 sec)
#我们看到最后一条记录的前几条也是没值的,OK,我们导出来看看:
[root@localhost MsBCPData]# mysql -uroot -p7roaddba -P3306 --default-character-set=utf8 db_tank_2 -e "select * from cyf;" > cyf
[root@localhost MsBCPData]# cat cyf
Color
\0
\0
\0
\0
\0
\0
\0
\0
\0
dsafdsaf
123234
\0
\0
\0
\0
cyf
[root@localhost MsBCPData]#
#发现刚才的insert进去的空值真的是空值(''值)现在的问题是,怎样才能把sql server原有的空值(''值)转到mysql时也是空值(''值)?
解决方案 »
- 问一个mysql 维护一张表的sql语句如何写
- phpmyadmin中如何导出一个数据表的部分内容?
- 【Mysql 行变列问题 】 如何输出学生成绩到一行记录中去
- mysql中属性为varchar类型的列的值求和?(在线等!)
- 数据组合问题
- MySQL中将数据库创建到指定目录的语句
- 高分请教远程连接MYSQL的问题(急):
- 各种数据库最多支持多少个表?
- 我安装了mysql后,为和在启动服务时失败,提示系统发生1067错误,该怎么解决
- 用c API 编程,对一个数据库操作时,用在mysql_real_query()中使用“USE”吗?-- 阿菜
- Group by 后如何保持原先的排序?
- 关于bcp出操作字符的问题,请各位帮帮忙
无论从哪个源数据库导致,需要把结果整理成为MYSQL可以使用的格式,包括其中的数据。