This section is excerpted from MySQL cookbook 3th. Specific content do not translate, haha, lazy
The default Tomcat default session storage mechanism uses temporary files. To save
Sessions using JDBC with MySQL instead, follow this procedure:
None of these steps involve modifying the sample session script in any, which
Reflects how Tomcat implements session, support above, the application level.
The following table satisfies those specifications; Create it now before proceeding:
Place the JDBC driver where Tomcat can find it.
CREATE TABLE tomcat_session( id VARCHAR(32) NOT NULL, app VARCHAR(255), data LONGBLOB, valid_session CHAR(1) NOT NULL, max_inactive INT NOT NULL, update_time BIGINT NOT NULL, PRIMARY KEY (id), INDEX (app));
Because Tomcat itself manages sessions, it must bes able to access the JDBC driver
Used to store sessions in a database. It ' s common to install drivers in the Lib directory
Of the Tomcat tree so, they ' re available both to Tomcat and to applications. (Note: If you already have references to MySQL JDBC driver in the war, you do not need to specifically Drive jar package Copy to Tomcat's lib directory)
To-tell Tomcat-to-use the Tomcat_session table, modify the MCB application context
File. Change location into the Webapps/mcb/meta-inf under the Tomcat we
Bapps directory, copy Context.xml.jdbc to Context.xml, and restart Tomcat.
If you look in Context.xml, you'll find a
<Context> element containing a element, specifies the use of the
<Manager> JDBC for MYSQ l-based Session Storage:
<managerclassname= "Org.apache.catalina.session.PersistentManager" saveonrestart= "true "Maxidlebackup=" "maxidleswap=" "minidleswap=" "><store classname=" org.apache.catalina.session . Jdbcstore "Drivername=" Com.mysql.jdbc.Driver "connectionurl=" Jdbc:mysql://localhost/cookbook?user=cbuser& ;p assword=cbpass&usessl=false "sessiontable=" tomcat_session "sessionidcol=" id "sessionAppCol=" app "ses Siondatacol= "Data" sessionvalidcol= "Valid_session" sessionmaxinactivecol= "max_inactive" sessionLastAccessedCol= "u Pdate_time "/></MANAGER>
<Manager> element attributes specify general session-related options. Within the
<Manager>Element body, the
<Store> element provides attributes pertaining to the
JDBC driver. The following discussion focuses on the attributes shown in the example,
But there is others you can use. For more information, see the Tomcat session-
<Manager> attributes shown in the example has the following meanings:
<manager> element, the
<store> element indicates how to connect to the
Database server, the names of the database and table for storing session records, and the
names of the columns in T He table:
Classname:the name of a class that implements the Org.apache.catalina.Store interface.
For jdbc-based storage managers, the value is Org.apache.catalina.session.JDBCStore.
Drivername:the class name for the JDBC driver. For the connector/j driver, the value is com.mysql.jdbc.Driver.
sessiontable the table in which to Store session Records. For we example, this is the Tomcat_session table described earlier.
(The database that contains the table appears in the Connectionurl value.) The remainingPossible problems with MySQL large version fingertip reference class name package path change
This section is excerpted from the following: Com.mysql.jdbc.Driver and Com.mysql.cj.jdbc.Driver differences servertimezone settings
com.mysql.jdbc.Driveris in Mysql-connector-java 5,
com.mysql.cj.jdbc.DriverIt's in Mysql-connector-java 6.
1. JDBC Connection MYSQL5
2, JDBC Connection Mysql6
com.mysql.cj.jdbc.Driver , you need to specify the time zone Servertimezone:
When setting the time zone, if set SERVERTIMEZONE=UTC, will be 8 hours earlier than Chinese time, if in China, can choose Asia/shanghai or Asia/hongkong, for example:
Java connection to MySQL database, prompting establishing SSL connection without warning
This content is excerpted from: Java connection MySQL database, prompt establishing SSL connection without warning
Java when connecting to MySQL database, output the following warning message * *
Tue Jul 11 18:04:07 CST 2017 WARN: Establishing SSL connection without server‘s identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn‘t set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to ‘false‘. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
mysql-connector-javadependent version is reduced, as follows
<dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>5.1.38</version></dependency>
In general, the span between the minor versions does not affect use, but the usage difference between the large versions will be large, so you have to confirm the MySQL version and find the appropriate driver.
Tomcat by default is to put this part of the session related information in the file, through the above configuration can put the corresponding information into MySQL, if large concurrent large data volume, the performance should be better. In fact, if you have more than one tomcat that allows these tomcat to connect to the database, you can implement a distributed session sharing. Of course, in the case of large concurrency big data, it is often better to put the session information into the Redis, performance should be better.
Welcome reprint, but please indicate this article link, thank you.
Tomcat-generated session persisted to MySQL