Cannot set limit of MySQL open-files-limit from 1024 to 65535 - mysql

I have mysql ver. 5.1.49-3, I am working on linux debian. I am trying to set open-files-limit to 65535. so I edited te my.cnf in /etc/mysql/
[mysqld]
open_files_limit = 65535
[mysqld_safe]
open_files_limit = 65535
then in /etc/security/limit.conf
* soft nofile 100000
* hard nofile 200000
After restarting mysql service, when I run this command in linux
ps -ef|grep mysql
I got 65535. when I log into mysql as root and fetch the value of open-files-limit
show global variables like "%open_files_limit%";
I got 1024. Please help.

If mysql is started with systemd, this setting is important:
In the file /lib/systemd/system/mysql.service you have to add this 2 lines in the [Service] section at the end:
LimitNOFILE = infinity
LimitMEMLOCK = infinity
After this restart systemctl and mysql:
systemctl daemon-reload
/etc/init.d/mysql restart
To check if the configuration is effective, you can get the parameter from the running mysql process like this:
cat /proc/$(pgrep mysqld$)/limits | grep files

All I need is to add this line to /etc/pam.d/common-session:
session required pam_limits.so
then restart apache

An issue with older versions of MySQL require you to use use open-files-limit (dashes not underbars) in my.cnf. See http://bugs.mysql.com/bug.php?id=40368

do ulimit -a for show. ulimit -n NUMBER can change to YOUR_NUMEBR open files

Take a look at the official documentation:
"The value of this variable at runtime is the real value permitted by the system and might be different from the value you specify at server startup."

On Unbuntu 14.04 this worked
vim /etc/mysql/my.cnf
[mysqld]
open-files-limit=16000
After this, just restart mysql
/etc/init.d/mysql restart

Related

Zabbix and "PHP Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 78 bytes)"

I created this issue to solve a problem you have with zabbix, version 3.2 running on centos 7. The above error appeared when trying to access the zabbix GUI in a few moments.
I edited the php.ini file in CentOS as I saw here on stack overflow and it did not solve, it was necessary to edit the file /etc/httpd/conf.d/zabbix.conf, and modify the attribute php_value memory_limit 128M to 256M or 512M.
Just in case:
You may reset filter settings by adding filter_rst=1 after ? symbol in php query.
For example:
https://your.zabbix.server.com/zabbix/latest.php?filter_rst=1
First of all I had to find the file which contains the 'memory_limit' string by running this command:
grep -rnw '/etc' -e 'memory_limit'
Based on the result I increased the limit from 128M to 1024M in this below file:
/etc/opt/rh/rh-php72/php-fpm.d/zabbix.conf
Finally, restart the Apache, Zabbix, and PHP services:
systemctl restart rh-php72-php-fpm.service httpd zabbix-server

The max_connections in MySQL 5.7

