Cannot start MySQL on Mac - Permission denied - mysql

I am trying to run MySQL installed through HomeBrew on a Mac (High Sierra) but I am always having these problems of permissions and with the PID file. I have tried hundreds of possible solutions I found online, but I could not fix these issues:
Haline:/ Haline$ mysql.server start
Starting MySQL
./usr/local/Cellar/mysql/8.0.12/bin/mysqld_safe: line 144: /usr/local/var/mysql/Haline.local.err: Permission denied
/usr/local/Cellar/mysql/8.0.12/bin/mysqld_safe: line 144: /usr/local/var/mysql/Haline.local.err: Permission denied
/usr/local/Cellar/mysql/8.0.12/bin/mysqld_safe: line 199: /usr/local/var/mysql/Haline.local.err: Permission denied
/usr/local/Cellar/mysql/8.0.12/bin/mysqld_safe: line 144: /usr/local/var/mysql/Haline.local.err: Permission denied
ERROR! The server quit without updating PID file (/usr/local/var/mysql/Haline.local.pid).
Can anyone help me, pleeease?

According to the official troubleshooting page of Homebrew:
If commands fail with permissions errors, check the permissions of /usr/local’s subdirectories. If you’re unsure what to do, you can run cd /usr/local && sudo chown -R $(whoami) bin etc include lib sbin share var opt Cellar Caskroom Frameworks.
Alternatively, if you have not installed applications in /usr/local that rely on specific permissions, you can also run:
sudo chown -R $(whoami) /usr/local/*

Related

ERROR 2002 (HY000) while using brewed mysql

I was using MAMP and have removed it completely from my MAC OS.
Post this,
I installed mysql5.7 using brew
Added mysql path to zshrc / bash profile
Started mysql service using brew services start mysql#5.7
Now when I try to access mysql on command line it gives me error ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/Applications/MAMP/tmp/mysql/mysql.sock' (2)
Where as I have already added socket path to /tmp/mysql.sock in my.cnf as well as tried creating symlink of same to ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/Applications/MAMP/tmp/mysql/mysql.sock' (2)
but no luck.
Advice on same will be highly appreciated!
this is a sign that the server did not really start.
Run:
ps aux|grep mysql
If you find a mysql server process , there are chances is not correctly installed.
the best is to uninstall, if you don't have anything important in the database and reinstall it again . You could try reinstall , but this is usually not fixing the issue.
brew services list
brew uninstall mysql#YOUR_VERSION
brew install mysql#DESIRED_VERSION
[1] I faced a similar issue a few weeks ago, the fix was changing my brew permissions. Try some of the answers in this stackoverflow answer and the rest of the thread:
sudo chown -R $(whoami) $(brew --prefix)/*
[2] Brew tells you a bunch of folders having permission issues and the fix for each of them. Run commands mentioned in brew doctor and it should work. Here is what my brew doctor had to say:
You should change the ownership of these directories to your user.
> sudo chown -R $(whoami) /usr/local/Cellar /usr/local/Frameworks /usr/local/Homebrew /usr/local/bin /usr/local/etc /usr/local/etc/bash_completion.d /usr/local/include /usr/local/lib /usr/local/lib/pkgconfig /usr/local/lib/python3.7/site-packages /usr/local/opt /usr/local/sbin /usr/local/share /usr/local/share/aclocal /usr/local/share/doc /usr/local/share/info /usr/local/share/locale /usr/local/share/man /usr/local/share/man/man1 /usr/local/share/man/man3 /usr/local/share/man/man5 /usr/local/share/man/man7 /usr/local/share/man/man8 /usr/local/share/zsh /usr/local/share/zsh/site-functions /usr/local/var/homebrew/linked /usr/local/var/homebrew/locks /usr/local/var/log
And make sure that your user has write permission.
> chmod u+w /usr/local/Cellar /usr/local/Frameworks /usr/local/Homebrew /usr/local/bin /usr/local/etc /usr/local/etc/bash_completion.d /usr/local/include /usr/local/lib /usr/local/lib/pkgconfig /usr/local/lib/python3.7/site-packages /usr/local/opt /usr/local/sbin /usr/local/share /usr/local/share/aclocal /usr/local/share/doc /usr/local/share/info /usr/local/share/locale /usr/local/share/man /usr/local/share/man/man1 /usr/local/share/man/man3 /usr/local/share/man/man5 /usr/local/share/man/man7 /usr/local/share/man/man8 /usr/local/share/zsh /usr/local/share/zsh/site-functions /usr/local/var/homebrew/linked /usr/local/var/homebrew/locks /usr/local/var/log

ERROR! The server quit without updating PID file on El captian

I have problem mysql starting, i was update to El captian on mac.
In terminal,
brew install mysql
mysql.server start
but it not working
this is error message.
Starting MySQL... ERROR! The server quit without updating PID file(/usr/local/var/mysql/Heo-MacBook-Pro.local.pid).
help me please!
I had the same problem using brew command to start mysql service.
If you are using MacOS, go to System Preferences and click on MySQL icon. Probably you'll see information message about permission denied in some directories. All you need to do is to give permission to that.
That's worked for me.
Open your terminal
Execute this command: sudo chown -R mysql /usr/local/mysql/data
Try this first:
/usr/local/var/mysql/support-files/mysql.server restart
If that doesn’t fix
Remove or backup the /etc/my.cnf
also try this method:
sudo /usr/local/var/mysql/support-files/mysql.server start
Starting MySQL
. ERROR! ....................
remove the .err files like so:
rm *.err /usr/local/var/mysql/data/
Solution working for my case:
Check your error log at /usr/local/var/mysql/Heo-MacBook-Pro.local.err
If there is something like this in the log: ...[Note] Unable to delete pid file: Permission denied..., which means mysql does not have the permission to your mysql folder
Use the following command in terminal to grant the permission: sudo chown -R mysql /usr/local/var/mysql/
The Problem could also be a version mismatch. My db was installed with Homebrew as version 5, later unintentionally upgraded to version 8.
Check the most recent error log at /usr/local/var/mysql/<your-computers-name.some.domain>.err
You can conveniently read the last couple of lines (e.g. 40) of the file with tail -n 40 <your-computers-name.some.domain>.err
You may find a hint about upgrading istructions in this case.

Systemwide permission problems

I've been installing Node, NVM, NPM and some other tools lately on my MacBook. After a while, suddenly, I discovered that mysqld wasn't booting anymore due to the following:
Operating system error number 13 in a file operation. The error means mysqld does not have the access rights to the directory.
I figured I should reinstall mysql with brew, but doing that led to:
$ brew remove mysql
Uninstalling /usr/local/Cellar/mysql/5.6.17_1...
Error: Permission denied - /usr/local/include/mysql
Than tried:
$ brew cleanup
Removing: /usr/local/Cellar/openssl/1.0.1g...
Error: Permission denied - /usr/local/Cellar/openssl/1.0.1g/bin/c_rehash
Also installing fails:
$ brew install mysql
Error: Cannot write to /usr/local/Cellar
I didn't change anything to brew or it's directories, so this problem is coming from somewhere else. I remember when installing NVM I made some changes to permissions, but can't remember exactly what is was..
Turns out in the past I changed the owner of /usr/local. Changing it back to whoami did the trick..

Permission denied while creating a symbolic link

I am installing mysql using homebrew for Mac OS X. Once the installation completes these options are given in the terminal:
To connect:
mysql -uroot
To have launchd start mysql at login:
ln -sfv /usr/local/opt/mysql/*.plist ~/Library/LaunchAgents
Then to load mysql now:
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
Or, if you don't want/need launchctl, you can just run:
mysql.server start
So what I would like to do is have mysql started at login but when I enter the command I get permission denied like so:
$ ln -sfv /usr/local/opt/mysql/*.plist ~/Library/LaunchAgents
ln: /Users/xxxxxxxxxxxxxx/Library/LaunchAgents/homebrew.mxcl.mysql.plist: Permission denied
Any suggestions as to why this may be occuring?
Did you try sudo?
$ sudo ln -sfv /usr/local/opt/mysql/*.plist ~/Library/LaunchAgents
^^^^
I have similar issue while trying to run ln -s /Applications/ngrok ngrok. It returns permission denied. That means you need to allow Administrator to delegate a user to perform the operation. By prepending sudo will give that privilege and the system will prompt you for administrator password. sudo ln -s /Applications/ngrok ngrok
For more information on sudo.
This happened to me on a web server where I have limited access (no sudo), so what worked for me was putting the symbolic link under /home//bin instead. I was able to install custom apps that I needed and setup them to work globally in this way. Hope this might help someone.

Not able to get mysql running on my mac

I'm trying to install mysql on my mac but unable to start server. When I try to start mysql server, I get this error in the logs: Can't start server: can't create PID file: Permission denied. Can't create/write to file ~/Downloads/mysql-5.5.32-osx10.6-x86_64/data/HOSTNAME.pid. I have symlinked /usr/local/mysql to ~/Downloads/mysql-5.5.32-osx10.6-x86_64. And all files/directories under /usr/local/mysql and ~/Downloads/mysql-5.5.32-osx10.6-x86_64 are owned by mysql. I'm trying start mysql server as root. Searched everywhere for this, but no luck. I tried with mysql 5.5 and 5.6. Same problem with both the versions. Any clues?
I'd highly recommend you install mysql using Homebrew. To do this:
ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/go)"
brew install mysql
The output of the second command may give you a few extra steps. Follow them and you should be set.
You have to start it as an administrator. Write sudo and a space followed by the command you will use to start MySQL.
Use below permission to grant permissions:
check your mysqld location, mine is this:
do this:
ls -ld /usr/local/var/mysql
sudo chmod a+w /usr/local/var/mysql