MySQL Connection Methods
Http://icbm.iteye.com/blog/1840673
In addition to the most common TCP connection mode, MySQL also provides SOCKET (default LINUX connection mode), PIPE, and shared memory connection methods.
The following table lists the server and client startup options and default connection values of each connection method:
TCPLinux ):
|
Target |
Startup options |
Default Value |
|
SERVER |
-- Port = PORT |
3306 |
|
CLIENT |
-- Protocol = TCP -- port = PORT |
3306 |
SOCKETLinux ):
|
Target |
Startup options |
Default Value |
|
SERVER |
-- Enable-named-pipe -- socket = SOCKET |
/Tmp/mysql. sock |
|
CLIENT |
-- Protocol = SOCKET -- socket = SOCKET |
/Tmp/mysql. sock |
PIPEWindows ):
|
Target |
Startup options |
Default Value |
|
SERVER |
-- Enable-named-pipe -- socket = SOCKET |
MYSQL |
|
CLIENT |
-- Protocol = PIPE -- socket = SOCKET |
MYSQL |
SHARED MEMORYWindows ):
|
Target |
Startup options |
Default Value |
|
SERVER |
-- Shared-memory-base-name = MEMORY |
MySQL |
|
CLIENT |
-- Protocol = MEMORY -- shared-memory-base-name = MEMORY |
MySQL |
The following describes how to use socket in Linux, so that mysql service port 3306 is not needed.
Junixsocket
Https://code.google.com/p/junixsocket
Junixsocket-1.3-bin.tar
Junixsocket-1.3.jar
Junixsocket-mysql-1.3.jar
Tomcat configuration
Because the connection pool of dbcp and c3p0 does not support this, use jdbc connection pool configuration. For more information, see
Https://tomcat.apache.org/tomcat-7.0-doc/jdbc-pool.html
ApplicationContext. xml
<Context: property-placeholder
Ignore-unresolvable = "true" location = "classpath:/application. properties"/>
<Bean id = "dataSource" class = "org. apache. tomcat. jdbc. pool. DataSource"
Destroy-method = "close">
<! -- Connection Info -->
<Property name = "driverClassName" value = "$ {jdbc. driver}"/>
<Property name = "url" value = "$ {jdbc. url}"/>
<Property name = "username" value = "$ {jdbc. username}"/>
<Property name = "password" value = "$ {jdbc. password}"/>
<Property name = "defaultCatalog" value = "$ {jdbc. defaultCatalog}"/>
<Property name = "dbProperties">
<Props>
<Prop key = "socketFactory"> org.newsclub.net. mysql. AFUNIXDatabaseSocketFactory </prop>
<Prop key = "junixsocket. file">/tmp/mysql. sock </prop>
</Props>
</Property>
<Bean id = "sessionFactory"
Class = "org. springframework. orm. hibernate4.LocalSessionFactoryBean"
P: dataSource-ref = "dataSource">
<! -- Mapping configuration can be used in the automatic scanning package provided by spring -->
<Property name = "packagesToScan" value = "cn. csbit. **. model"/>
<Property name = "hibernateProperties">
<Props>
<Prop key = "javax. persistence. validation. mode"> none </prop>
<Prop key = "hibernate. dialect"> org. hibernate. dialect. MySQL5Dialect </prop>
<Prop key = "hibernate. show_ SQL"> false </prop>
<Prop key = "hibernate. format_ SQL"> false </prop>
</Props>
</Property>
</Bean>
Difference from dbcp
Application. properties
# Mysql database setting
Jdbc. driver = com. mysql. jdbc. Driver
Jdbc. url = jdbc: mysql ://? UseUnicode = true & characterEncoding = UTF-8 & useLocalSessionState = true & autoReconnect = true
Jdbc. username = ***
Jdbc. password = ***
Jdbc. defaultCatalog = ***
Jar package and Runtime Library
Tomcat-jdbc.jar
Tomcat-juli.jar
Tomcat-juli-adapters.jar
Copy lib-native to/opt/newsclub in junixsocket-1.3-bin.tar