安装配置(必须在root下用户安装)
1、安装unixODBC
# tar vxzf unixODBC-2.2.8.tar.gz
# cd unixODBC-2.2.8
# ./configure --prefix=/usr/local/unixODBC --enable-gui=no
# make
# make install
2、安装freetds
# tar vxzf freetds-0.62.4.tar.gz
# cd freetds-0.62.4
# ./configure --prefix=/usr/local/freetds --with-unixodbc=/usr/local/unixODBC --with-tdsver=8.0
# make
# make install
3、配置freetds
# vi /usr/local/freetds/etc/freetds.conf
[global]
# TDS protocol version
tds version = 8.0
client charset = UTF-8
[SQLServer2000]
host = 192.168.1.110
port = 1433
tds version = 8.0
client charset = UTF-8
[root@pc02 bin]# ./freebcp
usage: freebcp [[database_name.]owner.]table_name {in | out} datafile
[-m maxerrors] [-f formatfile] [-e errfile]
[-F firstrow] [-L lastrow] [-b batchsize]
[-n] [-c] [-t field_terminator] [-r row_terminator]
[-U username] [-P password] [-I interfaces_file] [-S server]
[-v] [-d] [-h "hint [,...]" [-O "set connection_option on|off, ...]"
[-A packet size] [-T text or image size] [-E]
example: freebcp testdb.dbo.inserttest in inserttest.txt -S mssql -U guest -P password -c
[root@pc02 bin]#
1,按表导出
/usr/local/freetds/bin/freebcp tb1 out tb1.txt -S ssgg -U ssgg -P ssgg -c
2,按查询导出
/usr/local/freetds/bin/freebcp "select * from xxx.[xxx].tb1" queryout /home/oracle/tb1.txt -c -t "|" -S 192.100.251.218 -U sa -P 11
如果不设置字符集会出现:
Some character(s) could not be converted into client's character set. Unconverted bytes were changed to question marks ('?')