init.d/mysql - Default configuration is blocking one of my instances on startup - mysql

I am having a bit of an issue that popped up over the past weekend.
One of my servers was rebooted and when the server came it started a default instance of mysql that is configured upon installation. It uses port 3306 as a default and blocks one of my instances from coming up.
How can I remove this default instance from booting and instead boot my instances in /etc/my.cnf ?
I think what is happening is it is going to /var/lib/mysql and starting an instance based off some default configuration as there is not a my.cnf file located here, but I find this code in init.d:
#Set some defaults
mysqld_pid_file_path=
if test -z "$basedir"
then
basedir=/usr
bindir=/usr/bin
if test -z "$datadir"
then
datadir=/var/lib/mysql
fi
But I don't see any my.cnf file at that location that it could be pulling configuration options from.
My data directories change per instance and they are all specified in /etc/my.cnf
I appreciate any effort spent helping with this issue.

Try this:
$ my_print_defaults --defaults-file=/etc/my.cnf mysqld
This will show you what it thinks datadir is set to, according to your config file.
I've seen config files get confused as people edit them, or even automated tools may edit the config file and append new config entries. Keep in mind if the config file has more than one line defining datadir, the last such line in the file takes precedence.
If you have an instance of mysqld starting up automatically at boot time, I'd use chkconfig to find out when that's happening. For example, here's a command run on my VM:
$ chkconfig
...
mysql 0:off 1:off 2:on 3:on 4:on 5:on 6:off
...
The numbers 0 through 6 are runlevels, and "on" means that when the given runlevel starts, the /etc/init.d/mysql service script is run by init.
You can also use chkconfig to modify which runlevels a given service starts under, and even to disable the service at all runlevels, so that it won't start automatically ever.
$ chkconfig --level 2345 mysql off
Refer to man chkconfig for more uses.

Related

Missing mysql on /etc/init.d/ directory

