add services to init.d on Ubuntu - mysql

I'm trying to simplify commands on my ubuntu server.
For now, to start / stop / restart apache2, we have to type those commands :
stop : /etc/apache2/bin/apachectl -k stop
start : /etc/apache2/bin/apachectl -f /usr/local/apache2/conf/httpd.conf
restart : /etc/apache2/bin/apachectl restart
and kinda same for MySql :
stop : mysqladmin -u root shutdown
start : mysqld_safe --user=mysql --log &
What I wish is to be able to use /etc/init.d/apache2 start or /etc/init.d/mysql start to make it simple and not having to always look at the Wiki to find the exact command to use each time...
I tried to find samples of files to put in init.d folder, but found nothing.
I also wanted to know how to do the same with service apache2 start (and same for stop/restart and MySql).
Is there a difference between using /etc/init.d/xx start and service xx start ?
Thanks for you help !

Just put the executable file i.e apachectl in /etc/init.d/ and than try with /etc/init.d/apache{tab} restart/start/stop and all for mysql too it will work.
Actually init.d contains the shell script file that is executable.
Take care the file should be executable like below
chmod +x /etc/init.d/apachectl

Related

MAMP server : start and stop server [duplicate]

I am trying to find a way by which I can start and stop MAMP PRO's Apache and mysql using command line.
So far whatever I have search has only helped me start MAMP PRO.
Thanks.
As of at least MAMP 3.0.6, the following works for both Free and Pro versions:
Open MAMP Pro or Free, depending on the one you use:
Pro:
open /Applications/MAMP\ PRO/MAMP\ PRO.app/
Free:
open /Applications/MAMP/MAMP.app/
Then, cd into MAMP/bin:
cd /Applications/MAMP/bin
To start Apache & MySQL:
./start.sh
To stop Apache & MySQL:
./stop.sh
Note that you might need to sudo the commands above.
After much trial and error:
Note that I have my ports set to the application's respective defaults (Apache: 80, MySQL: 3306), and as such these commands reflect that, AND you must use sudo with Apache (which you will in MAMP as well if you're using port 80).
Apache
sudo /Applications/MAMP/Library/bin/httpd -f "/Library/Application Support/appsolute/MAMP PRO/conf/httpd.conf" -k start
sudo /Applications/MAMP/Library/bin/httpd -f "/Library/Application Support/appsolute/MAMP PRO/conf/httpd.conf" -k stop
sudo /Applications/MAMP/Library/bin/httpd -f "/Library/Application Support/appsolute/MAMP PRO/conf/httpd.conf" -k restart
MySQL
To start MySQL:
sh -c '/Applications/MAMP/Library/bin/mysqld_safe --defaults-file=/Applications/MAMP/tmp/mysql/my.cnf --port=3306 --socket=/Applications/MAMP/tmp/mysql/mysql.sock --user=alex --pid-file=/Applications/MAMP/tmp/mysql/mysql.pid --log-error=/Applications/MAMP/logs/mysql_error_log.err --tmpdir=/Applications/MAMP/tmp/mysql/tmpdir --datadir=/Library/Application\ Support/appsolute/MAMP\ PRO/db/mysql &'
(for some reason you must hit enter again to regain your prompt)
To stop MySQL:
sh -c '/Applications/MAMP/Library/bin/mysqladmin -u root -proot --socket=/Applications/MAMP/tmp/mysql/mysql.sock shutdown'
As a bonus, the indicators in the MAMP PRO.app GUI show the correct status of these apps in real time, so you can continue to rely on that.
I have MAMP PRO v2.0.3.
http://pastebin.com/avn0BFap
Save the script and give executable rights such as: chmod +x start.sh
Then use it like ./start.sh Start or ./start.sh Stop or ./start.sh Restart
Best Solution for MAMP 3 on OSX
(should work for MAMP Pro as well).
Look inside of the folder:
/Applications/MAMP/Library/bin
You'll see the scripts used for starting and stoping Apache & MySQL.
Look inside any of the scripts:
start.sh or stop.sh or startApache.sh etc
You will see that they use the program:
apachectl
You can use the restart command with apachectl. So, just set-up an alias in your ~/.bash_rc file:
alias rap='sudo /Applications/MAMP/Library/bin/apachectl restart'
rap is the acronym I gave for 'Restart Apache'. Presto! One step from the command line without having to open the MAMP application. Use the same logic if you want to set this up for MySQL.
To start it on MAMP pro version 4 it's
/Applications/MAMP\ PRO/MAMP\ PRO.app/Contents/MacOS/MAMP\ PRO cmd startServers
To stop it it's
/Applications/MAMP\ PRO/MAMP\ PRO.app/Contents/MacOS/MAMP\ PRO cmd stopServers
Sadly
Based on the advice given here
"https://deliciousbrains.com/automating-local-wordpress-site-setup-scripts-part-3-automating-rest"
And found then discovered - it's HIDDEN in the documentation right here.
https://documentation.mamp.info/en/MAMP-PRO-Mac/How-Tos/General/CreateHostDatabaseCommandLine
Nearly the same with MAMP Pro 5:
/Applications/MAMP\ PRO.app/Contents/MacOS/MAMP\ PRO cmd stopServers
start:
/Applications/MAMP\ PRO.app/Contents/MacOS/MAMP\ PRO cmd startServers
If you are using MAMP PRO there is an easier way to stop MySQL.
MAMP PRO creates a shell script in your Library folder. If you've changed the password for the root user (which you should), the updated password will also be reflected in the script. The file can be found at:
~/Library/Application Support/appsolute/MAMP PRO/stopMysql.sh
In order to type that on the command line you need to escape the spaces by adding a backslash in front of them like the command below.
Stop MySQL Shell Script for MAMP PRO
~/Library/Application\ Support/appsolute/MAMP\ PRO/stopMysql.sh
The other thing that I found on my system was that the file didn't have the execute bit set on it. I cheated and used Path Finder to set the file as executable but you can easily find information about how to do it through the command line with chmod.
Unfortunately I can't find a proper start script created by MAMP PRO. I wanted to find something simple to use for the start command in MySQLWorkbench but for now I just left it blank because the default MAMP script does not work. I may create a script based on the helpful commands Astockwell posted in response to this question.
I found /Applications/MAMP PRO/MAMP PRO.app/Contents/Resources/MAMP.startup, which works for me in MAMP PRO, with custom ports.
Just run
/Applications/MAMP PRO/MAMP PRO.app/Contents/Resources/MAMP.startup start
or
/Applications/MAMP PRO/MAMP PRO.app/Contents/Resources/MAMP.startup stop
etc.
Simple way would be to shut down and restart the application, MAMP PRO will start and stop Apache and MySQL.
start MAMP PRO
open -a MAMP\ PRO
stop MAMP PRO
osascript -e 'quit app "MAMP PRO"'
For MAMP Pro 5 use
sudo /Applications/MAMP/Library/bin/apachectl -f"/Library/Application Support/appsolute/MAMP PRO/conf/httpd.conf" -k restart
remember, you must use sudo
For MAMP5.5, search for this script file in your MAMP bin folder: startMysql.sh
It would have few lines:
#!/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 &
Copy Paste the entire command on your OSX shell and just press enter, your Mysql server would start.
Open a new shell and start using Mysql from command line.

