环境:
MYSQL服务器:mysql 5.1.55 64位
ORACLE服务器 : oracle 10g 64位
安装
1.安装数据源驱动(ODBC)64位
Connector/ODBC 5.3.14 :https://dev.mysql.com/downloads/connector/odbc/5.3.html
2.打开 ODBC 数据源:
打开后选择系统DSN:
选择:ANSI Driver
配置完成后点击ok就行
3.在cmd 验证一下,输入dg4odbc
配置oracle
1.透明网关配置
找到你的oracle的安装目录的initdg4odbc.ora文件,然后复制一份,命名规则是:init+sid.ora,所以就是initmysqlodbc.ora;
initmysqlodbc.ora(斜体加粗部分)
HS_FDS_CONNECT_INFO = mysqlodbc
HS_FDS_TRACE_LEVEL = off
2.listener.ora配置(斜体加粗部分)
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(SID_NAME = orcl)
(GLOBAL_DBNAME = orcl)
(ORACLE_HOME = F:\product\11.2.0\dbhome_1)
(ENVS = "EXTPROC_DLLS=ONLY:F:\product\11.2.0\dbhome_1\bin\oraclr11.dll")
)
(SID_DESC =
(GLOBAL_DBNAME = orcl)
(ORACLE_HOME = F:\product\11.2.0\dbhome_1)
(SID_NAME = orcl)
)
(SID_DESC =
(SID_NAME = mysqlodbc)
(ORACLE_HOME = F:\product\11.2.0\dbhome_1)
(PROGRAM = dg4odbc)
)
)
3.sqlnet.ora(斜体加粗部分)
SQLNET.AUTHENTICATION_SERVICES= (NONE)
NAMES.DIRECTORY_PATH= (TNSNAMES, EZCONNECT)
4.tnsnames.ora(斜体加粗部分)
mysqlodbc =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = mysqlodbc)
)
(HS = OK)
)
5.数据库测试
在数据执行以下语句
create public database link mysqlodbc connect to "admin" identified by "admin" using 'mysqlodbc';
admin/admin为mysql数据库账号密码
执行查操作
SELECT * FROM tb_hisdata@mysqlodbc
SELECT * FROM tb_hisdata@mysqlodbc where "sfvalue"!='0';
注意!注意where子句列名加",不加我电脑上报列名不存在!
错误1
Connection Failed
[MySQL][ODBC 5.3(w) Driver]Access denied for user 'root'@'192.168.18.155' (using password: YES):
新建个用户 admin
附上所有权限
错误2
Connection Failed
[MySQL][ODBC 5.3(w) Driver]Unknown character set: 'utf8mb4':
编码错误,选择ANSI Driver