Reducing memory consumption of mysql on ubuntu#aws micro instance - mysql

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

Related

I am using LOAD DATA LOCAL INFILE <URL> query In sql but ERROR: #2000 - LOAD DATA LOCAL INFILE is forbidden, check mysqli.allow_local_infile [duplicate]

Is there a MySQL command to locate the my.cnf configuration file, similar to how PHP's phpinfo() locates its php.ini?
There is no internal MySQL command to trace this, it's a little too abstract. The file might be in 5 (or more?) locations, and they would all be valid because they load cascading.
/etc/my.cnf
/etc/mysql/my.cnf
$MYSQL_HOME/my.cnf
[datadir]/my.cnf
~/.my.cnf
Those are the default locations MySQL looks at. If it finds more than one, it will load each of them & values override each other (in the listed order, I think). Also, the --defaults-file parameter can override the whole thing, so... basically, it's a huge pain in the butt.
But thanks to it being so confusing, there's a good chance it's just in /etc/my.cnf.
(If you just want to see the values: SHOW VARIABLES, but you'll need the permissions to do so.)
Run mysql --help and you will see:
Default options are read from the following files in the given order: /etc/my.cnf /etc/mysql/my.cnf ~/.my.cnf
You can actually "request" MySQL for a list of all locations where it searches for my.cnf (or my.ini on Windows). It is not an SQL query though. Rather, execute:
$ mysqladmin --help
or, prior 5.7:
$ mysqld --help --verbose
In the very first lines you will find a message with a list of all my.cnf locations it looks for. On my machine it is:
Default options are read from the following files in the given order:
/etc/my.cnf
/etc/mysql/my.cnf
/usr/etc/my.cnf
~/.my.cnf
Or, on Windows:
Default options are read from the following files in the given order:
C:\Windows\my.ini
C:\Windows\my.cnf
C:\my.ini
C:\my.cnf
C:\Program Files\MySQL\MySQL Server 5.5\my.ini
C:\Program Files\MySQL\MySQL Server 5.5\my.cnf
Note however, that it might be the case that there is no my.cnf file at any of these locations. So, you can create the file on your own - use one of the sample config files provided with MySQL distribution (on Linux - see /usr/share/mysql/*.cnf files and use whichever is appropriate for you - copy it to /etc/my.cnf and then modify as needed).
Also, note that there is also a command line option --defaults-file which may define custom path to my.cnf or my.ini file. For example, this is the case for MySQL 5.5 on Windows - it points to a my.ini file in the data directory, which is not normally listed with mysqld --help --verbose. On Windows - see service properties to find out if this is the case for you.
Finally, check the https://dev.mysql.com/doc/refman/8.0/en/option-files.html - it is described there in more details.
You could always run find in a terminal.
find / -name my.cnf
mysql --help | grep /my.cnf | xargs ls
will tell you where my.cnf is located on Mac/Linux
ls: cannot access '/etc/my.cnf': No such file or directory
ls: cannot access '~/.my.cnf': No such file or directory
/etc/mysql/my.cnf
In this case, it is in /etc/mysql/my.cnf
ls: /etc/my.cnf: No such file or directory
ls: /etc/mysql/my.cnf: No such file or directory
ls: ~/.my.cnf: No such file or directory
/usr/local/etc/my.cnf
In this case, it is in /usr/local/etc/my.cnf
You can use :
locate my.cnf
whereis my.cnf
find . -name my.cnf
This might work:
strace mysql ";" 2>&1 | grep cnf
on my machine this outputs:
stat64("/etc/my.cnf", 0xbf9faafc) = -1 ENOENT (No such file or directory)
stat64("/etc/mysql/my.cnf", {st_mode=S_IFREG|0644, st_size=4271, ...}) = 0
open("/etc/mysql/my.cnf", O_RDONLY|O_LARGEFILE) = 3
read(3, "# /etc/mysql/my.cnf: The global "..., 4096) = 4096
stat64("/home/xxxxx/.my.cnf", 0xbf9faafc) = -1 ENOENT (No such file or directory)
So it looks like /etc/mysql/my.cnf is the one since it stat64() and read() were successful.
By default, mysql search my.cnf first at /etc folder. If there is no /etc/my.cnf file inside this folder, I advise you to create new one in this folder as indicated by the documentation (https://dev.mysql.com/doc/refman/5.6/en/option-files.html).
You can also search for existing my.cnf furnished by your mysql installation. You can launch the following command
sudo find / -name "*.cnf"
You can use the following configuration file with myisam table and without innodb mysql support (from port installation of mysql on mac os x maverick). Please verify each command in this configuration file.
# Example MySQL config file for large systems.
#
# This is for a large system with memory = 512M where the system runs mainly
# MySQL.
#
# MySQL programs look for option files in a set of
# locations which depend on the deployment platform.
# You can copy this option file to one of those
# locations. For information about these locations, see:
# http://dev.mysql.com/doc/mysql/en/option-files.html
#
# In this file, you can use all long options that a program supports.
# If you want to know which options a program supports, run the program
# with the "--help" option.
# The following options will be passed to all MySQL clients
[client]
#password = your_password
port = 3306
socket = /opt/local/var/run/mysql5/mysqld.sock
# Here follows entries for some specific programs
# The MySQL server
[mysqld]
port = 3306
socket = /opt/local/var/run/mysql5/mysqld.sock
skip-locking
key_buffer_size = 256M
max_allowed_packet = 1M
table_open_cache = 256
sort_buffer_size = 1M
read_buffer_size = 1M
read_rnd_buffer_size = 4M
myisam_sort_buffer_size = 64M
thread_cache_size = 8
query_cache_size= 16M
# Try number of CPU's*2 for thread_concurrency
thread_concurrency = 8
# Don't listen on a TCP/IP port at all. This can be a security enhancement,
# if all processes that need to connect to mysqld run on the same host.
# All interaction with mysqld must be made via Unix sockets or named pipes.
# Note that using this option without enabling named pipes on Windows
# (via the "enable-named-pipe" option) will render mysqld useless!
#
#skip-networking
# Replication Master Server (default)
# binary logging is required for replication
log-bin=mysql-bin
# binary logging format - mixed recommended
binlog_format=mixed
# required unique id between 1 and 2^32 - 1
# defaults to 1 if master-host is not set
# but will not function as a master if omitted
server-id = 1
# Replication Slave (comment out master section to use this)
#
# To configure this host as a replication slave, you can choose between
# two methods :
#
# 1) Use the CHANGE MASTER TO command (fully described in our manual) -
# the syntax is:
#
# CHANGE MASTER TO MASTER_HOST=<host>, MASTER_PORT=<port>,
# MASTER_USER=<user>, MASTER_PASSWORD=<password> ;
#
# where you replace <host>, <user>, <password> by quoted strings and
# <port> by the master's port number (3306 by default).
#
# Example:
#
# CHANGE MASTER TO MASTER_HOST='125.564.12.1', MASTER_PORT=3306,
# MASTER_USER='joe', MASTER_PASSWORD='secret';
#
# OR
#
# 2) Set the variables below. However, in case you choose this method, then
# start replication for the first time (even unsuccessfully, for example
# if you mistyped the password in master-password and the slave fails to
# connect), the slave will create a master.info file, and any later
# change in this file to the variables' values below will be ignored and
# overridden by the content of the master.info file, unless you shutdown
# the slave server, delete master.info and restart the slaver server.
# For that reason, you may want to leave the lines below untouched
# (commented) and instead use CHANGE MASTER TO (see above)
#
# required unique id between 2 and 2^32 - 1
# (and different from the master)
# defaults to 2 if master-host is set
# but will not function as a slave if omitted
#server-id = 2
#
# The replication master for this slave - required
#master-host = <hostname>
#
# The username the slave will use for authentication when connecting
# to the master - required
#master-user = <username>
#
# The password the slave will authenticate with when connecting to
# the master - required
#master-password = <password>
#
# The port the master is listening on.
# optional - defaults to 3306
#master-port = <port>
#
# binary logging - not required for slaves, but recommended
#log-bin=mysql-bin
# Uncomment the following if you are using InnoDB tables
#innodb_data_home_dir = /opt/local/var/db/mysql5
#innodb_data_file_path = ibdata1:10M:autoextend
#innodb_log_group_home_dir = /opt/local/var/db/mysql5
# You can set .._buffer_pool_size up to 50 - 80 %
# of RAM but beware of setting memory usage too high
#innodb_buffer_pool_size = 256M
#innodb_additional_mem_pool_size = 20M
# Set .._log_file_size to 25 % of buffer pool size
#innodb_log_file_size = 64M
#innodb_log_buffer_size = 8M
#innodb_flush_log_at_trx_commit = 1
#innodb_lock_wait_timeout = 50
[mysqldump]
quick
max_allowed_packet = 16M
[mysql]
no-auto-rehash
# Remove the next comment character if you are not familiar with SQL
#safe-updates
[myisamchk]
key_buffer_size = 128M
sort_buffer_size = 128M
read_buffer = 2M
write_buffer = 2M
[mysqlhotcopy]
interactive-timeout
For Ubuntu 16: /etc/mysql/mysql.conf.d/mysqld.cnf
As noted by konyak you can get the list of places mysql will look for your my.cnf file by running mysqladmin --help. Since this is pretty verbose you can get to the part you care about quickly with:
$ mysqladmin --help | grep -A1 'Default options'
This will give you output similar to:
Default options are read from the following files in the given order:
/etc/my.cnf /etc/mysql/my.cnf /usr/local/etc/my.cnf ~/.my.cnf
Depending on how you installed mysql it is possible that none of these files are present yet. You can cat them in order to see how your config is being built and create your own my.cnf if needed at your preferred location.
I don't know how you've setup MySQL on your Linux environment but have you checked?
/etc/my.cnf
Try running mysqld --help --verbose | grep my.cnf | tr " " "\n"
Output will be something like
/etc/my.cnf
/etc/mysql/my.cnf
/usr/local/etc/my.cnf
~/.my.cnf
You can also run this command.
mysql --help | grep cnf
If you're on a Mac with Homebrew, use
brew info mysql
You'll see something like
$ brew info mysql
mysql: stable 5.6.13 (bottled)
http://dev.mysql.com/doc/refman/5.6/en/
Conflicts with: mariadb, mysql-cluster, percona-server
/usr/local/Cellar/mysql/5.6.13 (9381 files, 354M) *
That last line is the INSTALLERDIR per the MySQL docs
Be aware that although mariadDB loads configuration details from the various my.cnf files as listed in the other answers here, it can also load them from other files with different names.
That means that if you make a change in one of the my.cnf files, it may get overwritten by another file of a different name. To make the change stick, you need to change it in the right (last loaded) config file - or, maybe, change it in all of them.
So how do you find all the config files that might be loaded? Instead of looking for my.cnf files, try running:
grep -r datadir /etc/mysql/
This will find all the places in which datadir is mentioned. In my case, it produces this answer:
/etc/mysql/mariadb.conf.d/50-server.cnf:datadir = /var/lib/mysql
When I edit that file (/etc/mysql/mariadb.conf.d/50-server.cnf) to change the value for datadir, it works, whereas changing it in my.cnf does not. So whatever option you are wanting to change, try looking for it this way.
If you are on Debian/Ubuntu system and already equipped with modern versions of the database (everything from 5.7 up, also true for mysql 8) the best way to locate the actual .cnf file I have found is:
sudo update-alternatives --config my.cnf
You should see a output like this:
There are 3 choices for the alternative my.cnf (providing /etc/mysql/my.cnf).
Selection Path Priority Status
------------------------------------------------------------
0 /etc/mysql/mariadb.cnf 500 auto mode
1 /etc/mysql/mariadb.cnf 500 manual mode
2 /etc/mysql/my.cnf.fallback 100 manual mode
* 3 /etc/mysql/mysql.cnf 300 manual mode
There are two lines in /etc/mysql/mysql.cnf that it makes sense to pay attention to:
!includedir /etc/mysql/conf.d/
!includedir /etc/mysql/mysql.conf.d/
MySQL will go watching for all .cnf files in /etc/mysql/conf.d/, then all files in /etc/mysql/mysql.conf.d/
Happy tuning!
Found mine using
mysqld --help --verbose | grep my.cnf
Answered for only MySQL Workbench users,
Another option is to use the whereis command.
E.g. whereis my.cnf
I installed xampp bundle with apache, php and mysql in ubuntu. There my.cnf file is located in /opt/lampp/etc/ folder. Hope it'll help somebody.
All great suggestions, in my case I didn't find it in any of those locations, but in /usr/share/mysql, I have a RHEL VM and I installed mysql5.5
You will have to look through the various locations depending on your version of MySQL.
mysqld --help -verbose | grep my.cnf
For Homebrew:
/usr/local/Cellar/mysql/8.0.11/bin/mysqld (mysqld 8.0.11)
Default possible locations:
/etc/my.cnf
/etc/mysql/my.cnf
~/.my.cnf
Found mine here:
/usr/local/etc/my.cnf
On Ubuntu (direct edit) :
$ sudo nano /etc/mysql.conf.d/mysqld.cnf
In case you are in a VPS and are trying to edit a my.cnf on an already running server you could try:
ps aux | grep mysql
You will be show the parameters the mysql command is being run and where the --defaults-file points to
Note that your server might be running more than one MySQL/MariaDB server's. If you see a line without --defaults-file parameter, that instance might be retrieving the configuration from the .cnf's that are mentioned on mysqladmin --help as others have pointed out.
You can find my.cnf or any other file with find command:
find / -name my.cnf (or any other file name)
find is a command
/ (slash) is a path
my.cnf is a file name
If you are using MAMP, access Templates > MySQL (my.cnf) > [version]
If you are running MAMP windowless you may need to customize the toolbar using the Customize button.
for me it was that i had "ENGINE=MyISAM" kind of tables , once i changed it to "ENGINE=InnoDB" it worked:)
in PhpMyAdmin on Azure App Service :)
It depend on your access right but for me
this work on phpmyadmin sql console
SHOW VARIABLES;
then after to change some variables
you can do
SET GLOBAL max_connections = 1000;
or
SET ##GLOBAL.max_connections = 1000;
give a try
MySQL configuration file:
/etc/my.cnf
try
mysql --verbose --help | grep -A 1 "Default options"
For MariaDB 10.5 on Ubuntu 20.04.4 LTS (Focal Fossa):
# The MariaDB configuration file
#
# The MariaDB/MySQL tools read configuration files in the following order:
# 0. "/etc/mysql/my.cnf" symlinks to this file, reason why all the rest is read.
# 1. "/etc/mysql/mariadb.cnf" (this file) to set global defaults,
# 2. "/etc/mysql/conf.d/*.cnf" to set global options.
# 3. "/etc/mysql/mariadb.conf.d/*.cnf" to set MariaDB-only options.
# 4. "~/.my.cnf" to set user-specific options.
#
# If the same option is defined multiple times, the last one will apply.

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

cannot increase open-files-limit in mariadb 10 on centos7

I searched about the topic subject and tested options, but I still cant increase the open-files-limit on my mariadb server that is used as remote database server for cpanel/whm server.
here is s good reference
http://duntuk.com/how-raise-ulimit-open-files-and-mysql-openfileslimit
I increased it in
/etc/my.cnf
open-files-limit=65550
here is some results
#ulimit -a
core file size (blocks, -c) 0
data seg size (kbytes, -d) unlimited
scheduling priority (-e) 0
file size (blocks, -f) unlimited
pending signals (-i) 63471
max locked memory (kbytes, -l) 64
max memory size (kbytes, -m) unlimited
open files (-n) 65535
pipe size (512 bytes, -p) 8
POSIX message queues (bytes, -q) 819200
real-time priority (-r) 0
stack size (kbytes, -s) 8192
cpu time (seconds, -t) unlimited
max user processes (-u) 65535
virtual memory (kbytes, -v) unlimited
file locks (-x) unlimited
#ulimit -Hn -Sn
open files (-n) 65535
open files (-n) 65535
cat /etc/systemd/system/mariadb.service.d/limits.conf
[Service]
LimitNOFILE=65500
cat /usr/lib/systemd/system/mariadb.service
[Unit]
Description=MariaDB database server
After=syslog.target
After=network.target
[Service]
Type=simple
User=mysql
Group=mysql
LimitNOFILE=infinity
LimitMEMLOCK=infinity
and still in mysql I get
show global variables like 'open%';
+------------------+-------+
| Variable_name | Value |
+------------------+-------+
| open_files_limit | 1024 |
+------------------+-------+
1 row in set (0.00 sec)
and im getting following error over and over after restart
60108 16:30:02 [ERROR] mysqld: Can't open file: './username_wp/wp_users.frm' (errno: 24)
160108 16:30:02 [ERROR] Error in accept: Too many open files
160108 16:30:04 [ERROR] Error in accept: Too many open files
160108 16:30:06 [ERROR] Error in accept: Too many open files
160108 16:30:11 [ERROR] mysqld: Can't open file: './username_db/strikes.frm' (errno: 24)
and here is the startup log of mariadb
[Warning] Could not increase number of max_open_files to more than 1024 (request: 132107)
RH/CentOS mariadb integration is quiet confusing, using in some places mariadb as its name, mysqld elsewhere...
You should edit(or create) a .conf file in
/etc/systemd/system/mariadb.service.d/
For eg: /etc/systemd/system/mariadb.service.d/centreon.conf
Then edit it as kujiy suggested
[Service]
LimitNOFILE=320000
Don't forget to reload systemd services files:
# systemctl daemon-reload
Cedric
This is an OS problem.
I think you have to increase the "hard limit" in /etc/security/limits.conf, something like this:
* hard nofile 65536
* soft nofile 16384
then use ulimit to increase the "soft limit".
finally i find solution but without any reasonable cause !
i was running MariaDB 5.5 and all settings where fine but the soft limit did not goes more than 1024 !
i was thinking my mariadb is 10.0 as i freshly installed it
after i find out that its 5.5 i tried to upgrade it to v10.0 ! and then BOOM ! problem solved without any extra action or setting ( kernel setting allows maximum files limit as described in reference link )
i hope it help other peoples have same problem ( but after try all other required settings )
You can see the official instruction in the mariadb.service file;
[root#db1 system]# cat /usr/lib/systemd/system/mariadb.service | grep exam -A 5
# For example, if you want to increase mariadb's open-files-limit to 10000,
# you need to increase systemd's LimitNOFILE setting, so create a file named
# "/etc/systemd/system/mariadb.service.d/limits.conf" containing:
# [Service]
# LimitNOFILE=10000
Though I think this should be written in the official manual...
I have CentOS 7.3 with MariaDB 10.0.29 installed from official repo.
For some reason, systemd unit is named mysql and I had to create /etc/systemd/system/mysql.service.d/oioki.conf:
[Service]
LimitNOFILE=500000
Don't forget to run systemctl daemon-reload after that.
open_files_limit is dynamic value that depends on next params:
#my.cnf file
# max connections
max_connections = 64
# table_open_cache = max_connections * tables used in one transaction + 5
table_open_cache = 800
# table_definition_cache = all tables(50) + max_connections + 5
table_definition_cache = 400
# open_files_limit = table_open_cache * 1.4
open_files_limit = 1120
To check the value of open_files_limit run this command from mysql:
mysql> select ##open_files_limit;
...it will output:
+--------------------+
| ##open_files_limit |
+--------------------+
| 12903 |
+--------------------+
1 row in set (0.000 sec)
I had this problem running RedHat Enterprise Linux 7.2 with Software Collections (SCL) and SystemD
rh-mariadb100-mariadb-server-10.0.20-1.el7.x86_64
In my case the hard limit was ok, but the soft limit was stuck on 1024
Summary of the old and new
old : RHEL6.x : MySQL : init.d : mysql_safe : 'root', mysqld : 'mysql'
new : RHEL7.x : MariaDB : SystemD : mysql_safe : 'mysql', mysqld 'mysql'
Note that the old initl.d wrapper script runs as root, but the new SystemD wrapper script runs as 'mysql'. This can cause mysql_safe to not make the call to ulimit. In my case setting LimitNOFILE in SystemD didn't help - all it did was increase the file limit for the wrapper, but NOT for the daemon itself.
I found a two step process to get it working
Step 1 - re-instate the mysqld_safe section to the conf file so that mysql_safe will read it
sudo vi /etc/opt/rh/rh-mariadb100/my.cnf.d/mariadb-server.cnf
[mysqld_safe]
open_files_limit=2048
Step 2 - create a SystemD drop-in to start the wrapper as root (the daemon will still run as 'mysql'). Note that LimitNOFILE is commented out.
/etc/systemd/system
mkdir rh-mariadb100-mariadb.service.d
cd rh-mariadb100-mariadb.service.d
vi limits.conf
[Service]
#LimitNOFILE=2048
User=
Group=
Reload SystemD service files
systemctl daemon-reload
now restart the service, check value of open_files_limit in mysql client
it should now say 2048 (new soft limit)
The proper solution would probably be to get rid of the wrapper and use native SystemD.
UPDATE
it looks like this is fixed in the more recent version, which no longer uses the mysql_safe wrapper
rh-mariadb101-mariadb-10.1.19-6.el7.x86_64
To increase open-files-limit in MySQL 5.6 on Centos 7 you must:
nano /usr/lib/systemd/system/mysqld.service
add at the end of the file:
LimitNOFILE=65535
LimitNPROC=65535
then:
systemctl daemon-reload
systemctl restart mysqld
Done! , I assume that for MariaDB is the same thing
Ensure that no other files exist in the:
/etc/systemd/system/mariadb.service.d
folder that might be limiting the number of files.
That was my case, there was another file that was reducing the limit I set :)

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

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

Can't get MySQL Community Server to Start from Command prompt or Netbeans IDE

I have installed Netbeans 7 on my Windows 7. In addition, the MySQL Community Server 5.6.12
is installed with the MSI installer on thesame 7 PC.
The MySQL server is integrated with the Netbeans IDE. However , it is not possible to start or stop the MySQL server from the command prompt or the Netbeans IDE.
I am only able to start or stop the server from the Windows 7 services tool.
Also , it is difficult running SQL queries from the Netbeans IDE even though it shows there is connection with the MySQL server.
I have added the my.ini file to the installed directory of the MySQL server , that is :
C:\Program Files\MySQL\MySQL Server 5.6
below is the my.ini file :
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html
# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the
# *** default location during install, and will be replaced if you
# *** upgrade to a newer version of MySQL.
[mysqld]
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
# These are commonly set, remove the # and set as required.
# basedir = .....
# datadir = .....
port = 3306
# server_id = .....
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
Any suggestion is welcomed.