mysql process cannot be stopped - mysql

I have recently installed 5.5.28-29.2 Percona Server (GPL), Release 29.2 in a Ubuntu 12.04 OS Desktop. I have tried to stop the server using different methods:
- sudo /etc/init.d/mysql stop
- sudo kill -9 pid
- mysqladmin -u root -p shutdown
All this methods stop the process, however it starts up automatically after it dies. I have checked syslog (/var/log/syslog/) and always shows me the next trace:
Jan 4 17:50:44 kernel: [ 1915.494219] init: mysql main process (17311) killed by KILL signal
Jan 4 17:50:44 kernel: [ 1915.494245] init: mysql main process ended, respawning
Jan 4 17:50:44 kernel: [ 1915.500025] type=1400 audit(1357318244.557:48): apparmor="STATUS" operation="profile_replace" name="/usr/sbin/mysqld" pid=18458 comm="apparmor_parser"
Jan 4 17:50:46 /etc/mysql/debian-start[18501]: Upgrading MySQL tables if necessary.
Jan 4 17:50:46 /etc/mysql/debian-start[18504]: /usr/bin/mysql_upgrade: the '--basedir' option is always ignored
Jan 4 17:50:46 /etc/mysql/debian-start[18504]: Looking for 'mysql' as: /usr/bin/mysql
Jan 4 17:50:46 /etc/mysql/debian-start[18504]: Looking for 'mysqlcheck' as: /usr/bin/mysqlcheck
Jan 4 17:50:46 /etc/mysql/debian-start[18504]: This installation of MySQL is already upgraded to 5.5.28, use --force if you still need to run mysql_upgrade
Jan 4 17:50:46 /etc/mysql/debian-start[18515]: Checking for insecure root accounts.
Jan 4 17:50:46 /etc/mysql/debian-start[18520]: Triggering myisam-recover for all MyISAM tables
Do you know the reason why the process restarts automatically ?
Thank you in advance!!

I was having this exact same problem. Running the kill command would kill the process, but in my case it would keep popping up again under a different process ID.
The only way I could figure out how to stop it for good was this:
sudo stop mysql
Source: http://www.itfromscratch.com/how-to-stop-the-percona-mysql-server/

Using sudo service mysql stop worked for me.

Want to kill all mysql instances? Try as root:
pkill mysqld;

I'm using Homebrew on Mac OS. brew services stop mysql did not work for me, but sudo brew services stop mysql did.

I'm going to guess here, but mysqld might be started via the mysql_safe init script, which will restart the server.

For those looking at this years after the fact, I had a similar issue and just solved it.
Seems there was a second init script called orig_mysql.conf that existed in the /etc/init directory along with the mysql.conf file. This caused upstart to start two instances and apparently it got confused when one was ended. As such a continuous respawning took place.
My solution:
Stop mysql via upstart if possible: service mysql stop
REMOVE one of the conf files (I removed /etc/init/orig_mysql.conf). Then restart init using: telinit u
Kill off any remaining mysqld processes manually.
Once you confirm you have no mysqld processes running and that they are not respawning any longer, restart mysql with service mysql start.
Hope this helps someone. It took me two years to solve this.

This might not apply to this particular problem but here it goes anyways. I checked the error log ("/var/log/mysql/error.log") and saw that "explicit_defaults_for_timestamp=TRUE" was causing an error ("Unknown variable"). So I removed it from my.cnf ("/etc/mysql/my.cnf"), and ran "sudo start mysql" and it was back up and running. I hope this helps as well!

Related

Trouble Installing MySQL 8.0 on centos 6

