53

I am not sure how to fix this:

dyn-72-33-214-45:python mona$ sudo /usr/local/mysql/bin/mysqld stop
2014-09-06 09:49:04 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2014-09-06 09:49:04 22992 [Warning] Setting lower_case_table_names=2 because file system for /usr/local/mysql-5.6.15-osx10.7-x86_64/data/ is case insensitive
2014-09-06 09:49:04 22992 [ERROR] Fatal error: Please read "Security" section of the manual to find out how to run mysqld as root!

2014-09-06 09:49:04 22992 [ERROR] Aborting

2014-09-06 09:49:04 22992 [Note] Binlog end
2014-09-06 09:49:04 22992 [Note] /usr/local/mysql/bin/mysqld: Shutdown complete
Mona Jalal
  • 24,172
  • 49
  • 166
  • 311
  • 2
    I suppose you wanted to execute ```sudo /etc/init.d/mysql stop``` (an initscript and not the mysqld binary). – MrTux Sep 06 '14 at 13:53
  • /usr/local/mysql/bin/mysqladmin -u root shutdown – Donal Sep 06 '14 at 13:54
  • @Donal /usr/local/mysql/bin/mysqladmin -u root shutdown /usr/local/mysql/bin/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! – Mona Jalal Sep 06 '14 at 14:02
  • What do you want to do? Do you want to start or stop it? - Are you sure mysqld is really running? – MrTux Sep 06 '14 at 14:04
  • Is mysqld running? Check it with this: ps -ef | grep mysqld – Donal Sep 06 '14 at 14:06
  • @MrTux I want to stop it – Mona Jalal Sep 06 '14 at 14:11
  • @Donal ps -ef | grep mysqld 501 66888 1 0 18Aug14 ?? 0:00.03 /bin/sh /Applications/MAMP/Library/bin/mysqld_safe --port=8889 --socket=/Applications/MAMP/tmp/mysql/mysql.sock --pid-file=/Applications/MAMP/tmp/mysql/mysql.pid --log-error=/Applications/MAMP/logs/mysql_error_log 501 67004 66888 0 18Aug14 ?? 0:30.92 /Applications/MAMP/Library/bin/mysqld --basedir=/Applications/MAMP/Library --datadir=/Applications/MAMP/db/mysql --plugin- – Mona Jalal Sep 06 '14 at 14:12
  • @MonaJalal Can you add that output to your question? OSX may be using a daemon to launch mysql. I have posted an answer that will help you unload it. – Donal Sep 06 '14 at 14:20
  • `sudo service mysql status` – Ryan McCullagh Sep 06 '14 at 14:20

14 Answers14

92

I'm using OS X (Yosemite) and this error happened to me when I upgraded from Mavericks to Yosemite. It was solved by using this command

sudo /usr/local/mysql/support-files/mysql.server start
Mise
  • 2,517
  • 18
  • 19
  • Wow! Thanks a lot! How did you get to this solution, anyway? (Google found you before any docs :) ) – yair Dec 02 '14 at 12:44
  • Thank you, this helped me too. – LarsH Apr 04 '15 at 03:22
  • 2
    While this solution did work to get MySQL running, it doesn't seem like the most correct solution. The MySQL documentation says the files in this directory are for building the server, not for general usage. https://dev.mysql.com/doc/internals/en/support-files-directory.html – SacWebDeveloper Sep 02 '15 at 21:44
  • @yair: [here](http://dev.mysql.com/doc/refman/5.7/en/programs-overview.html) is an overview of the different MySQL programs. – Mullefa Dec 11 '15 at 21:04
  • 7
    Following this threw a `ERROR! The server quit without updating PID file` error. I looked into /usr/local/mysql/data/*.err file (the name is as per your username) & it pointed that mysqld aborted as it is unable to connect to /tmp/mysql.sock.lock . I had that file already created (as a different user I guess) & I removed it manually. The command now works. – Pocha Feb 02 '16 at 05:23
  • Works like charm! Thanks! – Willa Mar 15 '16 at 05:58
  • 1
    Awesome answer! I can confirm that this one still works with mac os mojave! – skiabox Oct 16 '18 at 11:14
17

you might try this if you logged in with root:

mysqld --user=root
xiaojueguan
  • 445
  • 4
  • 13
13

The MySQL daemon should not be executed as the system user root which (normally) do not has any restrictions.

According to your cli, I suppose you wanted to execute the initscript instead:

sudo /etc/init.d/mysql stop

Another way would be to use the mysqladmin tool (note, root is the MySQL root user here, not the system root user):

/usr/local/mysql/bin/mysqladmin --port=8889 -u root shutdown
MrTux
  • 28,370
  • 24
  • 91
  • 123
  • 3
    I am using osx ! `sudo: /etc/init.d/mysql: command not found` – Mona Jalal Sep 06 '14 at 14:01
  • As you're not using the default port, you have to add your special port to the second command or the socket-path: ```--socket=/Applications/MAMP/tmp/mysql/mysql.sock``` – MrTux Sep 06 '14 at 14:13
7

Try this for Amazon Linux AMI or for centOS

sudo service mysqld restart
Saurabh Chandra Patel
  • 9,983
  • 3
  • 77
  • 72
4

How i resolved this was following the 4th point in this url: https://dev.mysql.com/doc/refman/8.0/en/changing-mysql-user.html

  1. Edit my.cnf
  2. Add user = root under under [mysqld] group of the file

If this doesn't work then make sure you have changed the password from default.

mondrey
  • 376
  • 2
  • 5
1

osx could be using launchctl to launch mysql. Try this:

sudo launchctl unload -w /Library/LaunchDaemons/com.mysql.mysqld.plist
Donal
  • 25,862
  • 9
  • 57
  • 70
1

Donal had the right solution for me. However, the updated plist name for 2017 is

com.oracle.oss.mysql.mysqld.plist.
Machavity
  • 28,730
  • 25
  • 78
  • 91
1

I also had the same problem and able to resolve after using below command

/root/mysql-sandboxes/3320/bin/mysqld --defaults-file=/root/mysql-sandboxes/3320/my.cnf  --user=root &
Hasitha
  • 518
  • 6
  • 11
0

in my case (RHEL7 and MariaDB) this works.

sudo systemctl restart mariadb
0

On top of @mise's answer, After I installed MacOS Mojave, I also had to change files ownership on all my MAMP directory and contents).

From the Finder, I went in Application/MAMP, showed files info (cmd + i) and in permissions section added myself with read & write perms, then from the little gear applied to all the children.

antoni
  • 3,652
  • 25
  • 37
0

The correct answer that worked for me on CentOS is

/etc/init.d/mysql restart

which is an init script and not /etc/init.d/mysqld restart, which is binary

The is in fact comment of @MrTux on the question which worked for me. It took quite a bit of my time hence posting it as answer.

Hammad Khan
  • 14,008
  • 14
  • 100
  • 123
0

to run mysqld as root user from command line you need to add the switch/options --user=root

mariadb run as system root user

Peter
  • 152
  • 1
  • 11
0

I had this issue while running MySQL on Minikube (Ubuntu box) and I solved it with:

sudo ln -s /etc/apparmor.d/usr.sbin.mysqld /etc/apparmor.d/disable/
sudo apparmor_parser -R /etc/apparmor.d/usr.sbin.mysqld
Ivan Bosnic
  • 1,778
  • 5
  • 20
  • 31
0

Very weird, but I got this error when I made a typo in the my.cnf file.
So it had nothing to do with the user directive not defined or not running as root-user.

My mistake was:

bind=192.168.1.2

instead of

bind-address=192.168.1.2
Tim
  • 1,755
  • 18
  • 17