mysql 连接超时异常
mysql 连接超时错误 自己的小网站在测试机器上长时间不访问后(默认8小时过期),再次访问发现有如下错误: Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully received fro m the server was 63,020,509 m
mysql 连接超时错误自己的小网站在测试机器上长时间不访问后(默认8小时过期),再次访问发现有如下错误:
Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully received fro
m the server was 63,020,509 milliseconds ago. ?The last packet sent successfully to the server was 63,020,509
?milliseconds ago. is longer than the server configured value of 'wait_timeout'. You should consider either e
xpiring and/or testing connection validity before use in your application, increasing the server configured v
alues for client timeouts, or using the Connector/J connection property 'autoReconnect=true' to avoid this pr
oblem.
? ? ? ? at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
? ? ? ? at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
? ? ? ? at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:4
5)
? ? ? ? at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
? ? ? ? at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
? ? ? ? at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1116)
? ? ? ? at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:3851)
? ? ? ? at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2471)
? ? ? ? at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2651)
? ? ? ? at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2683)
? ? ? ? at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2144)
? ? ? ? at com.mysql.jdbc.PreparedStatement.execute(PreparedStatement.java:1379)
? ? ? ? at org.apache.tomcat.dbcp.dbcp.DelegatingPreparedStatement.execute(DelegatingPreparedStatement.java:172)
? ? ? ? at org.apache.tomcat.dbcp.dbcp.DelegatingPreparedStatement.execute(DelegatingPreparedStatement.java:172)
?
Fix:?If only the connection pool could check if the the connection it is about to return is live or not, the porblem is fixed. This can be done in apache-common-dbcp (I know this one coz I used it, please look into documentation of the connection-pool you are using). Here’s how you do it: You add the following properties to dbcp configuration.
- validationQuery=”SELECT 1″
- testOnBorrow=”true”
And that does the trick.
?
暂时我对我的mysql连接加上: 试试效果
validationQuery
=
"SELECT 1"
?
testOnBorrow
=
"true"
?
目前我不想添加: ?autoReconnect=true? 因为我对此的理解不深,mysql文档这样写的:
?
This parameter is?false
?by default. This forces disconnected API nodes (including MySQL Servers acting as SQL nodes) to use a new connection to the cluster rather than attempting to re-use an existing one, as re-use of connections can cause problems when using dynamically-allocated node IDs. (Bug #45921)
如果有问题再添加 autoReconnect选项
like this:
?
? ? ? ? ? ? ? ?initialSize="10" maxActive="100" maxIdle="30" maxWait="10000"
? ? ? ? ? ? ? ?username="***" password="***" driverClassName="com.mysql.jdbc.Driver"
? ? ? ? ? ? ? ?url="jdbc:mysql://localhost:3306/saasNetTest"
? ? ? ? ? ? ? ?validationQuery="SELECT 1"
? ? ? ? ? ? ? ?testOnBorrow="true"
?
? ? />
?
参考文档:http://stackoverflow.com/questions/9674165/mysql-jdbc-timeout-even-with-autoreconnect-true
http://amitcodes.com/2008/07/26/16/
http://www.tomcatexpert.com/blog/2010/04/01/configuring-jdbc-pool-high-concurrency
?

ホットAIツール

Undresser.AI Undress
リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover
写真から衣服を削除するオンライン AI ツール。

Undress AI Tool
脱衣画像を無料で

Clothoff.io
AI衣類リムーバー

AI Hentai Generator
AIヘンタイを無料で生成します。

人気の記事

ホットツール

メモ帳++7.3.1
使いやすく無料のコードエディター

SublimeText3 中国語版
中国語版、とても使いやすい

ゼンドスタジオ 13.0.1
強力な PHP 統合開発環境

ドリームウィーバー CS6
ビジュアル Web 開発ツール

SublimeText3 Mac版
神レベルのコード編集ソフト(SublimeText3)

ホットトピック









MySQLデータベースでは、ユーザーとデータベースの関係は、アクセス許可と表によって定義されます。ユーザーには、データベースにアクセスするためのユーザー名とパスワードがあります。許可は助成金コマンドを通じて付与され、テーブルはCreate Tableコマンドによって作成されます。ユーザーとデータベースの関係を確立するには、データベースを作成し、ユーザーを作成してから許可を付与する必要があります。

MySQLは、インストールが簡単で、強力で管理しやすいため、初心者に適しています。 1.さまざまなオペレーティングシステムに適した、単純なインストールと構成。 2。データベースとテーブルの作成、挿入、クエリ、更新、削除などの基本操作をサポートします。 3.参加オペレーションやサブクエリなどの高度な機能を提供します。 4.インデックス、クエリの最適化、テーブルパーティション化により、パフォーマンスを改善できます。 5。データのセキュリティと一貫性を確保するために、バックアップ、リカバリ、セキュリティ対策をサポートします。

NAVICAT自体はデータベースパスワードを保存せず、暗号化されたパスワードのみを取得できます。解決策:1。パスワードマネージャーを確認します。 2。NAVICATの「パスワードを記憶する」機能を確認します。 3.データベースパスワードをリセットします。 4.データベース管理者に連絡してください。

1.正しいインデックスを使用して、データの量を削減してデータ検索をスピードアップしました。テーブルの列を複数回検索する場合は、その列のインデックスを作成します。あなたまたはあなたのアプリが基準に従って複数の列からのデータが必要な場合、複合インデックス2を作成します2。選択した列のみを避けます。必要な列のすべてを選択すると、より多くのサーバーメモリを使用する場合にのみサーバーが遅くなり、たとえばテーブルにはcreated_atやupdated_atやupdated_atなどの列が含まれます。

次のコマンドでmysqlデータベースを表示します。サーバーに接続します:mysql -u username -pパスワードrun showデータベース。すべての既存のデータベースを取得するコマンド[データベース]を選択します。データベース名を使用します。テーブルを表示:表を表示します。テーブル構造を表示:テーブル名を説明してください。データを表示:[テーブル名]から[ *]を選択します。

NAVICATプレミアムを使用してデータベースを作成します。データベースサーバーに接続し、接続パラメーターを入力します。サーバーを右クリックして、[データベースの作成]を選択します。新しいデータベースの名前と指定された文字セットと照合を入力します。新しいデータベースに接続し、オブジェクトブラウザにテーブルを作成します。テーブルを右クリックして、データを挿入してデータを挿入します。

MySQLでテーブルをコピーするには、新しいテーブルの作成、データの挿入、外部キーの設定、インデックスのコピー、トリガー、ストアドプロシージャ、および機能が必要です。特定の手順には、同じ構造を持つ新しいテーブルの作成が含まれます。元のテーブルからデータを新しいテーブルに挿入します。同じ外部キーの制約を設定します(元のテーブルに1つがある場合)。同じインデックスを作成します。同じトリガーを作成します(元のテーブルに1つがある場合)。同じストアドプロシージャまたは関数を作成します(元のテーブルが使用されている場合)。

Passwordが暗号化された形式で保存されているため、MariadbのNavicatはデータベースパスワードを直接表示できません。データベースのセキュリティを確保するには、パスワードをリセットするには3つの方法があります。NAVICATを介してパスワードをリセットし、複雑なパスワードを設定します。構成ファイルを表示します(推奨されていない、高リスク)。システムコマンドラインツールを使用します(推奨されません。コマンドラインツールに習熟する必要があります)。