I met a problem, the value of max_connction in MySQL is 214 after I set it 1000 via edit the my.cnf, just like below:
hadoop#node1:~$ mysql -V
mysql Ver 14.14 Distrib 5.7.15, for Linux (x86_64) using EditLine wrapper
MySQL version: 5.7
OS version : ubuntu 16.04LTS
mysql> show variables like 'max_connections';
+-----------------+-------+
| Variable_name | Value |
+-----------------+-------+
| max_connections | 151 |
+-----------------+-------+
1 row in set (0.00 sec)
As we can see, the variable value of max_connections is 151. Then , I edit the configuration file of MySQL.
yang2#node1:~$ sudo vi /etc/mysql/my.cnf
[mysqld]
character-set-server=utf8
collation-server=utf8_general_ci
max_connections=1000
Restart MySQL service after save the configraion.
yang2#node1:~$ service mysql restart
==== AUTHENTICATING FOR org.freedesktop.systemd1.manage-units ===
Authentication is required to restart 'mysql.service'.
Multiple identities can be used for authentication:
1. yangqiang,,, (yang2)
2. ,,, (hadoop)
Choose identity to authenticate as (1-2): 1
Password:
==== AUTHENTICATION COMPLETE ===
yang2#node1:~$
Now, we guess the max_connection is 1000, really?
mysql> show variables like 'max_connections';
+-----------------+-------+
| Variable_name | Value |
+-----------------+-------+
| max_connections | 214 |
+-----------------+-------+
1 row in set (0.00 sec)
It is 214. I do not really understand this result, who can help me? thx!
You may set the value manually, e.g.
set global max_connections=500;
however, after a restart of MySQL the value is reset to 214.
The solution depends on the (version of) OS and the MySQL version. With Ubuntu 16.04 and MySQL >= 5.7.7 following works:
systemctl edit mysql
Enter
[Service]
LimitNOFILE=8000
save, this will create a new file
/etc/systemd/system/mysql.service.d/override.conf
and restart the server:
systemctl daemon-reload
systemctl restart mysql
For other environments: Can not increase max_open_files for Mysql max-connections in Ubuntu 15
As MySQL documentation on max_connections setting says:
Increasing this value increases the number of file descriptors that
mysqld requires. If the required number of descriptors are not
available, the server reduces the value of max_connections.
This means that probably your MySQL server does not have enough resources to maintain the required number of descriptors.
MySQL documentation on How MySQL Opens and Closes Tables makes it clear that:
The table_open_cache and max_connections system variables affect the
maximum number of files the server keeps open. If you increase one or
both of these values, you may run up against a limit imposed by your
operating system on the per-process number of open file descriptors.
Many operating systems permit you to increase the open-files limit,
although the method varies widely from system to system. Consult your
operating system documentation to determine whether it is possible to
increase the limit and how to do so.
Follow the following steps:
cp /lib/systemd/system/mysql.service /etc/systemd/system/
echo -e "\r\nLimitNOFILE=infinity" >> /etc/systemd/system/mysql.service
echo "LimitMEMLOCK=infinity" >> /etc/systemd/system/mysql.service
sudo systemctl daemon-reload
sudo service mysql restart
And change or add he following line into file /etc/mysql/mysql.conf.d/mysqld.cnf :
[mysqld]
max_connections=110
Just this!
#Mahdi_Mohammadi
1.Edit mysql service file
#sudo cat /etc/systemd/system/multi-user.target.wants/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=600
Restart=on-failure
RuntimeDirectory=mysqld
RuntimeDirectoryMode=755
##this bellow for tuneup
LimitNOFILE=infinity
LimitMEMLOCK=infinity
2.edit /etc/mysql/mysql.conf.d/mysqld.cnf
max_connections = 99999
Add session required pam_limits.so in /etc/pam.d/common-session (usually is not present by default).
The in /etc/security/limits.conf you can add some limits:
* hard nofile 8192
* soft nofile 4096
Also check using ulimit -a the open files limit.
This you can increase with ulimit -n 4096
Make sure you reboot at the end.

How to set max connections in mysql permanently?

