MySQL 常見錯誤及解決方案

作者:辰風(fēng)沐陽 閱讀:1355 發(fā)布時間:2022-06-30 上次更新:2023-02-17

1. Too many connections


運行環(huán)境:Winows11、Phpstudy V8.1.1.3、MySQL 5.7.26

同一時間 MySQL 的連接數(shù)量有限制,當(dāng)超過上限時將提示下面錯誤信息:

  1. 1040 - Too many connections

查看當(dāng)前最大連接數(shù)

  1. mysql> show variables like '%max_connection%';
  2. +-----------------+-------+
  3. | Variable_name | Value |
  4. +-----------------+-------+
  5. | max_connections | 100 |
  6. +-----------------+-------+

修改最大連接數(shù)

  1. set global max_connections=500;

2. MySQL server has gone away


運行環(huán)境: Winows11 + Phpstudy V8.1.1.3

進(jìn)入 MySQL 命令行后,長時間連接 MySQL 服務(wù)但未進(jìn)行操作,MySQL服務(wù)自動斷開,再次執(zhí)行操作時出現(xiàn)以下提示

  1. ERROR 2006 (HY000): MySQL server has gone away
  2. No connection. Trying to reconnect...
  3. Connection id: 2
  4. Current database: liang

查看超時時間兩種寫法(默認(rèn)超時時間為 120 秒):

  1. select @@wait_timeout;
  2. show variables like 'wait_timeout';

當(dāng)前會話的超時時間設(shè)置為 700 秒

  1. set @@wait_timeout = 700;

標(biāo)簽: mysql