MariaDB - my.cnf isn't in my server CentOs - mysql

I have been working with MariaDB and i don't know why there is no my.cnf. But the crazy thing is that:
Where it is suposed that the file should be, there is only the my.cnf.d, but the .cnf isn't.
If i write a new file called my.cnf and i copy from another server, it works.
I want to know why happen this?
PD: This is my instalation via yum:
sudo yum install MariaDB-server MariaDB-client
sudo systemctl start mariadb
mysql_secure_installation

Depending on the specific version there may be no my.cnf file. See MariaDB KB
MariaDB will use compiled defaults if there is no my.cnf to override them. You can use my.cnf.d as a starting point for that.

Related

How to install and start MySQL 5.7 on macOS BigSur (Apple Silicon) with Homebrew?

I need a specific version of MySQL (5.7) to be installed on my MacBook with M1.
I'm trying to do that with Homebrew.
brew install mysql#5.7
The output:
We've installed your MySQL database without a root password. To secure it run:
mysql_secure_installation
MySQL is configured to only allow connections from localhost by default
To connect run:
mysql -uroot
mysql#5.7 is keg-only, which means it was not symlinked into /opt/homebrew, because this is an alternate version of another formula.
If you need to have mysql#5.7 first in your PATH, run: echo 'export PATH="/opt/homebrew/opt/mysql#5.7/bin:$PATH"' >> ~/.zshrc
For compilers to find mysql#5.7 you may need to set: export LDFLAGS="-L/opt/homebrew/opt/mysql#5.7/lib" export CPPFLAGS="-I/opt/homebrew/opt/mysql#5.7/include"
To have launchd start mysql#5.7 now and restart at login: brew services start mysql#5.7 Or, if you don't want/need a background service you can just run: /opt/homebrew/opt/mysql#5.7/bin/mysql.server start
Right after that, I try to run:
echo 'export PATH="/opt/homebrew/opt/mysql#5.7/bin:$PATH"' >> ~/.zshrc
source .zshrc
mysql_secure_installation
And get the error:
Securing the MySQL server deployment.
Enter password for user root:
Error: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
Also, I've tried:
brew services start mysql#5.7
And also get the error:
Error: Permission denied # rb_sysopen - /Users/vivanc/Library/LaunchAgents/homebrew.mxcl.mysql#5.7.plist
Seems like there is a permissions-related problem.
Any advice is appreciated.
If you are running into issues like "Can't connect to local MySQL server through socket '/tmp/mysql.sock'" or "The post-install step did not complete successfully MySQL", and you installed a previous version of mysql (e.g. 8.x) previously, you may have been at the point where you need to clean everything before reinstalling your preferred version of mysql#x.x.
If you've already visited these to links:
Uninstall all those broken versions of MySQL and re-install it with Brew on Mac Mavericks (Coderwall) + Install MySQL 5.7 on macOS using Homebrew (github) and your're still having trouble with starting your mysql-service, you should try to also remove also /opt/homebrew/etc/my.cnf file.
Remove it together with all the related files too! Summary for an M1 Apple Silcion machine, after uninstalling via brew uninstall mysql or brew uninstall mysql#x.x, please remove:
/opt/homebrew/var/mysql
/opt/homebrew/etc/my.cnf
After this, everything worked like a fresh install (for me). Hope this saved someone's time.
While this question is specific to Apple Silicon and mysql 5.7, and I will address that in this answer, I would like to start by adding some general notes to save others time:
Homebrew supports mysql 5.7 for both intel and apple silicon.
https://formulae.brew.sh/formula/mysql#5.7
Homebrew supports mysql 5.6 for the intel chip, but not apple silicon:
https://formulae.brew.sh/formula/mysql#5.6
If you need 5.6 on apple silicon, it's probably a good idea to just settle with 5.7 since production will need to be upgraded eventually and the differences aren't that big.
In my situation I originally did brew install mysql and it gave me the latest mysql (currently 8.0). When I tried going back over it and doing brew install mysql#5.6, of course this didn't work due to not being supported on the m1 max (apple silicon). I ran into issues then trying to get brew install mysql#5.7 working. I followed some guides mentioning various suggestions. After playing with it for a while, it seems that running two versions of mysql at once will corrupt your mysql files and make it hard to work with and confuse homebrew.
I came across these guides:
brew install mysql on macOS
https://coderwall.com/p/os6woq/uninstall-all-those-broken-versions-of-mysql-and-re-install-it-with-brew-on-mac-mavericks
https://www.codegrepper.com/code-examples/shell/brew+uninstall+mysql
Before reading further, note that in my situation, I had a zip available for my whole local mysql database needs and could risk destroying what I have.
Warning! Reading further and executing these commands carelessly may delete your mysql storage. Make sure you have a backup.
brew remove mysql is a good command that got rid of my latest install.
I also needed brew remove mysql#5.7 even though this is the version I'm trying to install, but they were stepping on each other's foot...
brew cleanup is nice, I noticed it freed up some lock files.
I don't recall having any luck with:
launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
but you can try it.
rm ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist has worked for me.
But note there will also be another file in there for your 5.7 setup.
I'd recommend:
cd ~/Library/LaunchAgents/ then look around to see if you have any mysql* in there. Then if you do, such as homebrew.mxcl.mysql#5.7.plist, then remove it.
These are some that worked for me:
sudo rm -rf /usr/local/var/mysql
rm /usr/local/etc/my.cnf
rm /usr/local/etc/my.cnf.default
Also:
cd opt/homebrew/var
Then if you notice a mysql directory in there, remove it.
It's possible you might have docker or something else similar also running mysql or mysqld.
ps -ax | grep "[m]ysql"
(Note the brackets and quotes in the above is to prevent the grep from showing up in the process list and matching itself unlike the lazier version: ps -ax | grep mysql which will give the impression there's an extra mysql process running)
Once you're ready, please run:
brew services list
double-check you don't have mysql in there.
Then double check you don't have any mysql process running:
ps -ax | grep "[m]ysql"
This can happen for example if you enter mysqld for example....
You might need to do brew services stop mysql or brew services stop mysql#5.7 or similar and repeat steps if you see anything on the service list or process list.
Finally, you should be ready for a fresh install.
The fresh installation process should be rather straight forward:
brew install mysql#5.7
brew link --force mysql#5.7
brew services start mysql#5.7
Then run brew services list to make sure your installation worked correctly.
If you see it's green and "started", your installation was successful!
You should also run:
mysql_secure_installation
Then choose a password for root and go through the list of questions like validation, etc.
Once you're installed, you might also run into mysql mode issues.
cd /opt/homebrew/etc and you should find a my.cnf file.
Edit it using either vim or nano.
You should see something like:
# Default Homebrew MySQL server config
[mysqld]
# Only allow connections from localhost
bind-address = 127.0.0.1
Edit it and set the mysql mode. For example, I don't want the no_zero_in_date mode, so I use:
# Default Homebrew MySQL server config
[mysqld]
# Only allow connections from localhost
bind-address = 127.0.0.1
sql-mode="ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
Then restart mysql like so:
brew services restart mysql#5.7
Then double check you still have a green status "started":
brew services list
If you do, then you should have the no_zero_in_date mode disabled.
You can test it with a query:
SELECT ##sql_mode;
You should now have mysql 5.7 running on Apple Silicon and have the sql_mode set.
If you run into more troubleshooting, do your best to get into a known state such as uninstalled, doing a fresh install, or already installed with some version, etc.
I solved it after hours of searching, it was because I had not cleaned everything regarding my previous MySQL 8.X installation. I followed this and got suspicious when I realized I don't have most of the folders there. I then did a search for all folders named mysql on my computer and found a mysql folder in opt/homebrew/var. After removing it, reinstalling MySQL 5.7, and starting the server everything is working as expected.
When setting up my Apple M1 Macbook Pro I was experiencing the issue of the following error message being thrown:
Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
My fix was to modify the MySQL config file:
nano /usr/local/etc/my.cnf
Append the following lines:
tmpdir=/tmp
user=root
Then run:
brew services restart mysql#5.7
This fixed my issue, and I was then able to connect successfully with my DB client.
Seems like I found the solution (or workaround).
After installing the MySQL 5.7 with Homebrew just run:
mysql.server start
MySQL is started and then you are able to run mysql_secure_installation and mysql commands.
I got this warning:
You should change the ownership of these directories to your user.
sudo chown -R $(whoami) /usr/local/share/doc /usr/local/share/man /usr/local/share/man/man1
And make sure that your user has write permission.
chmod u+w /usr/local/share/doc /usr/local/share/man /usr/local/share/man/man1
I run those two command then it works.

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.

mysql.sock does not exist error in fresh install of MySQL on Arch Linux

I'm trying to use MySQL on Arch Linux. it is already installed but this error comes up when I try to connect:
connect to server at 'localhost' failed
error: 'Can't connect to local MySQL server through socket '/run/mysqld/mysqld.sock' (2 "No such file or directory")'
I've looked for /etc/my.cfg but the file does not exist.
Something must have gone wrong during the installation.
How can I "purge" MariaDB and reinstall it?
If you're using archlinux it is a vital idea to understand the package manager (pacman). For the question about /etc/my.cfg you can run
pacman -Ql mariadb
there you will see that the file is actually called:
/etc/mysql/my.cnf
Arch linux will not configure the package for you, that is part of the arch philosophy. It will provide example configurations, and even provide you with a systemd unit file
usr/lib/systemd/system/mysqld.service
but it is your responsibility to ensure that the configuration is correct and actually start the daemon.
systemctl enable mysqld # add the unit file to the boot sequence
systemctl start mysqld # runs ExecStart= in the unit file
systemctl stop mysqld # kills the daemon
systemctl disable mysqld # remove unit from boot sequence
reinstall
Since the word reinstall is in the title of the question and someone might find this question thanks to that: To reinstall mariadb you simply do
pacman -S mariadb
pacman will reinstall a package that is already installed, there is no need to remove the package (for completeness, package removal happens with pacman -R)
as of 7-28-17 I had to do this on a new install. Newbie here might save someone some time. It was a real pain.
OK HERE IS THE DEAL!!!!!
INSTALL APACHE _ NO PROB
INSTALL MYSQL _PROBLEM
pacman -S mysql then before starting service
MUST UNCOMMENT INNODB IN:
nano /etc/mysql/my.cnf
then must initialize datadirectory before starting service:
mysql_install_db --user=mysql --basedir=/usr --datadir=/var/lib/mysql
You need to initialize the MariaDB data directory prior to starting
the service. This can be done with mysql_install_db command, e.g.:
mysql_install_db --user=mysql --basedir=/usr --datadir=/var/lib/mysql
Optional dependencies for mariadb
galera: for MariaDB cluster with Galera WSREP
perl-dbd-mysql: for mysqlhotcopy, mysql_convert_table_format and
mysql_setpermission
CNF file is /etc/mysql/my.cnf in Arch Linux.
One simple way I can reproduce your issue is when MariaDB is shut down. Sorry if it sounds dumb but as you did not mention it: is MariaDB started? sudo systemctl start mysqld.service
You should have a look at MariaDB logs to get some clue: journalctl _SYSTEMD_UNIT=mysqld.service (maybe paste some part if you still don't get what is going on).
This happens the first time you install MySQL and MariaDB. As grochmal pointed out, you have to set up configurations before first use. But, the user teckk sent these three links in the archlinux newbie corner:
https://wiki.archlinux.org/index.php/MariaDB
https://wiki.archlinux.org/index.php/MariaDB#Reset_the_root_password
https://bbs.archlinux.org/viewtopic.php?id=51981
In short, you have to run the command below before starting the service:
sudo mariadb-install-db --user=mysql --basedir=/usr --datadir=/var/lib/mysql
Optionally (recommended) you should improve the initial security by calling:
sudo mysql_secure_installation
Now you can start the service:
sudo systemctl start mariadb
Optionally, you could install and use a graphical front-end tool.
Carry on with setting up the configurations as described in the archwiki post on MariaDB Configuration.

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

Change port # for mysql on mac

I just installed mysql on a mac running 10.6. The mysql version is 5.1.56. I need to have mysql run on port 3307. This article says we can change the port by modifying this file:
# vi /etc/my.cnf
http://www.cyberciti.biz/faq/change-default-mysql-port-under-linuxunix/
but there is no such file in /etc. I can see mysql is running ok because I can connect to it just fine, is the way we change the port # different now?
Thanks
Looks like the new installers are adding the port as 3307
To change that follow below steps
sudo vi /Library/LaunchDaemons/com.oracle.oss.mysql.mysqld.plist
change 3307 from this line <string>--port=3307</string> to 3306
On OSX you can create /etc/my.cnf if it does not exist. You can base it on samples found in /usr/local/mysql/support-files. Don't forget to restart MySQL for your my.cnf to take effect.
On MacOs High Sierra running MySql v8 server, you need the following:
Edit /Library/LaunchDaemons/com.oracle.oss.mysql.mysqld.plist
Under ProgramArguments, you will see many entries with
<string>...</string> etc,
Add the following line: <string>--port=16000</string>
Also, to restart you need to do the following:
launchctl unload -F /Library/LaunchDaemons/com.oracle.oss.mysql.mysqld.plist
and then
launchctl load -F /Library/LaunchDaemons/com.oracle.oss.mysql.mysqld.plist
I hope this helps.
By default, the install doesn't create a my.cnf file on Snow Leopard. You can create one yourself under /etc or you can copy one from /usr/local/mysql/support-files/
Then run :
sudo cp my-huge.cnf /etc/my.cnf
Check out the explanation here
I experienced a similar problem and here's what worked for me. If you installed MySQL using brew install mysql then this should work for you.
For context, I'm using macOS Monterey 12, Homebrew 3.4.5, and MySQL 8.0.
MySQL is installed in:
/opt/homebrew/Cellar/mysql/8.0.28_1/
The configuration file my.cnf is located at /opt/homebrew/etc.
You can change the default port by specifying a new port in the my.cnf file.
First navigate to the homebrew etc folder
cd /opt/homebrew/etc
Append the new port value to the my.cnf file
echo "port = 3307" >> my.cnf
restart the MySQL service
brew services restart mysql
I tried a long time to get mysql running on my Mac (OSX 10.11.13) with mysql 5.7.11 to develop wordpress sites on my local machine...
When I used the app duplicator to migrate a website to my local machine I got errors during the database import. This was caused by to stricked sql_mode...
The trick that made it was:
Going to
/usr/local/mysql-5.7.11/support-files/
and copy the content from my-default.cnf
and paste it to
/etc/my.cnf (if this file does not exist create it!)
at the very last line of my.cnf I added:
sql_mode="NO_ENGINE_SUBSTITUTION"
Et voilà: sql_mode is changed permanently!
Whoop whoop!
I installed docker and was having problems with my company wanting to use port 3306 (which is what I was using privately).
Similar problem to you. So this is what I did to fix it.
sudo vi /Library/LaunchDaemons/com.oracle.oss.mysql.mysqld.plist
Then you get a long list of script tags and
Insert <string>--port=3307</string> into the array. Make sure you put it under the other strings and within the array.
I changed my port to 3307 instead of 3306 and now docker is working.