天天看點

mysql常見的參數配置_mysql常見配置參數

1max_connections

MySQL的最大連接配接數,增加該值增加mysqld 要求的檔案描述符的數量。如果伺服器的并發連接配接請求量比較大,建議調高此值,以增加并行連接配接數量,當然這建立在機器能支撐的情況下,因為如果連接配接數越多,介于MySQL會為每個連接配接提供連接配接緩沖區,就會開銷越多的記憶體,是以要适當調整該值,不能盲目提高設值。

數值過小會經常出現ERROR 1040: Too many connections錯誤,可以過’conn%’通配符檢視目前狀态的連接配接數量,以定奪該值的大小。

1.1出現的異常

18:38:11.262 [main] ERROR com.alibaba.druid.pool.DruidDataSource - {dataSource-10} init errorcom.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Data source rejected establishment of connection, message from server: "Too many connections"

1.2 檢視max_used_connections和max_connections

mysql> show variables like 'max_connections';+-----------------+-------+| Variable_name | Value |+-----------------+-------+| max_connections | 151 |+-----------------+-------+1 row in set (0.00 sec)mysql> show status like 'max%connections';+----------------------+-------+| Variable_name | Value |+----------------------+-------+| Max_used_connections | 152 |+----------------------+-------+1 row in set (0.00 sec)

max_used_connections / max_connections * 100% (理想值≈ 85%)

如果max_used_connections跟max_connections相同 那麼就是max_connections設定過低或者超過伺服器負載上限了,低于10%則設定過大。

這裡可以選擇把max_connections設定為200

1.3設定max_connections的值

1.在配置檔案my.cnf中設定max_connections的值

找到max_connections一行,修改為(如果沒有,則自己添加),

上面的1000即該參數的值。需要重新開機mysql

2、實時(臨時)修改此參數的值

首先登陸mysql,執行如下指令:

mysql> set GLOBAL max_connections=200;Query OK, 0 rows affected (0.00 sec)mysql> show variables like 'max_connections';+-----------------+-------+| Variable_name | Value |+-----------------+-------+| max_connections | 200 |+-----------------+-------+1 row in set (0.00 sec)

修改後就不再報剛才的錯了

mysql> show status like 'max%connections';+----------------------+-------+| Variable_name | Value |+----------------------+-------+| Max_used_connections | 165 |+----------------------+-------+1 row in set (0.00 sec)