I've been trying to install mysql using WSL and I've followed the steps indicated in this guide https://learn.microsoft.com/en-us/windows/wsl/tutorials/wsl-database. I tried running mysql --version and it worked (prompted mysql Ver 8.0.23 for Linux on x86_64 (MySQL Community Server - GPL)). But as I try the next command sudo /etc/init.d/mysql start, it says sudo: /etc/init.d/mysql: command not found. I've also tried checking the contents of /etc/init.d/ directory and there is no existing mysql file/folder there. What should I do next to proceed with my mysql installation?
Thanks!
There is a great blog post on this problem, with explanations of the issue and detailed solutions.
https://www.58bits.com/blog/2020/05/03/installing-mysql-80-under-wsl-2-and-ubuntu
From the post:
One solution is to download the mysql.server.sh script from here -
https://github.com/mysql/mysql-server/tree/8.0/support-files - and
then copy and rename the script to /etc/init.d/mysql (make sure that
it's also executable - chmod +x mysql)
You'll then need to set the default values for basdir, datadir and pid
file locations.
Here's an excerpt with the top portion of the file and the settings
that worked for me...
# If you change base dir, you must also change datadir. These may get
# overwritten by settings in the MySQL configuration files.
basedir=/usr
datadir=/var/lib/mysql
# Default value, in seconds, afterwhich the script should timeout waiting
# for server start.
# Value here is overriden by value in my.cnf.
# 0 means don't wait at all
# Negative numbers mean to wait indefinitely
service_startup_timeout=900
# Lock directory for RedHat / SuSE.
lockdir='/var/lock/subsys'
lock_file_path="$lockdir/mysql"
# The following variables are only set for letting mysql.server find things.
# Set some defaults
mysqld_pid_file_path=/var/run/mysqld/mysqld.pid
if test -z "$basedir"
After this you should be able to start and stop MySQL as follows:
sudo service mysql start
sudo service mysql stop
As he mentions later, you also need to create /var/run/mysqld/ and set permissions:
sudo mkdir /var/run/mysqld
sudo chown mysql:mysql /var/run/mysqld

MariaDB configuration changes don't take effect

The server is working on CentOS 8, I'm trying to configure MariaDB by making alterations to /etc/my.cnf but then when I restart DB by doing sudo systemctl restart mariadb, the server does restart but no configuration changes get applied.
mysql > SHOW VARIABLES;
It outputs the same values. I tried to comment out the including directive #!includedir /etc/my.cnf.d and to add settings to [mysqld] and [mariadb] sections.
mysql --verbose --help says:
Default options are read from the following files in the given order:
/etc/my.cnf ~/.my.cnf.
The following groups are read: mysql client client-server client-mariadb
Check whether mysql uses the config file debugging it with strace:
sudo strace mysql
In the strace output, look for lines like:
openat(AT_FDCWD, "/etc/my.cnf", O_RDONLY|O_CLOEXEC) = ...
Make sure openat doesn't return -1. In that case check whether the file exists or mysql has enough permissions to read the file.
When adding additional configuration files, make sure that they are not writable by 'other'. Otherwise you'll have a message on mysql startup like:
Warning: World-writable config file '/etc/mysql/conf.d/myproject.cnf' is ignored
and the configuration does not get applied.

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 Not Working [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
I have an amazon ec2 instance running on the Amazon Linux AMI and its a micro instance. I wanted to install Django onto my server so I entered these commands
wget http://www.mlsite.net/blog/wp-content/uploads/2008/11/go
wget http://www.mlsite.net/blog/wp-content/uploads/2008/11/django.conf
chmod 744 go
./go
So after I was done, I ran sudo service httpd restart and sudo service mysqld restart
and This is what came up for mysqld:
Stopping mysqld: [ OK ]
MySQL Daemon failed to start.
Starting mysqld: [FAILED]
So I deleted the django files /usr/local/python2.6.8/site-packages/django_registration.egg
and I tried finding the error and I found out that in my
/etc/my.cnf for the socket, it said
[mysqld]
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under different user or group,
# customize your systemd unit file for mysqld according to the
# instructions in http://fedoraproject.org/wiki/Systemd
datadir=/mnt/ebs/mysql
socket=/var/lib/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
[mysqld]
default-storage-engine=INNODB
[mysqld]
default-storage-engine=INNODB
[mysqld]
default-storage-engine=INNODB
[mysqld]
default-storage-engine=INNODB
so I went to /var/lock/subsys/ and there was no mysql.sock. I tried creating one using vim but it still didn't work. Then I checked the error log and it said
120712 20:33:11 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended
120712 20:33:15 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
UPDATE:
I entered these commands:
cd /var/lib/mysql/
touch mysql.sock
chmod +x mysql.sock
chown mysql:mysql -R *
And it still didn't work...
So I am pretty much lost right now. I know it has something to do with mysql.sock
If you might know a reason why this was caused could you please let me know? I have a wordpress site on my server, so i kind of need MySQL to work. Thanks!
Inspecting the go script you downloaded and executed, I found the following lines:
# Change the MySQL data directory
sed -e 's!/var/lib/mysql$!/mnt/ebs/mysql!' -i /etc/my.cnf
This effectively changes your mysql data directory (datadir setting), so you can't access any previously created database (like the wordpress database).
As a wild guess, I would think that the mysqld can't access /mnt/ebs/mysql and therefore doesn't start. Try to change it back to /var/lib/mysql. However, this might interfere with your django. If you get the django configured mysql to run, you can always add a second my.cnf with another name and other tcp port and run two MySQL servers with different configurations.
The socket error message is about the MySQL server not running. Do not try to emulate the socket by putting a file in its way.
The go script also makes some more changes to my.cnf that could be a problem. Have a look at the go file yourself and try to undo the changes made.
If nothing of the above helps, you can try to start the mysqld process from command line by hand, using the same arguments as the service script does, plus an added --verbose and post its output.
Ok, I figured it out thanks to #escitalopram so I will accept his answer! Ok, django changed my MySQL data directory from /var/lib/mysql to /mnt/ebs/mysql in my /etc/my.cnf, so in my /etc/my.cnf, it said
datadir=/mnt/ebs/mysql and I changed it to datadir=/var/lib/mysql. And everything worked fine. I restarted MySQL hoping for the red [FAILED] message but I got an [OK]. Also, my socket was messed up in /etc/my.cnf but I had already fixed that!

Run multiple MySQL server on a single machine

Can we run multiple MySQL servers on a single machine?
Thanks.
Yes, you just need to run them on separate ports and point them at different lib directories for their data.
Here's a good reference: http://dev.mysql.com/doc/refman/5.1/en/mutiple-servers.html
(If you want to use this for testing, I suggest checking out MySQL Sandbox which is now replaced by dbdeployer)
There are various methods to run multiple instances of mysql (on different ports) on the same machine. Here I have used the same binary and used a separate configuration file (with separate port, pid, socket and data directory).
We need to create new directories for our datadir and log folder (if used). Also we need to assign proper permissions on those folders:
# mkdir /var/lib/mysql2
# chown -R mysql.mysql /var/lib/mysql2/
# mkdir /var/log/mysql2
# chown -R mysql.mysql /var/log/mysql2
Next we need a separate configuration file same as a default mysql configuration file. So start by copying the existing one and changing the needed values.
# cp /etc/my.cnf /etc/my2.cnf
(or change the path appropriately for your configuration file is in a different place).
Next, we need to edit our new configuration file with different mysql port (default to 3306), the pid and socket than the default ones, and also point the data and log folders to the ones created before.
# cd /etc
# sed -i ‘s/3306/3307/g’ my2.cnf
# sed -i ‘s/mysqld.sock/mysqld2.sock/g’ my2.cnf
# sed -i ‘s/mysqld.pid/mysqld2.pid/g’ my2.cnf
# sed -i ‘s/var\/lib\/mysql/var\/lib\/mysql2/g’ my2.cnf
# sed -i ‘s/var\/log\/mysql/var\/log\/mysql2/g’ my2.cnf
Finally we need to initialize the default dbs:
# mysql_install_db –user=mysql –datadir=/var/lib/mysql2/
Finally we can start our new mysql instance with:
# mysqld_safe – -defaults-file=/etc/my2.cnf &
We can connect to our new instance using:
# mysql -S /var/run/mysqld/mysqld2.sock
or
# mysql -h 127.0.0.1 -P 3307
and if we no longer need it, stop it with:
# mysqladmin -S /var/run/mysqld/mysqld2.sock shutdown
Ref Site : https://linuxinpakistan.com/start-multiple-instances-mysql-machine
My steps on Windows 10:
Copy C:\ProgramData\MySQL\MySQL Server 8.0\my.ini to C:\ProgramData\MySQL\MySQL Server 8.0\my1.ini
Open my1.ini and modify:
port=3307(under Client and Server Section)
datadir=C:/ProgramData/MySQL/MySQL Server 8.0/Data1
report_port=3307
Copy C:\ProgramData\MySQL\MySQL Server 8.0\Data to C:\ProgramData\MySQL\MySQL Server 8.0\Data1
Run on cmd prompt: (With Administrator privileges if necessary)
C:\Program Files\MySQL\MySQL Server 8.0\bin>mysqld --install MySQL80-1 --defaults-file="C:\ProgramData\MySQL\MySQL Server 8.0\my1.ini"
If all went well, you will see:
Service successfully installed.
Win+R
Type services.msc, find the service name MySQL80-1, right-click on it and click Start.
If all went well, you will see the Status change to Running.
If it did not go well, open xxx.err file found in C:\ProgramData\MySQL\MySQL Server 8.0\Data1 to check why.
If you do not want the service anymore:
Stop it
Delete it on the cmd prompt using sc delete MySQL80-1 where MySQL80-1 is your service name.
For Windows, if the version of mysql server is different then using MYSQL Installer download and install the different versions of the MYSQL server.
Select Reconfigure for each MYSQL server and configure the PORT differently. Complete the configuration steps by clicking next until it is finished
Yes definitely,
Create multiple configuration files with different ports.
This is the best resource to understand:
Video Tutorial: MySQL Multiple Instances
Reference article: Click here