EXEC master.dbo.sp_addlinkedsrvlogin @rmtsrvname = N'MYSQLLINK',@useself = N'False',@locallogin = N'sa',@rmtuser = N'root',@rmtpassword = N'wison'
之后就可以使用
SELECT * FROM OPENQUERY (MYSQLLINK, 'SELECT * FROM wisontest.sssss')
来查询mysql数据库中的数据了.
oracle:系统redhat 5.5 数据库:11.2.0.1mysql:系统centos6.3 数据库:5.6.21
1.先装 mysql-connector-odbc和unixODBC
[root@rac1 ~]# rpm -qa | grep mysql
mysql-5.0.77-4.el5_4.2
mysql-5.0.77-4.el5_4.2
mysql-connector-odbc-5.1.13-1.rhel5
[root@rac1 ~]# rpm -qa | grep ODBC
unixODBC-devel-2.2.11-7.1
unixODBC-2.2.11-7.1
unixODBC-devel-2.2.11-7.1
unixODBC-2.2.11-7.1
2.配置 /etc/odbc.ini
[myodbc3]
Driver = /usr/lib64/libmyodbc5.so
Description = MySQL ODBC 5.1 Driver DSN
SERVER = 192.1.1.200
PORT = 3306
USER = bi
Password = 123456
Database = chanpin
OPTION = 3
SOCKET =
charset = utf8
3.配置/etc/odbcinst.ini
[MySQL]
Description = ODBC for MySQL
Driver = /usr/lib64/libmyodbc5.so
Setup = /usr/lib64/libodbcmyS.so
FileUsage = 1
4.测试连接
[root@rac1 ~]# isql myodbc3 -v
+---------------------------------------+
| Connected!|
| |
| sql-statement |
| help [tablename] |
| quit |
| |
+---------------------------------------+
SQL>
5.配置oracle环境变量
export ORACLE_BASE=/u01/app/oracle
export GRID_HOME=/u01/grid
export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/db_1
export ORACLE_SID=rac1
export BASE_PATH=/usr/sbin:$PATH
export PATH=$ORACLE_HOME/bin:$BASE_PATH:/usr/bin
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib:/usr/local/lib:$ORACLE_HOME/hs/lib:/usr/lib64
export CLASSPATH=$ORACLE_HOME/JRE:$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib
ODBCINI=/etc/odbc.iniexport ODBCINI
ODBCSYSINI=/etcexport ODBCSYSINI
ODBCINSTINI=/etc/odbc.ini
export ODBCINSTINI
6.配置监听
listener.ora:
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.1.1.100)(PORT = 1522))
)
)
SID_LIST_LISTENER=
(SID_LIST=
(SID_DESC=
(PROGRAM = dg4odbc)
(SID_NAME= myodbc3)
(ORACLE_HOME= /u01/app/oracle/product/11.2.0/db_1)
(ENVS=LD_LIBRARY_PATH=/u01/app/oracle/product/11.2.0/db_1/lib:/lib:/usr/lib:/usr/local/lib:/u01/app/oracle/product/11.2.0/db_1/hs/lib:/usr/lib64)
)
)
tnsname.ora:
myodbc3=
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.1.1.100)(PORT = 1522))
(CONNECT_DATA =
(SID = myodbc3))
(HS = OK)
)
7.配置odbc监听
路径:$ORACLE_HOME/hs/admin
注意:名字要跟odbc配置的名字一样 我这里是myodbc3
[oracle@rac1 admin]$ cat initmyodbc3.ora
HS_FDS_CONNECT_INFO = myodbc3
HS_FDS_TRACE_LEVEL = ON
HS_FDS_TRACE_FILE_NAME = odbc_test.log
HS_FDS_TRACE_LEVEL = 4
HS_FDS_SHAREABLE_NAME = /usr/lib64/libodbc.so
HS_FDS_SUPPORT_STATISCTICS = FALSE
HS_LANGUAGE = AMERICAN_AMERICA.WE8ISO8859P1
HS_FDS_SQLLEN_INTERPRETATION=32
set ODBCINI = /etc/odbc.ini
8.测试下监听
[oracle@rac1 admin]$ tnsping myodbc3
TNS Ping Utility for Linux: Version 11.2.0.1.0 - Production on 25-NOV-2014 03:02:16
Copyright (c) 1997, 2009, Oracle. All rights reserved.
Used parameter files:
Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.1.1.100)(PORT = 1522)) (CONNECT_DATA = (SID = myodbc3)) (HS = OK))
OK (0 msec)
9.创建dblink
SQL>create public database link myodbc connect to "bi" identified by "123456" using'myodbc3'
SQL>select count(*) from "t_user"@myodbc
COUNT(*)
----------
53980
1. 首先是jdbc.properties属性文件的编写,便于数据库移植:datasource.driverClassName=oracle.jdbc.driver.OracleDriver
datasource.url=jdbc:oracle:thin:@10.6.1.11:1521:student
datasource.username=zs
datasource.password=zs
datasource.defaultAutoCommit=true
hibernate.dialect=org.hibernate.dialect.Oracle9Dialect
#当连接池中的连接耗尽的时候c3p0一次同时获取的连接数。Default: 3
c3p0.acquireIncrement=5
#初始化时获取三个连接,取值应在minPoolSize与maxPoolSize之间。Default: 3
c3p0.initialPoolSize=10
#每60秒检查所有连接池中的空闲连接。Default: 0
c3p0.idleConnectionTestPeriod=600
#-连接池中保留的最小连接数。
c3p0.minPoolSize=5
#连接池中保留的最大连接数。Default: 15
c3p0.maxPoolSize=50
#JDBC的标准参数,用以控制数据源内加载的PreparedStatements数量。但由于预缓存的statements
#属于单个connection而不是整个连接池。所以设置这个参数需要考虑到多方面的因素。
#如果maxStatements与maxStatementsPerConnection均为0,则缓存被关闭。Default: 0
c3p0.maxStatements=100
#c3p0是异步 *** 作的,缓慢的JDBC *** 作通过帮助进程完成。扩展这些 *** 作可以有效的提升性能
#通过多线程实现多个 *** 作同时被执行。Default: 3
c3p0.numHelperThreads=10
#最大空闲时间,60秒内未使用则连接被丢弃。若为0则永不丢弃。Default: 0
c3p0.maxIdleTime=600
#hibernate.dialect=org.hibernate.dialect.SQLServerDialect
hibernate.jdbc.batch_size=25
hibernate.jdbc.fetch_size=50
hibernate.show_sql=true
hibernate.connection.release_mode=after_transaction
2. 其次是spring配置文件的数据源配置:
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location">
<value>/WEB-INF/classes/conf/jdbc/jdbc.properties</value>
</property>
</bean>
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close" dependency-check="none">
<property name="driverClass">
<value>${datasource.driverClassName}</value>
</property>
<property name="jdbcUrl">
<value>${datasource.url}</value>
</property>
<property name="user">
<value>${datasource.username}</value>
</property>
<property name="password">
<value>${datasource.password}</value>
</property>
<!-- 当连接池中连接耗尽的时候c3p0一次同时获取的连接数 -->
<property name="acquireIncrement">
<value>${c3p0.acquireIncrement}</value>
</property>
<!--初始化时获取三个连接,取值应在minPoolSize与maxPoolSize之间。Default: 3 -->
<property name="initialPoolSize">
<value>${c3p0.initialPoolSize}</value>
</property>
<!-- 最小连接数 -->
<property name="minPoolSize">
<value>${c3p0.minPoolSize}</value>
</property>
<!-- 最大连接数 -->
<property name="maxPoolSize">
<value>${c3p0.minPoolSize}</value>
</property>
<!--最大空闲时间,60秒内未使用则连接被丢弃。若为0则永不丢弃。Default: 0 -->
<property name="maxIdleTime">
<value>${c3p0.maxPoolSize}</value>
</property>
<!--每60秒检查所有连接池中的空闲连接。Default: 0 -->
<property name="idleConnectionTestPeriod">
<value>${c3p0.idleConnectionTestPeriod}</value>
</property>
<!--JDBC的标准参数,用以控制数据源内加载的PreparedStatements数量。但由于预缓存的statements属于单个connection而不是整个连接池。
所以设置这个参数需要考虑到多方面的因素。如果maxStatements与maxStatementsPerConnection均为0,则缓存被关闭。Default: 0-->
<property name="maxStatements">
<value>${c3p0.maxStatements}</value>
</property>
<!--c3p0是异步 *** 作的,缓慢的JDBC *** 作通过帮助进程完成。扩展这些 *** 作可以有效的提升性能通过多线程实现多个 *** 作同时被执行。Default: 3-->
<property name="numHelperThreads">
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)