How do I correctly restart mysql so that changes in the `*.cnf`-files get active? - mysql

I try to configure mysql as mentioned here: https://websiteforstudents.com/install-erpnext-erp-platform-on-ubuntu-16-04-18-04-lts-with-nginx-mariadb-support/ on a Linux Mint 18.2 system.
I added innodb-file-format=barracuda to the [mysqld] section in /etc/mysql/mariadb.conf.d/50-server.cnf and restarted the mysql service. But these settings are taking no effect.
If I run following commands
sudo mysql -u root -p
SHOW VARIABLES LIKE 'innodb_file_format';
then I get following output.
+--------------------+----------+
| Variable_name | Value |
+--------------------+----------+
| innodb_file_format | Antelope |
+--------------------+----------+
The settings file ~/.my.cnf is not existing.
Why are my settings taking no effect?
++++++++++++ UPDATE 2019-06-03 ++++++++++++
I think I found the issue now. /etc/mysql/mariadb.conf.d/50-server.cnf is the correct logfile and the settings were not overwritten by another *.cnf-file. After a restart of the PC, the changed settings were used. The problem is, that restarting the mysql service (sudo service mysql restart or sudo /etc/init.d/mysql restart) is not enough.
So the question should be:
How do I correctly restart mysql so that changes in the *.cnf-files get active?

First, you should try to find my.cnf in other locations like
How do I find the MySQL my.cnf location
If no luck, scan all *.cnf files in /etc/mysql/mariadb.conf.d/ because Mariadb may read all *.cnf as config in that folder
Therefore you may add this value on 50-server.cnf, but it is overwritten in another files
Hope this helps

Don't do this:
systemctl restart mysqld
Instead, do:
systemctl stop mysqld
systemctl start mysqld
Not sure exactly what the syntax is for Debian's 'service' command but I believe that's just a wrapper around systemctl. Syntax should be easily found. Change the service name if your system uses something different, of course. I have found that for some services, doing a restart doesn't seem to reread the config files, while a stop and then start forces a complete reload and config file read.

Related

MariaDB cannot start after update: [Warning] Can't create test file /home/mysql/beta.lower-test

