<p>I had successfully deployed MySQL router in Kubernetes as described in <a href="https://stackoverflow.com/questions/63149618/mysql-router-in-kubernetes-as-a-service">this</a> answer.</p>
<p>But recently I noticed mysql router was having overflow issues after some time.</p>
<pre><code>Starting mysql-router.
2022-03-08 10:33:33 http_server INFO [7f2ba406f880] listening on 0.0.0.0:8443
2022-03-08 10:33:33 io INFO [7f2ba406f880] starting 4 io-threads, using backend 'linux_epoll'
2022-03-08 10:33:33 metadata_cache INFO [7f2b63fff700] Starting Metadata Cache
2022-03-08 10:33:33 metadata_cache INFO [7f2b63fff700] Connections using ssl_mode 'PREFERRED'
2022-03-08 10:33:33 metadata_cache INFO [7f2b9c2c8700] Starting metadata cache refresh thread
2022-03-08 10:33:33 routing INFO [7f2b617fa700] [routing:myCluster_ro] started: listening on 0.0.0.0:6447, routing strategy = round-robin-with-fallback
2022-03-08 10:33:33 routing INFO [7f2b60ff9700] [routing:myCluster_rw] started: listening on 0.0.0.0:6446, routing strategy = first-available
2022-03-08 10:33:33 routing INFO [7f2b3ffff700] [routing:myCluster_x_ro] started: listening on 0.0.0.0:64470, routing strategy = round-robin-with-fallback
2022-03-08 10:33:33 routing INFO [7f2b3f7fe700] [routing:myCluster_x_rw] started: listening on 0.0.0.0:64460, routing strategy = first-available
2022-03-08 10:33:33 metadata_cache INFO [7f2b9c2c8700] Potential changes detected in cluster 'myCluster' after metadata refresh
2022-03-08 10:33:33 metadata_cache INFO [7f2b9c2c8700] Metadata for cluster 'myCluster' has 1 replicasets:
2022-03-08 10:33:33 metadata_cache INFO [7f2b9c2c8700] 'default' (3 members, single-primary)
2022-03-08 10:33:33 metadata_cache INFO [7f2b9c2c8700]     node3.me.com:3306 / 33060 - mode=RW 
2022-03-08 10:33:33 metadata_cache INFO [7f2b9c2c8700]     node2.me.com:3306 / 33060 - mode=RO 
2022-03-08 10:33:33 metadata_cache INFO [7f2b9c2c8700]     node1.me.com:3306 / 33060 - mode=RO 
2022-03-08 10:33:33 routing INFO [7f2b9c2c8700] Routing routing:myCluster_x_rw listening on 64460 got request to disconnect invalid connections: metadata change
2022-03-08 10:33:33 routing INFO [7f2b9c2c8700] Routing routing:myCluster_x_ro listening on 64470 got request to disconnect invalid connections: metadata change
2022-03-08 10:33:33 routing INFO [7f2b9c2c8700] Routing routing:myCluster_rw listening on 6446 got request to disconnect invalid connections: metadata change
2022-03-08 10:33:33 routing INFO [7f2b9c2c8700] Routing routing:myCluster_ro listening on 6447 got request to disconnect invalid connections: metadata change
2022-03-08 14:59:30 routing WARNING [7f2b9d2ca700] [routing:myCluster_rw] reached max active connections (512 max=512)
2022-03-08 14:59:30 routing WARNING [7f2b9d2ca700] [routing:myCluster_rw] reached max active connections (512 max=512)
</code></pre>
<p>We have innodb cluster (MySQL 8)  and router is connected to it.</p>
<p>When I check <code>show processlist</code> in master node :</p>
<pre><code>| 6176344 | routeruser                  | 192.168.10.6:61195 | my_db | Sleep   |   23946 |                                                          | NULL   
|
| 6176345 | routeruser                  | 192.168.10.6:62671 | my_db | Sleep   |   23946 |                                                                | NULL   
|
| 6176346 | routeruser                  | 192.168.10.6:65531 | my_db | Sleep   |   23946 |                                                                | NULL 
|
| 6176347 | routeruser                  | 192.168.10.6:39541 | my_db | Sleep   |   23946 |                                                                | NULL                          |
| 6176348 | routeruser                  | 192.168.10.6:34074 | my_db | Sleep   |   23946 |                                                                | NULL
</code></pre>
<p>I had stopped all custom applications running in K8,but still I got this issue.</p>
<p>In <code>/etc/mysql/mysql.conf.d/mysqld.cnf</code></p>
<pre><code>[mysqld]
pid-file    = /var/run/mysqld/mysqld.pid
socket      = /var/run/mysqld/mysqld.sock
datadir     = /var/lib/mysql
log-error   = /var/log/mysql/error.log
log_timestamps='SYSTEM'
max_connections = 1000
</code></pre>
<p>What am I missing here? why router service overflow after working few hours? Any help to solve/further debug this issue is highly appreciate.</p>

Sachith Muhandiram
<blockquote>
<p>Why router service overflow after working few hours?</p>
</blockquote>
<p>From what I know, you would modify the <code>max_connection</code> setting at <code>mysqld</code> section in your MySQL configuration file. You could determine where the location of the configuration file is by running command:</p>
<blockquote>
<p><code>mysqld --help --verbose</code></p>
</blockquote>
<p>After modify don't forget about restart your MySQL server.</p>
<p>You have to set <code>$defaultvalue</code>  as the your desired value how it writes in <a href="https://dev.mysql.com/doc/mysql-router/8.0/en/mysql-router-conf-options.html#option_mysqlrouter_max_connections" rel="nofollow noreferrer">MySQL documentations</a>:</p>
<blockquote>
<p>Default Value = 512,
Minimum Value = 1,
Maximum Value = 9223372036854775807</p>
</blockquote>
<p>And also look in <code>max_total_connections</code> parameter at the same file.</p>