I need some help to set MAX connections value permanently in MySql. I have tried but I can't find a permanent solution. Now, I am using temporary solution by changing in command prompt like in this article.
Since this question shows up on the search results when people search for a solution, and now that the solution has changed, I felt it necessary to post an answer.
Ubuntu 15.04+ no longer respects the limits set in /etc/security/limits.conf. So if you set max connections and you don't see any effect, have a look at the log file at sudo vim /var/log/mysql/error.log and you'll see Changed limits: max_connections: 214 (requested 5000).
Solution:
Copy the limits for mysql from the systemd config file to /etc/systemd using:
sudo cp /lib/systemd/system/mysql.service /etc/systemd/system/
sudo vim /etc/systemd/system/mysql.service
Then add the following lines to the bottom of the file:
LimitNOFILE=infinity
LimitMEMLOCK=infinity
You could also use a finite number instead of infinity.
Now reload systemd config:
sudo systemctl daemon-reload
Thank you Very much i inserted the code into the MY.ini file and it solved the problem.
in c:/xampp/mysql/bin/my.ini file under the [mysqld] section i inserted the following line
**
max_connections = 250
**
Later restart the xampp server to take effect.
if we give set-variable=max_connections=250 Mysql server is not starting.
Once again thank you very much.
I had the same problem using Ubuntu 16.04.
Had to do it this way:
sudo vim /etc/systemd/system/mysql.service
Added the lines at the bottom of the file:
LimitNOFILE=infinity
LimitMEMLOCK=infinity
Reloaded systemd config:
sudo systemctl daemon-reload
Increased the number of files the system could open:
ulimit -n 4096
Edited my.cnf like this:
vi /etc/mysql/mysql.conf.d/mysqld.cnf
Looked for the max_connections and changed it´s value to 20000.
To make sure the settings become permanent performed a mysql service restart:
sudo service mysql restart
Went to phpmyadmin and checked the max_connections global variable using:
SHOW VARIABLES like '%max_connections';
It worked - Now when the daemon restarts I have the same max_connections that I had before.
you can set that in my.cnf, Mysql Doc
I quote
You can increase this value in main config file (e.g., /etc/my.cnf or /etc/mysql/my.cnf) using this syntax:
[mysqld]
set-variable=max_connections=250
i think you need to restart mysql after changes to take effect.

Reducing memory consumption of mysql on ubuntu#aws micro instance

I have recently started on a PoC project wherein we are developing a small web app. The initial setup is done on a micro instance from AWS. We are on rails+mysql stack.
After installing/running MySQL, I see that about 500+ MB RAM has been consumed already; leaving quite less for rest of the systems (micro instances have barely 620 MB RAM).
Our app is fairly simple at this stage. Can I do something to reduce the memory consumed by MySQL server?
Appreciate the help.
As of MySQL 8.0.30:
Edit your /etc/mysql/my.cnf file and add the following:
[mysqld]
performance_schema = 0
Restart your mysql server and happiness should ensue.
To verify that the configuration change has been loaded correctly, start a new mysql session (e.g. mysql -u root -p) and run the following:
SHOW VARIABLES LIKE '%perf%';
You should see the following line at the top:
| performance_schema | OFF |
It should read OFF. If it reads ON, your config was not properly loaded for some reason.
Change this setting in the MySQL configuration file (my.cnf)
key_buffer = 8M
max_connections = 30 # Limit connections
query_cache_size = 8M # try 4m if not enough
query_cache_limit = 512K
thread_stack = 128K
Just to add to the other answer. I recently had this problem myself with the Amazon micro instance (not Ubuntu). The my.cnf file is almost empty so what I did was this:
cp /etc/my.cnf /etc/my.cnf.orig
cp /usr/share/mysql/my-medium.cnf /etc/my.cnf
Edit my.cnf and enable the innodb lines if applicable. Restart mysqld.
Also the micro instance has no swap, that might be a problem..
SWAPFILE=/mnt/swapfile.swap
dd if=/dev/zero of=$SWAPFILE bs=1M count=512
mkswap $SWAPFILE
swapon $SWAPFILE
Then in /etc/rc.local add:
swapon /mnt/swapfile.swap
To save memory in ruby you might want to use ruby enterprise:
bash < <(curl -s https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer)
gpasswd -a root rvm
source /etc/profile.d/rvm.sh
rvm get head
rvm reload
rvm install ree
rvm --default use ree
I have a server with only 500mb ram and found that mysql started using a lot of ram as my tables got larger. After playing with a bunch of the settings, what reduced memory usage for me was to convert all my tables to MyISAM.
If you dont need the features of innodb converting tables to MyISAM helps quite a bit.
You can convert tables like this :
ALTER TABLE test.mytable ENGINE=MyISAM;
After this change I found that memory usage decreased by 20%.
To get a further reduction in memory usage you can convert ALL of your tables to MyISAM and then turn off innodb support in mysql altogether.
This reduced my memory usage by 50%.
You can do this by adding :
[mysqld]
default_storage_engine=myisam
innodb=OFF
and then restarting mysql.
Configure Swapfile
sudo fallocate -l 2G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
sudo cp /etc/fstab /etc/fstab.bak
sudo nano /etc/fstab
Add the following line at the end, save and close:
/swapfile swap swap defaults 0 0
sudo sysctl vm.swappiness=10
sudo vi /etc/sysctl.conf
Add the following line at the end, save and close:
vm.swappiness=10
Configure PHP
sudo nano /opt/bitnami/php/etc/memory.conf
; Bitnami memory configuration for PHP-FPM
;
; Note: This will be modified on server size changes
pm.max_children=10
pm.start_servers=2
pm.min_spare_servers=2
pm.max_spare_servers=10
pm.max_requests=5000
Configure MariaDB (MySQL)
sudo nano /opt/bitnami/mariadb/conf/bitnami/memory.conf
[mysqld]
#wait_timeout = 120
long_query_time = 1
query_cache_limit=2M
query_cache_type=1
query_cache_size=8M
innodb_buffer_pool_size=16M
#innodb_log_file_size=128M
#innodb_flush_method=O_DIRECT
tmp_table_size=16M
max_connections = 100
max_user_connections = 250
key_buffer_size=8M
sudo /opt/bitnami/ctlscript.sh restart