I've just updated MariaDB using apt-get dist-upgrade. Now it won't start using service mysql start anymore.
I can however, run it as root or do: sudo -u mysql mysqld_safe then MariaDB starts up fine. The folder /home/mysql is owned by the mysql user and group.
I've found the error to be thrown in this function:
https://github.com/MariaDB/server/blob/7ff44b1a832b005264994cbdfc52f93f69b92cdc/sql/mysqld.cc#L9865
I can't figure out what to do next. Any pointers?
To run MariaDB SQL from /home, in the file /usr/lib/systemd/system/mariadb.service or /lib/systemd/system/mariadb.service, just change :
ProtectHome=true
to :
ProtectHome=false
The answer by Thomas is correct, but get's reset by updates every few months. So here is a permanent solution:
Use systemctl edit mariadb to create a file overwritting the default settings of the mariadb service. (In debian it's located in /etc/systemd/system/mariadb.service.d/override.conf)
Set the same setting Thomas changed in the file:
[Service]
ProtectHome=false
Use systemctl daemon-reload to reload the systemctl config.
On debian 9 you need to change ProtectHome to false in both /lib/systemd/system/mariadb.service and /lib/systemd/system/mariadb#.service then run sudo systemctl daemon-reload.
Maybe also run sudo grep -Ri "protecthome" /lib/systemd/system to find other instances of ProtectHome in mysql-related files if this still isn't working
The workaround for this is mounting the directory in home as /var/lib/mysql:
mount --bind /home/mysql/var/lib/mysql /var/lib/mysql
Same situation after update on Debian 8 (Jessie) and 9 (Stretch). After "apt-get upgrade" the command
service mysql start
the server fails to start and logs error:
[Warning] Can't create test file /home/johndoe/UserDatabases/mypcname.lower-test
the solution is to change in file /lib/systemd/system/mariadb.service the value:
ProtectHome=true
to
ProtectHome=false
as described above.
#RedGiant yes I solved it. Forgot to post here.
Apparently after the .1 release you cannot run SQL from /home anymore. There's probably a way around this but haven't found it.
I can run MySQL from any location except /home. What I did was unmount /home (I had my SSD RAID mounted to /home) and re-mount my disk as /ssd. Changed my paths in the config and it worked right away.
I did not run SELinux or Apparmor.
I have faced the same issue as mentioned in the question. In my case, I wanted to move the MariaDB Data Directory to the /home/mysql folder but after changing the my.cnf file, MariaDB service was failing to start.
I have made the following changes in the file /lib/systemd/system/mariadb.service
ProtectHome=true to ProtectHome=false
It asked me to reload the daemon while starting the Mariadb service again. However, i have rebooted the server and started the MariaDB service without any issue.

Changes to my.cnf don't take effect (Ubuntu 16.04, mysql 5.6)

Changes I make to my.cnf don't seem to have any effect on the mysql environment. Here's a summary of what's happened...
I installed mysql 5.7 on Ubuntu 16.04 but then realized I needed to downgrade to mysql 5.6 due to incompatibility issues.
I apt purged the related applications and then removed any remaining directories such at /etc/mysql and /var/lib/mysql
I then installed mysql-5.6 (server and client) and related packages.
I was able to load one database from a dump from a server also running mysql 5.6 but when I tried to load a second database from a second dump from that same server, I got this error:
ERROR 2006 (HY000) at line 1721: MySQL server has gone away
When I Googled that, I saw results saying to set various options via the my.cnf file.
When I run...
updatedb && locate my.cnf
...I only see four results which are all links back to the same file: /etc/mysql/my.cnf.fallback. E.g. /etc/mysql/my.cnf.fallback == /etc/mysql/my.cnf
There are no .my.cnf files in either the root home directory or my user's home directory. I put a typo into the my.cnf file and reloaded mysql just to see the expected error and know the file was being loaded. I then removed the erroneous code and added the following:
[mysqld]
max_allowed_packet=1073741824
I then reloaded mysql by running in various ways:
service mysql restart
or
service mysql stop
service mysql start
or
/etc/init.d/mysql stop
/etc/init.d/mysql start
I then kept getting this default value indicating that it was not getting set from my.cnf:
mysql> SHOW VARIABLES LIKE 'max_allowed_packet';
+--------------------+---------+
| Variable_name | Value |
+--------------------+---------+
| max_allowed_packet | 4194304 |
+--------------------+---------+
If I do this:
mysql> SET GLOBAL max_allowed_packet=1073741824;
and log out and back into the mysql client, I see the correct value:
mysql> SHOW VARIABLES LIKE 'max_allowed_packet';
+--------------------+------------+
| Variable_name | Value |
+--------------------+------------+
| max_allowed_packet | 1073741824 |
+--------------------+------------+
But of course, if I restart the mysql server, the value reverts.
I've exhausted my search ability. What can I possibly be doing wrong?
The config files are fine. The root cause is a bug in the MySQL 5.6 packaging for Ubuntu 16.04.
If you check your /var/log/syslog you'll probably see a line like this:
Sep 15 18:56:09 ip-172-31-18-162 kernel: [ 383.840275] audit: type=1400 audit(1505501769.234:50): apparmor="DENIED" operation="open" profile="/usr/sbin/mysqld" name="/etc/mysql/my.cnf.fallback" pid=25701 comm="mysqld" requested_mask="r" denied_mask="r" fsuid=0 ouid=0
A security tool called AppArmor is denying access to a symlinked file (/etc/mysql/my.cnf.fallback).
Try this workaround, which will allow symlinks to be read by mysqld.
echo '/etc/mysql/** lr,' >> /etc/apparmor.d/local/usr.sbin.mysqld
systemctl reload apparmor
Now mysqld should see your custom config.
This bug appears to be fixed in the MySQL 5.7 Ubuntu package.
Obviously my.cnf.fallback is not the correct configuration file.
If you try this commands you can get output for possible my.cnf locations:
$ which mysqld
/usr/sbin/mysqld
$ /usr/sbin/mysqld --verbose --help | grep -A 1 "Default options"
Default options are read from the following files in the given order:
/etc/mysql/my.cnf ~/.my.cnf /usr/etc/my.cnf
It means mysql will check those locations for my.cnf file. Simply rename /etc/mysql/my.cnf.fallback as /etc/mysql/my.cnf:
mv /etc/mysql/my.cnf.fallback /etc/mysql/my.cnf

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.

For homebrew mysql installs, where's my.cnf?

For homebrew mysql installs, where's my.cnf? Does it install one?
There is no my.cnf by default. As such, MySQL starts with all of the default settings. If you want to create your own my.cnf to override any defaults, place it at /etc/my.cnf.
Also, you can run mysql --help and look through it for the conf locations listed.
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
The following groups are read: mysql client
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.
--defaults-file=# Only read default options from the given file #.
--defaults-extra-file=# Read this file after the global files are read.
As you can see, there are also some options for bypassing the conf files, or specifying other files to read when you invoke mysql on the command line.
The homebrew mysql contains sample configuration files in the installation's support-files folder.
ls $(brew --prefix mysql)/support-files/my-*
If you need to change the default settings you can use one of these as a starting point.
cp $(brew --prefix mysql)/support-files/my-default.cnf /usr/local/etc/my.cnf
As #rednaw points out, a homebrew install of MySQL will most likely be in /usr/local so the my.cnf file should not be added to the system /etc folder, so I’ve changed the command to copy the file into /usr/local/etc.
If you are using MariaDB rather than MySQL use the following:
cp $(brew --prefix mariadb)/support-files/my-small.cnf /usr/local/etc/my.cnf
One way to find out:
sudo /usr/libexec/locate.updatedb
# wait a few minutes for it to finish
locate my.cnf
in my system it was
nano /usr/local/etc/my.cnf.default
as template and
nano /usr/local/etc/my.cnf
as working.
Nothing really helped me - I could not overwrite settings in a /etc/my.cnf file.
So I searched like John suggested https://stackoverflow.com/a/7974114/717251
sudo /usr/libexec/locate.updatedb
# wait a few minutes for it to finish
locate my.cnf
It found another my.cnf in
/usr/local/Cellar/mysql/5.6.21/my.cnf
changing this file worked for me! Don't forget to restart the launch Agent:
launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
Update:
If you have a fairly recent installation of homebrew you should use the brew services commands to restart mysql (use your installed homebrew mysql version, i.e. mysql or mysql#5.7):
brew services stop mysql
brew services start mysql
Since mysql --help shows a list of files, I find it useful to pipe the result to ls to see which of them exist:
$ mysql --help | grep /my.cnf | xargs ls
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
For my (Homebrew installed) MySQL 5.7, it seems the files is on /usr/local/etc/my.cnf.
Add another answer cause
The accepted anwser is right. Since we're talking about Homebrew installed mysql, not MySQL installed manually, there's more direct way to find the conf.
The former answers may be a little outdated, Homebrew on M1 Mac is stored in a different location
Conf
The my.cnf is copied by Homebrew to following places during installation
/usr/local/etc/my.cnf for x86 Mac
/opt/homebrew/etc/my.cnf for M1 Mac
Homebrew chooses /usr/local, or /opt/homebrew to store packages, so the default conf files are not stored in /etc/ but /usr/local/etc or /opt/homebrew/etc.
In fact, homebrew changed the -DSYSCONFDIR= (default conf location) flag during compiling mysql from source.
Start the Service
A short answer: run brew info mysql and check the tips.
The recommended way is brew services start mysql, which uses the launchd to manage services. (launchd is deemed a systemd alternative on macOS)
For anyone wanna start it manually, mysql.start without any option is enough to start the service. (mysql.start is a script provided by mysql to help start the service)
On your shell type my_print_defaults --help
At the bottom of the result, you should be able to see the file from which the server reads the configurations. It prints something like this:
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
Server version: 8.0.19 Homebrew. macOS Catalina 10.15.5 and installed MySQL via Homebrew. Found this file here:
/usr/local/etc/my.cnf
This solution helped :)
You can find where the my.cnf file has been provided by the specific package, e.g.
brew list mysql # or: mariadb
In addition to verify if that file is read, you can run:
sudo fs_usage | grep my.cnf
which will show you filesystem activity in real-time related to that file.
I believe the answer is no. Installing one in ~/.my.cnf or /usr/local/etc seems to be the preferred solution.
run
sudo find / -name my.cnf
Usually the first result is the correct one.
Should be in
/usr/local/etc/
In case of Homebrew, mysql would also look for my.cnf in it's Cellar directory, for example:
/usr/local/Cellar/mysql/5.7.21/my.cnf
For the case one prefers to keep the config close to the binaries - create my.cnf here if it's missing.
Restart mysql after change:
brew services restart mysql
If you are using mac m1 (Apple silicon), the my.cnf is located at
/opt/homebrew/etc/my.cnf
and can also be found by mysql --help
I have installed MySQL 5.7 using Homebrew
my.cnf file is located in "/opt/homebrew/etc/my.cnf"
For MacOS (High Sierra), MySQL that has been installed with home brew.
Increasing the global variables from mysql environment was not successful. So in that case creating of ~/.my.cnf is the safest option. Adding variables with [mysqld] will include the changes (Note: if you change with [mysql] , the change might not work).
<~/.my.cnf> [mysqld] connect_timeout = 43200 max_allowed_packet =
2048M net_buffer_length = 512M
Restart the mysql server. and check the variables.
y
sql> SELECT ##max_allowed_packet;
+----------------------+ | ##max_allowed_packet |
+----------------------+ | 1073741824 |
+----------------------+
1 row in set (0.00 sec)
$ps aux | grep mysqld
/usr/local/opt/mysql/bin/mysqld --basedir=/usr/local/opt/mysql --datadir=/usr/local/var/mysql --plugin-dir=/usr/local/opt/mysql/lib/plugin
Drop your my.cf file to /usr/local/opt/mysql
brew services restart mysql

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