MySQL does not start when upgrading OSX to Yosemite or El Capitan

I know similar questions exist, such as MySQL with MAMP does not work with OSX Yosemite 10.10. However, I do have MAMP, nor XAMPP installed on my computer.
When I try to start mySQL from the PrefPane, nothing happens.
When I try to start mqSQL from the command line via sudo /usr/local/mysql/support-files/mysql.server start I get:
Starting MySQL . ERROR! The server quit without updating PID file
(/usr/local/mysql/data/adamg.local.pid).
Any and all help would be appreciated. I can supply any file output necessary.
Open a terminal:
Check MySQL system pref panel, if it says something along the line "Warning, /usr/local/mysql/data is not owned by 'mysql' or '_mysql'
If yes, go to the mysql folder cd /usr/local/mysql
do a sudo chown -R _mysql data/
This will change ownership of the /usr/local/mysql/data and all of its content to own by user '_mysql'
Check MySQL system pref panel, it should be saying it's running now, auto-magically. If not start again.
Another way to confirm is to do a
netstat -na | grep 3306
It should say:
tcp46 0 0 *.3306 *.* LISTEN
To see the process owner and process id of the mysqld:
ps aux | grep mysql
Long story short you need to create a launch file. So, from Terminal:
sudo vi /Library/LaunchDaemons/com.mysql.mysql.plist
(If you are not familiar with vi, then press i to start inserting text)
This should be the content of your file:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>KeepAlive</key>
<true />
<key>Label</key>
<string>com.mysql.mysqld</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/mysql/bin/mysqld_safe</string>
<string>--user=mysql</string>
</array>
</dict>
</plist>
press esc then : wq!enter
Then you need to give the file the right permissions and set it to load on startup.
sudo chown root:wheel /Library/LaunchDaemons/com.mysql.mysql.plist
sudo chmod 644 /Library/LaunchDaemons/com.mysql.mysql.plist
sudo launchctl load -w /Library/LaunchDaemons/com.mysql.mysql.plist
And that is it.
In my case I fixed it doing a little permission change:
sudo chown -R _mysql:_mysql /usr/local/var/mysql
sudo mysql.server start
I hope it helps somebody else...
Note: As per Mert Mertin comment:
For el capitan, it is sudo chown -R _mysql:_mysql /usr/local/var/mysql
Solved by installing the latest mySQL release, following the instructions here http://coolestguidesontheplanet.com/get-apache-mysql-php-phpmyadmin-working-osx-10-10-yosemite/
EDIT
As Yosemite gets more popular, more people are stumbling on this question. The answer above has to do with upgrading MySQL, so that it runs. The answer linked by #doc in the comments has to do with getting MySQL to start automatically. These are 2 separate issues.
Execute the following commands from command line...
sudo launchctl load -F /Library/LaunchDaemons/com.oracle.oss.mysql.mysqld.plist
sudo launchctl unload -F /Library/LaunchDaemons/com.oracle.oss.mysql.mysqld.plist
and then start the mysql server using
sudo /usr/local/mysql/support-files/mysql.server start
The .pid is the processid of the running mysql server instance. It appears in the data folder when mysql is running and removes itself when mysql is shutdown.
If the OSX operating system is upgraded and mysql is not shutdown properly before the upgrade,mysql quits when it started up it just quits because of the .pid file.
There are a few tricks you can try, http://coolestguidesontheplanet.com/mysql-error-server-quit-without-updating-pid-file/ failing these a reinstall is needed.
You just need to create the user mysql (mysql installation script creates _mysql)
sudo vipw
duplicate line that contains _mysql
Change for the duplicated line _mysql to mysql
sudo /usr/local/mysql/support-files/mysql.server start
Starting MySQL
.. SUCCESS!
The re-install fixed it because the installer created a new MySQL instance and the symbolic link to /usr/local/mysql now points to a data directory that does not have an existing pid.
It's worth noting that the mysql prefpane and mysql.server script use the hostname for the pid, so changing the hostname may cause issues with the this.
While the prefpane is out of date, it's a nice GUI for someone to start/stop MySQL even if the auto-start function doesn't work.
I've taken a hybrid approach where I've adapted my MySQL install script to use Launchd to auto-start MySQL, but the plist actually calls the mysql.server script. This way the prefpane can still be used to start/stop MySQL on demand, and trying to do a simple MySQL restart won't be too confusing.
Here is script that just enables this Launchd behavior on Yosemite with MySQL already installed:
https://raw.githubusercontent.com/MacMiniVault/Mac-Scripts/master/mmvMySQL/YosemiteLaunchd.sh
Here is the script that handles the entire automated installation of MySQL:
https://raw.githubusercontent.com/MacMiniVault/Mac-Scripts/master/mmvMySQL/mmvmysql.sh
You will sometimes miss previous data if you try to install new version.. Please use the following in your terminal and I guarantee that mySql will start running in no time..
sudo /Applications/XAMPP/xamppfiles/bin/mysql.server start
Remember, it will ask for your Machine password and not mysql password..
I’ve got a similar problem with MySQL on a Mac (Mac Os X Could not startup MySQL Server. Reason: 255 and also “ERROR! The server quit without updating PID file”). After a long trial and error process, finally in order to restore the file permissions, I’ve just do that:
* launch the Disk Utilities.app
* choose my drive on the left panel
* click on the “Repair disk permissions” button
This did the trick for me.
Hoping this can help someone else.
Try this:
sudo mysqld_safe &
Way simplest: copy and paste this into Terminal (but be sure to read more first):
bash <(curl -Ls http://git.io/eUx7rg)
This will install and configure everything automagically. The script is provided by MacMiniVault and is available on Github. More information about the mySQL install script on http://www.macminivault.com/mysql-yosemite/.
you want fix it can edit file "/Applications/XAMPP/xamppfiles/xampp" with TextEdit.
Look for text "$XAMPP_ROOT/bin/mysql.server start > /dev/null &"
And add "unset DYLD_LIBRARY_PATH" on top of it. It should look like:
unset DYLD_LIBRARY_PATH
$XAMPP_ROOT/bin/mysql.server start > /dev/null &
hope can help you
None of the above worked.. but installing a new version of MySQL did the trick.
2 steps solved my problem:
1) Delete "/Library/LaunchDaemons/com.mysql.mysql.plist"
2) Restart Yosemite
I usually start mysql server by typing
$ mysql.server start
without sudo. But in error I type sudo before the command. Now I have to remove the error file to start the server.
$ sudo rm /usr/local/var/mysql/`hostname`.err
My Mac decided to restart itself randomly; causing a whole slew of errors. One of which, was mysql refusing to start up properly. I went through many SO questions/answers as well as other sites.
Ultimately what ended up resolving MY issue was this:
1) Creating the file (/usr/local/mysql/data/.local.pid
2) chmod 777 on that file
3) executing mysql.server start (mine was
located in/usr/local/bin/mysql.server)
Same happened to me! So I tried to startup again after I had terminated the running mysql application, and that worked!

