How to increase value open_file_limit in mysql

Hello Community Team,

i want to increate open_files_limit = 5000 in my.cnf to open_files_limit= 1048576. i have edited my.cnf file but it not take effect (Restarted mysql). still after that it shows the 5000.

mysql> show variables like ‘%open%files%’;
±------------------±------+
| Variable_name | Value |
±------------------±------+
| innodb_open_files | 2000 |
| open_files_limit | 5000 |
±------------------±------+
2 rows in set (0.00 sec)

cat /lib/systemd/system/mysql.service

MySQL systemd service file

[Unit]
Description=MySQL Community Server
After=network.target

[Install]
WantedBy=multi-user.target

[Service]
Type=forking
User=mysql
Group=mysql
PIDFile=/run/mysqld/mysqld.pid
PermissionsStartOnly=true
ExecStartPre=/usr/share/mysql/mysql-systemd-start pre
ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/run/mysqld/mysqld.pid
TimeoutSec=infinity
Restart=on-failure
RuntimeDirectory=mysqld
RuntimeDirectoryMode=755
LimitNOFILE=infinity
LimitMEMLOCK=infinity
tungsten@vm-mysql2-prod-sa:~$

i have tried /usr/lib/systemd/system/mysqld.service to edit LimitNOFILE parameter and restart the systemctl daemon-reload and mysql service but no luck still it shows old value.

1 Like

I hope you will find the following Blog post useful for the same,

1 Like

LimitNOFILE=infinity
Alos infinity could be considered as 65535. You may specify a higher integer value, if needed.

1 Like

Thanks for the update , also i have observed parameter updated in my.cnf file is not reflected even after restart the mysql. i have chnaged max_connections parameter but it still shows old value 4190.

while some parameter is shows properly like innodb_buffer_pool_size and innodb_buffer_pool_instances this parameter i have changed in same file and it shows proper after change. why max_connections parameter shows older value.

$ cat /etc/mysql/my.cnf
[mysqld]
bind-address=0.0.0.0
server-id=2
port=13306
datadir=/volumes/mysql/data/mysql
open_files_limit=1048576
log-bin=/volumes/mysql/binlogs/mysql/mysql-bin
sync_binlog=1
max_allowed_packet=52m
max_connections=100000
default-storage-engine=InnoDB
innodb_flush_log_at_trx_commit=1
innodb_flush_method=O_DIRECT
innodb_buffer_pool_instances=8
innodb_buffer_pool_size=16G
innodb_temp_data_file_path=ibtmp1:12M:autoextend:max:100G
innodb_log_file_size=512M
binlog-format=row
auto-increment-increment=10
auto-increment-offset=2
character-set-server=utf8
collation-server=utf8_general_ci
default-time-zone=‘+00:00’
max_connect_errors=10000

lower_case_table_names=1

innodb_read_io_threads=16
metadata_locks_hash_instances=256
innodb_concurrency_tickets=10000

1 Like

@matthewb @lalit.choudhary @Rahul_Malik can you please check thsi why some parameter taking affecting and some is not? it will really helpfull.

i have set max_connections=100000 and table_open_cache=2000 and restart the mysql but still it shows old value and execute mysqld --verbose --help it shows Changed limits: table_open_cache: 400 (requested 2000) , why it not reflecting?

mysql> show variables like ‘%max_connections%’;
±----------------±------+
| Variable_name | Value |
±----------------±------+
| max_connections | 4190 |
±----------------±------+
1 row in set (0.00 sec)

mysql> show variables like table_open_cache;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘table_open_cache’ at line 1
mysql> show variables like ‘%table_open_cache%’;
±---------------------------±------+
| Variable_name | Value |
±---------------------------±------+
| table_open_cache | 400 |
| table_open_cache_instances | 16 |
±---------------------------±------+
2 rows in set (0.00 sec)

mysql> exit
Bye
tungsten@vm-mysql2-prod-sa:/etc/mysql$ mysqld --verbose --help
2022-12-20T13:46:26.955286Z 0 [Warning] Changed limits: max_open_files: 65535 (requested 500000)
2022-12-20T13:46:26.955329Z 0 [Warning] Changed limits: max_connections: 64725 (requested 100000)
2022-12-20T13:46:26.955332Z 0 [Warning] Changed limits: table_open_cache: 400 (requested 2000)
mysqld Ver 5.7.39-0ubuntu0.18.04.2-log for Linux on x86_64 ((Ubuntu))
Copyright (c) 2000, 2022, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Starts the MySQL database server.

Usage: mysqld [OPTIONS]

Default options are read from the following files in the given order:
/etc/my.cnf /etc/mysql/my.cnf ~/.my.cnf
The following groups are read: mysqld server mysqld-5.7
The following options may be given as the first argument:
–print-defaults Print the program argument list and exit.
–no-defaults Don’t read default options from any option file,

1 Like

Issue resolved.

Create file /etc/systemd/system/mysqld.service or add if its exists already with below lines.

Load the defaults

.include /etc/systemd/system/multi-user.target.wants/mysqld.service

Custom Settings

[Service]
LimitNOFILE = (Infinity or any nubmer)

Reload the configuration

systemctl daemon-reload

and restart mysql database

service mysql restart

2 Likes