I followed this tutorial to install MySQL 8.0 on my centos 6 Virtual server.
Tutorial
However when I get to the step where Im supposed to start the service (service mysqld start)
I get the following error:
Initializing MySQL database: [ OK ]
/usr/bin/mysqld_safe: line 199: 1632 Killed env MYSQLD_PARENT_ PID=1450 nohup /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin -dir=/usr/lib/mysql/plugin --user=mysql --log-error=/var/log/mysqld.log --pid-fi le=/var/run/mysqld/mysqld.pid --socket=/var/lib/mysql/mysql.sock < /dev/null > / dev/null 2>&1
MySQL Daemon failed to start.
Starting mysqld: [FAILED]
I tried serveral times and always get an error, does anyone know how to fix this?
I ran into this problem, and after inspecting journalctl -xe, I saw that it was due to an out-of-memory error. I solved this by upgrading from a 512MB RAM to a 1GB RAM for my virtual machine

MySQL doesn't start at all

This is awsome yesterday I got the same error and I debugged it but today I don't remember what to do since I did it to fast.
When I'm doing:
service mysql start
I get this message:
Job for mysql.service failed. See 'systemctl status mysql.service' and 'journalctl -xn' for details.
For this reason I did:
systemctl status mysql.service
and get:
Apr 16 18:11:25 darphus.xen.prgmr.com systemd[1]: Unit mysql.service entered failed state.
Apr 16 18:11:26 darphus.xen.prgmr.com systemd[1]: mysql.service holdoff time over, scheduling restart.
Apr 16 18:11:26 darphus.xen.prgmr.com systemd[1]: Stopping MySQL Community Server...
Apr 16 18:11:26 darphus.xen.prgmr.com systemd[1]: Starting MySQL Community Server...
Apr 16 18:11:26 darphus.xen.prgmr.com systemd[1]: mysql.service start request repeated too quickly, refusing to start.
Apr 16 18:11:26 darphus.xen.prgmr.com systemd[1]: Failed to start MySQL Community Server.
Apr 16 18:11:26 darphus.xen.prgmr.com systemd[1]: Unit mysql.service entered fai
journalctl -xn give:
Logs begin at Sun 2017-04-16 17:58:44 UTC, end at Sun 2017-04-16 18:16:35 UTC
Apr 16 18:16:34 darphus.xen.prgmr.com postfix/pickup[938]: warning: 868F625E66:
Apr 16 18:16:34 darphus.xen.prgmr.com postfix/pickup[938]: 868F625E66: uid=0 fro
Apr 16 18:16:34 darphus.xen.prgmr.com postfix/proxymap[941]: warning: mysql:/etc
Apr 16 18:16:34 darphus.xen.prgmr.com postfix/cleanup[1361]: warning: proxy:mysq
Apr 16 18:16:34 darphus.xen.prgmr.com postfix/cleanup[1361]: warning: 868F625E66
Apr 16 18:16:35 darphus.xen.prgmr.com postfix/pickup[938]: warning: 8744E25E66:
Apr 16 18:16:35 darphus.xen.prgmr.com postfix/pickup[938]: 8744E25E66: uid=0 fro
Apr 16 18:16:35 darphus.xen.prgmr.com postfix/proxymap[941]: warning: mysql:/etc
Apr 16 18:16:35 darphus.xen.prgmr.com postfix/cleanup[1362]: warning: proxy:mysq
Apr 16 18:16:35 darphus.xen.prgmr.com postfix/cleanup[1362]: warning: 8744E25E66
I think a tryed all the trick on the internet and nothing work for today.
Please help me since All my website are down for this reason.
The answer by #Lotfio Lakehal will fix your issues but should be considered a last resort - you certainly wouldn't want to run this on a database that had data you require as it will remove all your configuration values in the process. A better way would be to find out what is causing the issue in your my.cnf and fix it. MySQL has this ability built in.
mysqld --help --verbose
The above command will simulate starting your mysql server. If it can't it will give an error message and a description of what is wrong with the config files.
For instance I set up a test config file with some invalid data and when I ran the above command I got the following:
error: Found option without preceding group in config file: /etc/mysql/my.cnf at line: 22
This allows me to easily go to the configuration file and remove or edit the offending configuration, hopefully, allowing you to fix the said config file without having to do a full reinstall of the server.
Just to clarify this is in no way a put down on this answer, the previous answer will fix 99% of all issues but should be considered a last resort. Ideally, you want to fix the issue and understand why it occurred so you don't make the same mistakes in the future.
Usually this problem appears when you try to change something in the /etc/mysql/my.cnf.
WARNING
The following solution will delete all your database data! Try other solutions first.
Reinstalling MySQL may solve the problem, but should only be used as a last resort! To reinstall:
sudo apt purge mysql-server mysql-common
sudo apt autoremove mysql-server mysql-common
and reinstall it again
sudo apt-get update
sudo apt-get install mysql-server
check this out:
https://askubuntu.com/questions/392438/mysql-job-failed-to-start
note : This solution will delete all your database data ! So be aware of what you are doing .
I had the same problem running on ubuntu 18.04 with mysql 5.7. The first thing that I did was to go to mysql error log, it should be in /var/log/mysql/error.log.
There I found the following line:
[ERROR] InnoDB: Cannot allocate memory for the buffer pool
So looked like a memory issue, I checked the syslog for mentions of MySQL:
grep mysql syslog
Which displayed this:
kernel: [21270406.665399] Out of memory: Kill process 9674 (mysqld) score 251 or sacrifice child
I checked that I had ‘spare memory’ in the form of swap.
free -m
Which displayed this:
total used free shared buff/cache available
Mem: 985 522 69 45 393 276
Swap: 0 0 0
This meant that we have to setup swap space:
Swap: 0 0 0
In my case, mysql is on DigitalOcean and their guides are great so I defer you to the following:
How To Add Swap Space on Ubuntu 18.04
This answer should be read in conjunction with #"James Lendrem" answer.
If you changed or added anything to the mysql configuration files, try removing what you did.
First check the syslog file, which may give you a clue:
grep mysql /var/log/syslog | grep ERROR
This command searches the syslog for any reference to the term "mysql", and then limit those results to ones containing "ERROR".
Next look in the various config files. If you edited a specific config file, start there. Otherwise, look in all the config files in these directories:
ls -l /etc/mysql/*.cfg
ls -l /etc/mysql/mysql.conf.d/
ls -l /etc/mysql/conf.d/
If you change anything in any of the config files, (re)start the mysql server:
service mysql restart
# or else you could use for the first time:
service mysql start
I had the same problem running on ubuntu 18.04 with mysql 5.7
In log files I found the following lines:
Jul 13 01:25:35 r-lap audit[11196]: AVC apparmor="DENIED" operation="open" profile="/usr/sbin/mysqld" name="/sys/devices/system/node/" pid=11196 comm="mysqld" req
Jul 13 01:25:35 r-lap kernel: audit: type=1400 audit(1531425335.671:116): apparmor="DENIED" operation="open" profile="/usr/sbin/mysqld" name="/sys/devices/system/
On stopping apparmor, mysql start was successful with a message that ssl support could not be enabled. Stop the service.
To generate the certs,
Run
sudo mysql_ssl_rsa_setup --datadir /var/lib/mysql
The datadir may be different in your case.
Then do
sudo -i
cd /var/lib/mysql
chown mysql:mysql ./*
This will set the permissions for the generated cert and key files right.
Next you can start both apparmor and then mysql.
This fixed the issue in my case.
Since I did not try separately, I don't know whether it's the apparmor restart or generating the ssl key and certs that fixed the issue.
Note: I later found out this thread
For me, I ran some cache clearing operations to free up space using tools like Stacer, and then MySQL started showing problems.
Use this to get some clues first
grep mysql /var/log/syslog | grep ERROR
If the error says, Could not open file '/var/log/mysql/error.log' for error logging: No such file or directory
then clearly, the log files were cleaned up.
Use this to first create the MySQL directory and grant all permissions for MySQL to use that folder.
> sudo mkdir /var/log/mysql
> sudo chown -R mysql:mysql /var/log/mysql
> sudo service mysql restart
This solution has nothing to do with the my.cnf files and is completely safe on data.
Try running journalctl -u mysql.service to figure out why the error is happening.
Also, systemd cat mysql.service will show you the Service Unit file that describes your service - there might be errors.

Not To Start MySql Automatically at Centos Startup

i have "CentOS 6" VPS and i wanted to start mysql service automatically at Startup of Server when it is restarted. so i used this command in putty
chkconfig --level 345 mysqld on
this command is working and mysql starts on every startup automatically.
BUT how can i now stop this? what if i want to start Mysql manually on every startup, then what command should i use?
also what is the File where i can see the list of programs that are running automatically on every setup.
Thanks
You can turn off auto-start with this command:
chkconfig --level 345 mysqld off
To see what is configured for auto-start, you can run:
chkconfig --list
See more info on chkconfig here:
https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/6/html/Deployment_Guide/s2-services-chkconfig.html

MySQL Server 5.7 won't start and error log isn't being populated

I recently installed MySQL Server 5.7 on Ubuntu 14.04 (through ansible using this role to be specific). It started up fine when first installed, but when I try to restart it, it just hangs forever:
sudo service mysql restart
* Stopping MySQL Community Server 5.7.13
* MySQL Community Server 5.7.13 is already stopped
* Re-starting MySQL Community Server 5.7.13
....................................................................................................................................................................................
* MySQL Community Server 5.7.13 did not start. Please check logs for more details.
To make matters worse, no error logs seem to get populated anywhere (I've checked /var/log/mysql/ and /var/log/mysql.err).
Running in verbose mode (sudo /usr/sbin/mysqld --user=mysql --verbose) also gives me nothing.
Where can I look to diagnose this?
I had this exact problem as well, I hope my solution fixes your issues.
When I installed MySQL 5.7 manually it ran correctly, but with the Ansible role it would not start. The mysql log files were of no help. Checking /var/log/syslog however I found many messages from AppArmor:
Aug 10 18:50:05 vagrant-ubuntu-trusty-64 kernel: [ 4446.790627] type=1400 audit(1470855005.470:40): apparmor="DENIED" operation="open" profile="/usr/sbin/mysqld" name="/var/log/mysql.err" pid=13991 comm="mysqld" requested_mask="c" denied_mask="c" fsuid=109 ouid=109
AppArmor was denying access to the /var/log/mysql.err file because its policy for mysqld does not allow files to be written to /var/log/, just /var/log/mysql/. The AppArmor policy for mysql is at /etc/apparmor.d/usr.sbin.mysqld. The section of the policy that deals with log file access shows:
# Allow log file access
/var/log/mysql/ r,
/var/log/mysql/** rw,
This basically says that AppArmor expects log files to be written to /var/log/mysql with no provisions for /var/log. Since it sees mysql trying to write outside the directories inside the policy it shuts you down. There are several solutions to this, including adding a new policy to let mysql write files to /var/log, but I found it easiest to update the Ansible variables dealing with log files.
In the default variables for the geerlingguy.mysql role two log file pointers are set:
mysql_slow_query_log_file: /var/log/mysql-slow.log
mysql_log_error: /var/log/mysql.err
I override these defaults and move them to /var/log/mysql instead:
mysql_slow_query_log_file: /var/log/mysql/mysql-slow.log
mysql_log_error: /var/log/mysql/mysql.err
Now AppArmor is happy, and mysql starts and runs just fine. The rest of my playbook completes normally.
For more information on AppArmor and MySQL, this page provides a discussion and alternate solutions:
https://blogs.oracle.com/jsmyth/entry/apparmor_and_mysql

Trouble running mysql on OSX 10.6 development machine: "ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)"

I've installed MySQL on my personal/development machine using the .dmg package, according to the instructions here: http://dev.mysql.com/doc/refman/5.5/en/macosx-installation-pkg.html including installing the startup item and the preferences pane. And yet, I can't seem to use MySQL at all.
running:
/Library/StartupItems/MySQLCOM/MySQLCOM start
or
/Library/StartupItems/MySQLCOM/MySQLCOM restart
"appears" to work -- in that, it gives me a message like "Starting MySQL database server" -- but afterward, I still can't go into mysql at the command-line, or connect to it in a Rails 2.3.8 application running in script/server. I get the error denoted in the question title.
Also, the MySQL preferences pane doesn't seem to work either. If I click the "Start MySQL Server" button, I'm asked for my password, but then nothing happens -- the pane continues to say that the server is stopped.
(I believe I had a MacPorts version of MySQL installed previously, and it's also possible that there was one built from source at some time in the past -- but I'm reasonably sure I've uninstalled these and deleted all the files having to do with it that I could find.)
I'm also trying mysqld start in terminal. here's the output:
110127 15:40:28 [Warning] Can't create test file /usr/local/mysql-5.5.8-osx10.6-x86_64/data/Lucky-Charm.lower-test
110127 15:40:28 [Warning] Can't create test file /usr/local/mysql-5.5.8-osx10.6-x86_64/data/Lucky-Charm.lower-test
110127 15:40:28 [Note] Plugin 'FEDERATED' is disabled.
mysqld: Can't find file: './mysql/plugin.frm' (errno: 13)
110127 15:40:28 [ERROR] Can't open the mysql.plugin table. Please run mysql_upgrade to create it.
InnoDB: The InnoDB memory heap is disabled
InnoDB: Mutexes and rw_locks use GCC atomic builtins
InnoDB: Compressed tables use zlib 1.2.3
110127 15:40:28 InnoDB: Initializing buffer pool, size = 128.0M
110127 15:40:28 InnoDB: Completed initialization of buffer pool
110127 15:40:28 InnoDB: Operating system error number 13 in a file operation.
InnoDB: The error means mysqld does not have the access rights to
InnoDB: the directory.
InnoDB: File name ./ibdata1
InnoDB: File operation call: 'open'.
InnoDB: Cannot continue operation.
Tried following the message about running mysql_upgrade but that just gives me my original error again.
UPDATE:
OK I've been pursuing the theory that it's a permissions problem. Seeing that the datadir was owned by root, I chown -R it to _mysql. In response to Mike, here's where that now stands:
$ ls -al /usr/local/mysql-5.5.8-osx10.6-x86_64
total 296
drwxr-xr-x 16 root wheel 544 Dec 3 12:53 .
drwxrwxr-x 12 root staff 408 Jan 27 14:38 ..
-rw-r--r-- 1 root wheel 17987 Dec 3 11:58 COPYING
-rw-r--r-- 1 root wheel 12388 Dec 3 11:58 INSTALL-BINARY
-rw-r--r-- 1 root wheel 113534 Dec 3 11:58 README
drwxr-xr-x 44 root wheel 1496 Dec 3 12:53 bin
drwxr-xr-x 9 _mysql wheel 306 Jan 27 16:46 data
drwxr-xr-x 4 root wheel 136 Dec 3 12:53 docs
drwxr-xr-x 47 root wheel 1598 Dec 3 12:53 include
drwxr-xr-x 12 root wheel 408 Jan 27 14:38 lib
drwxr-xr-x 4 root wheel 136 Dec 3 12:53 man
drwxr-xr-x 19 root wheel 646 Jan 27 14:38 mysql-test
drwxr-xr-x 3 root wheel 102 Dec 3 12:53 scripts
drwxr-xr-x 32 root wheel 1088 Dec 3 12:53 share
drwxr-xr-x 28 root wheel 952 Dec 3 12:53 sql-bench
drwxr-xr-x 16 root wheel 544 Dec 3 12:53 support-files
I was trying to do mysqld start in the Terminal because it was the only thing giving me anything that seemed like meaningful error message output (see https://gist.github.com/799436) but I'm told by folks in #mysql that that's not intended to be run directly (and if I try sudo mysqld start i get a message bitching me out for trying to run mysql as root).
I seem to have something working now: mysqld_safe & successfully gets a MySQL server running. What still doesn't work is the "normal" method of starting up the server (the Startup Item or Preferences Pane)
... leading someone in #mysql to tell me that apparently MySQL is fine, it's the startup item that's borked.
Ok there were several things, mostly having to do with permissions/ownership, that were tried to make the binary-installed MySQL work nicely.
You may need to make sure that the startup item is owned by root:
sudo chown -R root:wheel /Library/StartupItems/MySQLCOM
Maybe you need a /etc/my.cnf file with this in it:
[mysqld]
socket=/tmp/mysql.sock
datadir=/usr/local/mysql/data
You might need to fill in these variables in /usr/local/mysql/support-files/mysql.server (the line will be there with blank values):
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
(see can't start MySql in Mac OS 10.6 Snow Leopard regarding the above)
That may be enough to do it, but if not, try making sure the mysql user (_mysql) can write to the data directory (owns it and has write permissions to everything in it).
Anyway, now the Preferences Panel and Startup Item actually seem to work for me.
After going over this a second time on another machine, I've made some edits and removed some unnecessary bit from what I answered yesterday.
Overall here's what I suggest you do to get the binary-installed MySQL working nice in OSX 10.6. Warning, you might end up deleting any databases you already had in the first couple steps, but as this is intended to be for your development machine, that shouldn't be any big deal. Back stuff up with mysqldump first if you must.
Make sure you don't have a mysql server running right now: ps aux | grep mysql will show you their processes. Stop it with mysqladmin shutdown or if that won't work because something is borked, sudo kill the process numbers.
Remove any prior installed versions of mysql -- check port list installed, check for a homebrew-installed one, sudo find / -name mysql looking for compiled-from-source ones and delete them, whatever it takes. You could even remove the startup item by deleting the /Library/StartupItems/MySQLCOM directory if you want.
Run the mysql-whatever-version.pkg install package
Test it by typing sudo mysqld_safe & at the terminal. If you get "command not found," add /usr/local/mysql/bin to your path and try again. If you get any scary error messages, check for a /etc/my.cnf file as described above and try again. If it still doesn't work, then maybe try recursively chowning and chmoding the /usr/local/mysql/data directory to make sure _mysql can write to it. Once you get it to appear to start up OK, enter mysql at terminal. If you get a MySQL command prompt, all is well (enter exit to get out of it) -- in fact, if you get anything other than the ol' "Can't connect to local MySQL server through socket" then you can conclude that the MySQL server works -- shut down or kill the server and move on.
Next we'll install the startup item. Run MySQLStartupItem.pkg
Test the startup item at the terminal by entering sudo /Library/StartupItems/MySQLCOM/MySQLCOM start. It will give you a message claiming that it is starting up the server, but if it's unsuccessful it won't give you any indication, so try going into mysql again to test that the server is running. If so, enter sudo /Library/StartupItems/MySQLCOM/MySQLCOM stop to stop the server (and to test that the startup item can stop the server as well as start it :D) If it didn't work, try making the settings described above in /usr/local/mysql/support-files/mysql.server. If that still doesn't do it, try the bit up at the top about sudo chown -R root:wheel /Library/StartupItems/MySQLCOM.
Once that works, run/install the MySQL.prefPane. This should give you a MySQL item in your System Preferences near the bottom, and if you go in there, you should see a button that you can click which will stop/start the MySQL server. Try it, and if it doesn't work by now, I'm not sure what else I can tell you.
I had experienced the same error after removing my old mac ports and installing mysql in a new mac ports directory ( a new /opt/local ).
I fixed it by setting the correct permissions for the mysql directories in the ports tree:
chown -R _mysql:_mysql /opt/local/var/db/mysql5
chown -R _mysql:_mysql /opt/local/var/run/mysql5/
chmod -R 755 /opt/local/var/run/mysql5
I'm not sure if the chmod was needed. Of course ports had already done the job of creating the _mysql user and group.