Does MySQL included with MAMP not include a config file?

I can't seem to find the my.cnf or other config file for the MySQL that comes with MAMP. Does it not include one?
The MySQL server of MAMP (not PRO) will be started without any my.cnf file. But you can create your own my.cnf file.
Stop servers
Create a my.cnf file in /Applications/MAMP/conf/
Add your content in to my.cnf
Save my.cnf
Start servers
You do not have to put a complete configuration in the my.cnf file. You can just add parts of a configuration ... for example:
[mysqld]
max_allowed_packet = 64M
Some standard my.cnf variants can be found at /Applications/MAMP/Library/support-files/
Invoking mysqld --verbose --help | less on the MAMP mysqld binary reports:
Default options are read from the following files in the given order:
/etc/my.cnf /etc/mysql/my.cnf /Applications/MAMP/conf/my.cnf ~/.my.cnf
Copy one of the variants in /Applications/MAMP/Library/support-files/ to one of the locations in mysqld's search order above, and you should be good to go after restarting the daemon.
Since MAMP server generates my.cnf dynamically on MAMP server startup, it's best to use the following steps to add or edit the MySQL configuration:
Stop MAMP server
Goto Files > Edit Template > MySQL
Make the necessary changes and save
Restart MAMP
I tried this on MAMP PRO 3.5.
For MAMP 3.5 on Mac El Capitan, only this worked for me:
Stop servers
Create a my.cnf file in /Applications/MAMP/Library/
Add your content into my.cnf like
[mysqld]
max_allowed_packet = 64M
Save my.cnf
Start servers
Not required to change ownership of file, it should work. Verify by running SHOW VARIABLES in phpmyadmin and look for your changed setting.
No, it doesn't come with the my.cnf file
I found that MAMP PRO will create a my.cnf by default on startup under the MAMP/tmp directory if a ~/my.cnf is not provided ... grepping ps aux you may find the default location under /Applications/MAMP/tmp/my.cnf ...
ps aux | grep mysql
Which provided the following...
root 284 0.0 0.1 2435544 532 ?? Ss 12:00AM 0:00.06 /bin/sh /Applications/MAMP/Library/bin/mysqld_safe
--defaults-file=/Applications/MAMP/tmp/mysql/my.cnf
--port=8889 --socket=/Applications/MAMP/tmp/mysql/mysql.sock
--user=mysql --pid-file=/Applications/MAMP/tmp/mysql/mysql.pid
--log-error=/Applications/MAMP/logs/mysql_error_log.err
--tmpdir=/Applications/MAMP/tmp/mysql/tmpdir
--datadir=/Library/Application Support/appsolute/MAMP PRO/db/mysql