how to kill mysql processes - mysql

My docker-compose command won't run because I have these processes running:
$ sudo lsof -nP +c 15 | grep LISTEN | grep sql
mysqld 113 _mysql 19u IPv6 0xd0786f05dec2ff3f 0t0 TCP *:3306 (LISTEN)
mysqld 113 _mysql 22u IPv6 0xd0786f05dec789ff 0t0 TCP *:33060 (LISTEN)
Every time I kill the process listed, it starts up again with a new PID.
I've already uninstalled it:
$ brew uninstall mysql
Error: No such keg: /usr/local/Cellar/mysql
How can I totally and permanently kill this?
I've tried
sudo /usr/local/mysql/bin/mysqld stop
and
/usr/local/mysql/bin/mysqladmin -u root -p shutdown
When I try:
sudo mysql.server stop
It shows:
ERROR! MySQL server PID file could not be found!
but I still see new processes running for mysqld

(1) Search process by port sudo lsof -i tcp:3306
(2) Kill by userid pkill -u UID

Find out how mysqld is being spawned (like daemontools) and stop it from there. Or
Try killall mysqld

Related

Can't connect to local MySQL server and lost root password

I can't connect to a MySQL server, so I stopped MySQL with:
sudo /etc/init.d/mysql stop
# Stopping mysql (via systemctl): mysql.service.
Then, login with root and start MySQL again:
sudo -s
mysqld_safe --skip-grant-tables &
# .... mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
# 2021-05-29T03:01:11.967630Z mysqld_safe mysqld from pid file /var/lib/mysql...... ended
After that I executed:
mysqld_safe --skip-grant-tables
# Logging to '/var/lib/mysql/......err'.
# 2021-05-29T03:03:40.507375Z mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
# 2021-05-29T03:03:40.834556Z mysqld_safe mysqld from pid file /var/lib/mysql/...... ended
# [1]+ Done mysqld_safe --skip-grant-tables
At last I executed:
mkdir -p /var/run/mysqld
chown mysql:mysql /var/run/mysqld
mysql -u root
# ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
I also forgot my root password.
H, welcome.
You dont' need to call mysqld_safe two times, only one time is necessary. The parameter --skip-grant-tables makes any local connection to MySQL happens without password.
The message:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock'
Means that your server isn't listening on default unix socket located on /var/run/mysqld/mysqld.sock.
Kill every mysqld instance with:
ps -ef | grep mysql
# copy every id and...
kill <id>
Look for any clue in MySQL logs, probrably in /var/log/mysql/error.log and then try to start with mysqld_start --skip-grant-tables.

Cannot Start MYSQL Server Mac