ERROR! MySQL manager or server PID file could not be found! QNAP

I am having an issue where MySQL isn't starting on my QNAP NAS.
I found this first by not being able to log in through phpMyAdmin - was getting error:
#2002 Cannot log in to the MySQL server
I then went to attempt to start mysql, as I guess this is a common issue with this, but it just gave a generic error.
I went through troubleshooting the mysql.sock file and everything, changing its permissions, but nothing is working.
I have rebooted my NAS many times.
I eventually tried to restart mysql. In doing so I get:
ERROR! MySQL manager or server PID file could not be found!
I can't find anything specific to the QNAP or any general type troubleshooting for this. Everything I find seems to be OSX related.
After a lot of searching, I was able to fix the "PID file cannot be found" issue on my machine. I'm on OS X 10.9.3 and installed mysql via Homebrew.
First, I found my PID file here:
/usr/local/var/mysql/{username}.pid
Next, I located my my.cnf file here:
/usr/local/Cellar/mysql/5.6.19/my.cnf
Finally, I added this line to the bottom of my.cnf:
pid-file = /usr/local/var/mysql/{username}.pid
Hopefully this works for someone else, and saves you a headache! Don't forget to replace {username} with your machine's name (jeffs-air-2 in my case).
I tried everything above, but saw no results until I got a hint from here: https://superuser.com/questions/159486/how-to-kill-process-in-mac-os-x-and-not-have-it-restart-on-its-own
I eventually went over to the activity monitor in my Mac, force Quit the PID, and ran the command:
sudo /usr/local/mysql/support-files/mysql.server restart
The magic was done!!!
If you have installed MySQL using brew the best way to go would be with homebrew
brew services restart mysql
after you run that command, all the problems that the update generated will be resolved
I ended up figuring this out on my own.
In searching for my logs I went into
cd /usr/local/mysql/var
In there I found the file named [MyNAS].pid (replace [MyNAS] with the name of your NAS.
I then ran the following to remove the file
rm -rf /usr/local/mysql/var/[MyNAS].pid
I then restarted mysql
[/usr/local/mysql/var] # /etc/init.d/mysqld.sh restart
/mnt/ext/opt/mysql
/mnt/ext/opt/mysql
Try to shutting down MySQL
ERROR! MySQL manager or server PID file could not be found!
/mnt/ext/opt/mysql
Starting MySQL. SUCCESS!
I tested everything and it all works like a charm again!
Run the below commands and it will work.
Go to terminal and type
sudo chown -RL root:mysql /usr/local/mysql
sudo chown -RL mysql:mysql /usr/local/mysql/data
sudo /usr/local/mysql/support-files/mysql.server start
Just run mysqld (don't run as root) from your terminal. Your mysql server will restart and reset everything like shown in the picture below:
And use a command like so:
mysql -u root -h 127.0.0.1
ERROR! MySQL server PID file could not be found!
This might be due to issues with disk space, disk inode usage or innodb corruption which may lead to the error.
The issue was with the pid file and the solution was:
SSH login to server as a root
Create directory /var/run/mysql
mkdir /var/run/mysql
3) Create a file with name as mysqld.pid
touch mysqld.pid
Change its ownership and group to mysql:mysql
chown mysql:mysql mysqld.pid
Restart MySQL service
Done!
I had the same issue. It turns out I added incorrect variables to the my.cnf file. Once I removed them and restarted mysql started with no issue.
Check if your server is full first, thats a common reason (can't create the PID file because you have no space). Run this to check your disk usage..
df -h
If you get something like this, you are full..
Filesystem Size Used Avail Use% Mounted on
/dev/vda1 40G 40G 6.3M 100% /
In that case, you need to start looking for what to delete to make room, or add an additional drive to your server.
Nothing of this worked for me. I tried everything and nothing worked.
I just did :
brew unlink mysql && brew install mariadb
My concern was if I would lost all the data, but luckily everything was there.
Hope it works for somebody else
Note: If you just want to stop MySQL server, this might be helpful.
In my case, it kept on restarting as soon as I killed the process using PID. Also brew stop command didn't work as I installed without using homebrew. Then I went to mac system preferences and we have MySQL installed there. Just open it and stop the MySQL server and you're done. Here in the screenshot, you can find MySQL in bottom of system preferences.
I know this is an older post, but I ran into the ERROR! MySQL server PID file could not be found! when trying to start MySQL after making an update to my.cnf file. I did the following to resolve the issue:
Deleted my experimental update to my.cnf
Deleted the .net.pid and .net.err files.
delete /usr/local/var/mysql/**<YourUserName>**-MBP.airstreamcomm.net.*
Ensured all MySQL processes are stopped.
ps -ax | grep mysql
kill **<process id>**
Started MySQL server as normal.
mysql.server start
First find PID of mysql service
ps aux | grep mysql
Then, you have to kill process
sudo kill <pid>
After you again start mysql service
mysql.server start
After doing setup of PHPMyAdmin, I was also facing the same problem,
Then I just stopped the MYSQL server by going into System settings, and then started again, and it worked.
root#host [~]# service mysql restart
MySQL server PID file could not be found! [FAILED]
Starting MySQL.The server quit without updating PID file (/[FAILED]mysql/host.pxx.com.pid).
root#host [~]# vim /etc/my.cnf
Add Line in my.cnf its working know
innodb_file_per_table=1
innodb_force_recovery = 1
Result
root#host [~]# service mysql restart
MySQL server PID file could not be found! [FAILED]
Starting MySQL……….. [ OK ]
root#host [~]# service mysql restart
Shutting down MySQL…. [ OK ]
Starting MySQL. [ OK ]
Source
I have the same problem. I found the file {username}.local.err instead of {username}.local.pid inside /usr/local/mysql, then i changed the name *.err to *.pid and it works fine.
Starting MySQL.
SUCCESS!
My OS El Capitan 10.11.5
If you're using MySQL Workbench, the mysql.server stop/restart/start will not work.
You will need to login into the workbench and then click "shutdown server". See image attached.
I was able to solve this on OS X by shutting down the existing mysql.server that was running:
mysql.server stop
The starting:
mysql.server start
From there I could run mysql.server restart without throwing the ERROR.

Mysql service failed to start after I remove all log file

I delete all file in /var/log, however, when I restart mysql service, it failed to start now.
help!
Rather than invoking init scripts through /etc/init.d, use the service(8)
utility, e.g. service mysql restart
Since the script you are attempting to invoke has been converted to an
Upstart job, you may also use the stop(8) and then start(8) utilities,
e.g. stop mysql ; start mysql. The restart(8) utility is also available.
start: Job failed to start
Try creating Directory Manually & Assign the Permission to Mysql.
Ex. mkdir /var/log/mysql
Chown -R mysql:mysql /var/log/mysql
& Restart the mysql Service again it might be slove your problem.
Maybe your my.cnf is "world wide writable" ?
Check permissions.
It should be like 755...
NOT 777.
try running mysqld using
/usr/sbin/mysqld
i have once come across this problem. i.e. my mysql says Job can't start .I don't know why but it started after
sudo dpkg-reconfigure mysql-server-5.5
/usr/sbin/mysqld
May be there is some bug on service routine.
You can re-create the "log pool" yourself
mkdir /var/log/mysql
And give it full access
chmod -R 777 /var/log/mysql
Now restart your db server
service mysql start
or
/usr/sbin/mysqld

After MySQL install via Brew, I get the error - The server quit without updating PID file

Ok, I've searched all over and have spent quite a bit of my time installing, uninstalling, trying various option but without success.
I'm on Mac OS X Lion (10.7.3) and am trying to setup a Python, MySQL.
I successfully installed Python and MySQL via HomeBrew.
Python works great.
After MySQL Installation, I followed the first 2 steps - unset and the mysql_install_db commands.
Now, when I try to start mysql "mysql.server start", I get the following error
ERROR! The server quit without updating PID file (/usr/local/var/mysql/Brajeshwar.local.pid).
Brajeshwar is my username on my machine.
I found that it was a permissions issue with the mysql folder.
chmod -R 777 /usr/local/var/mysql/
solved it for me.
EDIT 2012/09/18:
As pointed out by Kane, make sure the mysql database is properly set up before doing anything else. See “PID error on mysql.server start?” for more info.
Original answer kept for history's sake:
It most likely is a permissions issue. Check /usr/local/var/mysql/*.err. Mine said:
120314 16:30:14 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.
120314 16:30:14 mysqld_safe mysqld from pid file /usr/local/var/mysql/janmoesen.local.pid ended
I also had to do this:
sudo chown _mysql /usr/local/var/mysql/*
I ended up with completely reinstalling of mysql, and it finally worked out.
WARNING This will remove all of your databases, so make sure to save dumps first.
brew remove mysql
brew cleanup
launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
rm ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
sudo rm -rf /usr/local/var/mysql
brew install mysql
mysqld --initialize --explicit_defaults_for_timestamp
mysql.server start # no sudo!
I had this issue on mac 10.10.5 Yosemite
What I did to solve this
cd /usr/local/var/mysql
sudo rm *.err && sudo rm *.pid
sudo reboot
sudo mysql.server start
I had the same issue on OS X El Capitan, here's the terminal command sequence that fixed it for me.
Delete error files (you'll have to change the path depending on your setup)
sudo rm /usr/local/mysql/data/*.err
Find the info for the mysql process that's still running and kill it:
ps -A | grep -m1 mysql | awk '{print $1}' | sudo xargs kill -9
Now restart MySQL:
/usr/local/mysql/support-files/mysql.server start
November, 2014: If you're getting this error on MySQL 5.6.x on Mac OS X Mavericks or Yosemite and want to use MySQL with PHP locally (/tmp/mysql.sock is where PHP PDO expects to find the sock file), here is what fixed it for me:
1) Uncomment the default homebrew config file lines and edit as below
$ sudo vi /usr/local/Cellar/mysql/5.6.21/my.cnf
...
basedir = /usr/local/Cellar/mysql/5.6.21
datadir = /usr/local/var/mysql
port = 3306
server_id = <UNIQUE_NUMBER_HERE_OR_LEAVE_COMMENTED_OUT>
socket = /tmp/mysql.sock
pid-file = /usr/local/var/mysql/[BOXNAME].local.pid
....
BOXNAME is what you have in your System Prefs -> Network as the unique id for your computer on the network.
2) Set permissions on all the files in the mysql datadir. These were all owned by [my_username]. MySQL is very picky about this and refuses to create the pid file unless it (the user _mysql) owns the directory.
$ sudo chown -R _mysql:mysql /usr/local/var/mysql
3) Start MySQL using the bash helper/wrapper script:
$ sudo mysql.server start
Starting MySQL
. SUCCESS!
Hope that helps. If the above doesn't work for you, try to run the mysqld_safe binary manually in the Cellar/mysql/VERSION_/bin/ directory and check what the settings are (if it runs)
sudo /usr/local/Cellar/mysql/5.6.12/bin/mysqld_safe &
If that runs, you can
ps aux | grep mysql
and see something like
[username] 6881 0.0 2.7 3081392 454836 ?? S 8:52AM 0:00.54 /usr/local/Cellar/mysql/5.6.21/bin/mysqld --basedir=/usr/local/Cellar/mysql/5.6.21 --datadir=/usr/local/var/mysql --plugin-dir=/usr/local/Cellar/mysql/5.6.21/lib/plugin --verbose --log-error=/usr/local/var/mysql/BOXNAME.local.err --pid-file=/usr/local/var/mysql/BOXNAME.local.pid
I'm not sure why that worked for me but it shows you where I got the my.cnf config file options from. You can also use the command line options to try to troubleshoot when starting mysqld manually.
If you do run manage to run MySQL server using mysqld_safe, you may have to do this to shut it down before trying the mysql.server bash helper. Resist the urge to kill -9 [PID] because you can corrupt your data.
mysqladmin -uroot shutdown
Good luck!
This worked for me:
sudo chmod -R 777 /usr/local/var/mysql/
sudo /usr/local/mysql/support-files/mysql.server start
This worked for me on 10.12.2 :
$ rm /usr/local/var/mysql/*.err
then
$ brew services restart mysql
If I remember correctly it is a permissions issue. Try to 'touch' and 'chmod' the pid file or the folder the file is held in.
My issue was that I started server as sudo once and then tried to restart as a local user.
Here mysql was not able to write to '.err' file owned by root.
I had to remove that file and restart the server:
sudo rm /usr/local/var/mysql/*.err
mysql.server start
Try this (OSX)
Step 1:
ps -aux | grep mysql
Then kill the 4 digits PID number
Step 2: kill 1965
Step 3: mysql.server start
Or having hard time to locate those PID numbers, try this below
Step 1 again: ps -aux | grep mysql
Step 2 again: killall
Step 3 again: mysql.server start
I’ve got a similar problem with MySQL on a Mac (Mac Os X Could not startup MySQL Server. Reason: 255 and also “ERROR! The server quit without updating PID file”). After a long trial and error process, finally in order to restore the file permissions, I’ve just do that:
launch the Disk Utilities.app
choose my drive on the left panel
click on the “Repair disk permissions” button
This did the trick for me. Hoping this can help someone else.
Find usr/local/var/mysql/your_computer_name.local.err file and understand the more information about error
Location : /usr/local/var/mysql/your_computer_name.local.err
It's probably problem with permissions
Find if mysql is running and kill it
ps -ef | grep mysql
kill -9 PID
where PID is second column value
2. check ownership of mysql
ls -laF /usr/local/var/mysql/
if it is owned by root, change it mysql or your user name

sudo chown -R mysql /usr/local/var/mysql/
For me it worked with:
unset TMPDIR
mysql_install_db --user=`whoami` --basedir="$(brew --prefix mariadb)" --datadir=/usr/local/var/mysql --tmpdir=/tmp
What worked for me was:
Go to your mysql installation directory
sudo chmod -R 777 data
Then go back one directory
cd support-files/
sudo ./mysql.server start
After that the server started running.
But the problem with this method is that I have to repeat this every time I want to start the mysql now. Don't know why it started behaving like this suddenly.
I had this problem on Linux, but the cause is relevant to any mysql installation. In my case, the server was crashing before startup was complete and the pid file updated. The error messages were seen when starting up mysqld directly instead of via "service mysql start".
In my case, the cause was the partition where the log files were located being full. Removing log files permitted mysql to start again. To test for this issue, go to the location of your mysql activity logs, and do df ..
If you have upgraded your mysql installation to 8.x, check if your previous version is supported for upgradation.
If not, mysql will not work! Uninstall your mysql along with all configuration files in /usr/local/var/mysql (remove the whole folder). Reinstall mysql.
NOTE: reinstalling might lead to loss of data.
Please check the log , you will get more detailed information .
Use the below command to tail the error log
tail -100 /usr/local/var/mysql/<user_name>.local.err
For me , one of the directory is missing , once created the server has started .
The key takeaway is to check the .err file, by default on Mac OSX it's in /usr/local/var/mysql.
That log filed revealed to me that I had to delete the following files:
ibdata1
ib_logfile0
ib_logfile1
Running MySQL with mysql.start worked successfully after that. Note that deleting those files will likely causes data loss.
sudo chmod -R 777 /usr/local/var/mysql/
works for me.
I had the same issue:
But the situation was, every time i try to enter:
/usr/local/mysql/support-files/mysql.server start
a file named localhost.pid is created instead of iMax0.local.pid which was stated in the error:
ERROR! The server quit without updating PID file (/usr/local/mysql/data/iMax0.local.pid).
Solution that works for me was copying localhost.pid and renaming it to iMax0.local.pid.
My solution on OSX El Capitan was:
sudo chmod ugo+w /tmp
It was broken suddenly.
The error was:
ERROR! The server quit without updating PID file
and the log showed:
Can't start server : Bind on unix socket: Permission denied
It might also be helpful to note, that under OSX there is no my.cnf file by default and not needed by default, which I did not know. Good luck!
$ sudo mysql.server restart
It works for me.
I had the similar issue. But the following commands saved me.
cd /usr/local/Cellar
sudo chown _mysql mysql
This is file permission problem.
Check disk permissions and repair.
Osx => Cmd+Space => Disk Utilty => Verify Disk Permissions.
Verify completed after Repair Disk Permissions.
mysql.server start command is worked succesfuly.
None of the answers worked for me. However, I simply did sudo mysql.server start and it worked nicely.
Also, for me, it did NOT show permissions issue in *.err file.
all solutions above doesn't work for me.
but they give me some clues to fix this error.
mysql.server start ----error The server quit without updating PID file
I installed mysql#5.7 on my macbook mojave with homebrew
brew install mysql#5.7
mysql error log located in /usr/local/var/mysql/IU.lan.err,there is one line in it:
Can't open and lock privilege tables: Table 'mysql.user' doesn't exist
after trying many posts in goole search engine,I turned to baidu
https://blog.csdn.net/xhool/article/details/52398042
inspired by this post,I found the solution:
rm /usr/local/var/mysql/*
mysqld --initialize
a random password for root user will be shown in bash.
but the command mysql -uroot -p[theRandomPassword] cant work.so I have to reset password.
create a init file with contents like this
SET PASSWORD FOR 'root'#'localhost' = PASSWORD('MyNewPass');
place it in any directory easy to find,such as Desktop
mysqld --init-file=[YourInitFile] &
many logs printed on your screen.
mysql -uroot -pMyNewPass
enjoy your high-version mysql!
Happened to me because I was actually switching from MariaDB to Mysql.
Switching back to MariaDB solved this.
I'm guessing the existing database wasn't compatible.
Solved this using sudo chown -R _mysql:_mysql /usr/local/var/mysql
Thanks to Matteo Alessani
This error may be actually being show because mysql is already started. Try to see the current status by:
mysql.server status