I am currently trying to run mysql server on a mac, but the Start MySQL Server from the preferences pane doesn't work, and neither does starting it from the Terminal. I have found a lot of fixes, but none of them work. This is my first time using MySQL, I have very little (just a bit of Java) programming experience, and this is my first StackOverflow post in a long time (please help me learn if I did it incorrectly!).
I installed this version(didn't use brew): mysql-5.7.21-1-macos10.13-x86_64
My machine is 64 bit
What I've tried:
Uninstalled and reinstalled MySQL using this process:
To uninstall MySQL and completely remove it (including all databases) from your Mac do the following:
Open a terminal window Use mysqldump to backup your databases to text
files! Stop the database server sudo rm /usr/local/mysql sudo rm -rf
/usr/local/mysql* sudo rm -rf /Library/StartupItems/MySQLCOM sudo rm
-rf /Library/PreferencePanes/My* edit /etc/hostconfig and remove the line MYSQLCOM=-YES- rm -rf ~/Library/PreferencePanes/My* sudo rm -rf
/Library/Receipts/mysql* sudo rm -rf /Library/Receipts/MySQL* sudo rm
-rf /private/var/db/receipts/mysql https://community.jaspersoft.com/wiki/uninstall-mysql-mac-os-x
When I open the folder where mysql is installed, I do not have permissions to open the data or keychain folders. So, I decided it was a permissions problem and tried this: Cannot start Mysql on Mac. When I tried to start the server, I got the following error:
sudo /usr/local/mysql/support-files/mysql.server start Starting MySQL
.Logging to '/usr/local/mysql/data/XXXXs-MacBook-Air.local.err'.
/usr/local/mysql/bin/mysqld_safe: line 198: 7892 Trace/BPT trap: 5
nohup /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql
--datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=XXXXs-MacBook-Air.local.err --pid-file=/usr/local/mysql/data/XXXXs-MacBook-Air.local.pid < /dev/null > /dev/null 2>&1 ERROR! The server quit without updating
PID file (/usr/local/mysql/data/XXXXs-MacBook-Air.local.pid).
Tried to check the admin version and got the following error:
XXXXs-MacBook-Air:mysql XXXX$ bin/mysqladmin version mysqladmin:
connect to server at 'localhost' failed error: 'Can't connect to local
MySQL server through socket '/tmp/mysql.sock' (2)' Check that mysqld
is running and that the socket: '/tmp/mysql.sock' exists!
Tried to open /temp/mysql.sock from the command line and got that it does not exist
Tried this:
XXXXs-MacBook-Air:mysql XXXX$ % mysqladmin variables
-bash: fg: %: no such job XXXXs-MacBook-Air:mysql XXXX$ mysqladmin variables
-bash: mysqladmin: command not found
Tried removing my.cnf per this post and restarted the server
sudo rm -rf /etc/my.cnf
sudo /usr/local/mysql/support-files/mysql.server start
Tried these instructions MySql server startup error 'The server quit without updating PID file '
XXXXs-MacBook-Air:mysql XXXX$ ps -ef | grep mysql 501 9173
549 0 11:54PM ttys000 0:00.01 grep mysql
XXXXs-MacBook-Air:mysql XXXX$ kill -9 PID
-bash: kill: PID: arguments must be process or job IDs XXXXs-MacBook-Air:mysql XXXX$ ls -laF /usr/local/var/mysql/ ls:
/usr/local/var/mysql/: No such file or directory
XXXXs-MacBook-Air:mysql XXXX$ ls -laF /usr/local/mysql lrwxr-xr-x
1 root wheel 30 Apr 4 22:44 /usr/local/mysql# ->
mysql-5.7.21-macos10.13-x86_64 XXXXs-MacBook-Air:mysql XXXX$ sudo
chown -R mysql /usr/local/var/mysql/ Password: chown:
/usr/local/var/mysql/: No such file or directory
XXXXs-MacBook-Air:mysql XXXX$ sudo chown -R mysql /usr/local/mysql
XXXXes-MacBook-Air:mysql XXXX$ sudo
/usr/local/mysql/support-files/mysql.server start Starting MySQL
.Logging to '/usr/local/mysql/data/XXXXs-MacBook-Air.local.err'.
/usr/local/mysql/bin/mysqld_safe: line 198: 9327 Trace/BPT trap: 5
nohup /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql
--datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=XXXXs-MacBook-Air.local.err --pid-file=/usr/local/mysql/data/XXXXs-MacBook-Air.local.pid < /dev/null > /dev/null 2>&1 . ERROR! The server quit without updating
PID file (/usr/local/mysql/data/XXXXs-MacBook-Air.local.pid).
XXXXs-MacBook-Air:mysql XXXX$ unset TMPDIR
XXXXs-MacBook-Air:mysql XXXX$ mysql_install_db --verbose
--user=whoami --basedir="$(brew --prefix mysql)" --datadir=/usr/local/var/mysql --tmpdir=/tmp
-bash: mysql_install_db: command not found
And now I'm back to this error:
ERROR! The server quit without updating PID file
(/usr/local/mysql/data/XXXXs-MacBook-Air.local.pid).
Please help!
EDITED: I uninstalled and reinstalled with brew. Using these instructions: http://stefan.magnuson.co/articles/osx/reinstalling-mysql-on-osx-with-homebrew/ Now it works.
I uninstalled and reinstalled SQL with Homebrew using these instructions: http://stefan.magnuson.co/articles/osx/reinstalling-mysql-on-osx-with-homebrew/ Now it works.
This small diagnosis worked for me in MAC...
open Your Terminal and use the following command to check all the instances or mysql that are currently running in your machine.
1) ps -ef | grep mysql
If you found any process Id with the above command.
2) sudo kill -9 [PID]
Where [PID] is the process id next to username
now try restarting mysql again using the mysql server pane or go to terminal and type the following command
sudo /usr/local/mysql/support-files/mysql.server start

MySQL won't start in XAMPP Manager-osx

My XAMPP mysql server is working fine
then I download the separate mysql from oracle and installed it. It is running fine but after some days I cant start it as :> mysql -u root
and in xampp mysql server it is also not working it shows stopped always.
I am providing all the commands that I tried from google as well as StackOverflow
and also I am providing all results of all commands.
Please refer commands before answering.
Number indicates ways that I tried.
1.> `mysql -u root -p`
2.> `mysql -u root`
3.> `sudo su`
3.1.> `ps aux | grep mysql`
3.2.> `kill -9 8306`
4.> `sudo /Applications/XAMPP/xamppfiles/bin/mysql.server start`
5.> `sudo killall mysqld`
6.> Changing content of file as: `innodb_force_recovery = 1` in
`/Applications/XAMPP/xamppfiles/etc/my.cnf`
7.> Changing content of file as: read only permission in
`/Applications/XAMPP/xamppfiles/etc/my.cnf`
8.> Port changed from 3306 to 3307 3308 but nothing is happened
9.> Activity manager : mysql service is. not listed
10.> Reinstalled XAMPP
I followed this 10 ways so please dont answer on this 10 ways
Result of commands :
<.1.
Pratiks-MacBook-Pro:~ pratik$ mysql -u root -p
Enter password:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/Applications/XAMPP/xamppfiles/var/mysql/mysql.sock' (2 "No such file or directory")
<.2.
Pratiks-MacBook-Pro:~ pratik$ mysql -u root
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/Applications/XAMPP/xamppfiles/var/mysql/mysql.sock' (2 "No such file or directory")
<.3.
Pratiks-MacBook-Pro:~ pratik$ sudo su
Password:
sh-3.2# ps aux | grep mysql
root 8306 0.0 0.0 4258468 180 s000 U+ 11:35AM 0:00.00 grep mysql
sh-3.2# kill -9 8306
sh: kill: (8306) - No such process
sh-3.2#
<.4.
Pratiks-MacBook-Pro:~ pratik$ sudo /Applications/XAMPP/xamppfiles/bin/mysql.server start
Starting MySQL
.2018-03-13 11:44:29 8513 mysqld_safe Logging to '/Applications/XAMPP/xamppfiles/var/mysql/Pratiks-MacBook-Pro.local.err'.
2018-03-13 11:44:29 8513 mysqld_safe Starting mysqld daemon with databases from /Applications/XAMPP/xamppfiles/var/mysql
ERROR!
<.5.
Pratiks-MacBook-Pro:~ pratik$ sudo killall mysqld
No matching processes were found

Kill Mysql service running on any port, Mac Sierra

Kill Mysql service running on any port using terminal.
Port number like 3306 or any.
sudo pkill mysql should serve your purpose.
If for some reason mysqld survives this, sudo pkill mysqld as well.
More information from SuperUser:
https://superuser.com/questions/983969/how-to-kill-mysql-with-moving-pid
Simplifying your answer.
1) Go to Launchpad Type Terminal then Run this.
2) Run following commands
Check if Mysql service is running
For all listening ports
netstat -vanp tcp
Apply port filter
netstat -vanp tcp | grep
netstat -vanp tcp | grep 3306
Kill Mysql Service
sudo pkill mysql
or sudo pkill mysqld
< Enter password >
Done !!!
Run this in terminal:
lsof -n -iTCP:3306 -sTCP:LISTEN -n -l -P | grep 'LISTEN' | awk '{print $2}' | xargs kill -9

How to kill mysql started with "mysql_safe" script?

Short version: I started mysql with mysql_safe and I can't kill it.
Long version: Installing an older version of mysql with macport displayed this suggestion:
$ sudo port install mysql55-server
---> Computing dependencies for mysql55-server
---> Fetching archive for mysql55-server
---> Attempting to fetch mysql55-server-5.5.49_0.darwin_14.noarch.tbz2 from https://packages.macports.org/mysql55-server
---> Attempting to fetch mysql55-server-5.5.49_0.darwin_14.noarch.tbz2.rmd160 from https://packages.macports.org/mysql55-server
---> Installing mysql55-server #5.5.49_0
---> Activating mysql55-server #5.5.49_0
If this is a new install you might want to run:
$ sudo -u _mysql /opt/local/lib/mysql55/bin/mysql_install_db
Running that gave these instructions:
$ sudo -u _mysql /opt/local/lib/mysql55/bin/mysql_install_db
Installing MySQL system tables...
161102 13:15:44 [Note] /opt/local/lib/mysql55/bin/mysqld (mysqld 5.5.49) starting as process 54176 ...
OK
Filling help tables...
161102 13:15:44 [Note] /opt/local/lib/mysql55/bin/mysqld (mysqld 5.5.49) starting as process 54180 ...
OK
To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system
PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:
/opt/local/lib/mysql55/bin/mysqladmin -u root password 'new-password'
/opt/local/lib/mysql55/bin/mysqladmin -u root -h myusername password 'new-password'
Alternatively you can run:
/opt/local/lib/mysql55/bin/mysql_secure_installation
which will also give you the option of removing the test
databases and anonymous user created by default. This is
strongly recommended for production servers.
See the manual for more instructions.
You can start the MySQL daemon with:
cd /opt/local ; /opt/local/lib/mysql55/bin/mysqld_safe &
You can test the MySQL daemon with mysql-test-run.pl
cd /opt/local/mysql-test ; perl mysql-test-run.pl
Please report any problems at http://bugs.mysql.com/
At this point I (unwisely, it seems) ran:
$ cd /opt/local ; /opt/local/lib/mysql55/bin/mysqld_safe &
Now I cannot figure out how to stop the mysql and/or daemondo process(es):
$ ps aux | grep mysql55
myusername 54937 0.1 0.0 2432772 660 s001 R+ 1:39PM 0:00.00 grep mysql55
_mysql 54888 0.0 0.1 2667884 6340 ?? S 1:36PM 0:00.12 /opt/local/lib/mysql55/bin/mysqld --user=_mysql
root 54885 0.0 0.0 2479468 700 ?? Ss 1:36PM 0:00.00 /opt/local/bin/daemondo --label=mysql55-server --start-cmd /opt/local/lib/mysql55/bin/mysqld --user=_mysql ; --pid=exec
I've tried many variations of kill, targeting both mysql (which seems pointless) and daemondo, including (but not limited to) the following:
sudo kill -9 54888 // killing the mysql process results in a new pid
sudo kill 54885 // the doemondo process
sudo kill -SIGHUP 54885
sudo killall mysqld_safe
sudo kill -9 54822 // a reincarnation of the doemondo process
sudo mysqladmin shutdown
For centos or mint
/usr/bin# initctl
for ubuntu
pkill mysqld