321

I installed MySQL on Mac OS X Mountain Lion with homebrew install mysql, but when I tried mysql -u root I got the following error:

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

What does this error mean? How can I fix it?

miken32
  • 42,008
  • 16
  • 111
  • 154
shrewdbeans
  • 11,971
  • 23
  • 69
  • 115
  • 4
    Didn't post it as an answer but you have to `install mysql-server` package aswell, not just `mysql` – Hanky Panky Mar 16 '13 at 13:57
  • You're right, Hanky Panky, I found a script that fully installs all you need for MySQL on my system (Mac OSX Mountain Lion) and that did the trick. I must have been missing a couple of things. – shrewdbeans Mar 18 '13 at 10:01
  • @shrewdbeans what script did you find that fully installs all MySQL dependencies on mac?? – Devin Rhode Nov 05 '15 at 22:19
  • 4
    @HankyPanky maybe that was true when you wrote it. But in 2016 Brew has no `mysql-server` to `install`. – jjpe Apr 05 '16 at 09:49
  • 63
    It's important to note that you **installed using Homebrew** so ignore the non-homebrew tips and start (and restart on startup) with `brew services start mysql` or (if you don't want a background service) `mysql.server start`. – Dave Everitt Jun 14 '17 at 15:31
  • find if `mysql.sock` exists in first place with `sudo find / -type s | grep mysql` – prayagupa Oct 29 '18 at 06:34
  • @prayagupd and if it doesn't exist, what to do? Cause I didn't find mine after a mysql crash due to big database. – KeitelDOG Dec 28 '18 at 20:12
  • @KeitelDOG ["The socket file is created when the service is started and removed when the service is terminated."](https://serverfault.com/questions/279366/what-should-mysqld-sock-contain-why-dont-i-have-it) and is mentioned in `/usr/local/etc/my.cnf` in MacOS would be in different place in other Linux distros. It should be present if you start mysql service again – prayagupa Dec 28 '18 at 20:41
  • 1
    I got it to work but with old normal mysql `5.7.19`. The new mysql@5.7 version `5.7.24` couldn't work because the some config reference was kept linked to the old mysql instead of the new brew Cellar mysql@5.7 Keg. So thanks I try this later – KeitelDOG Dec 28 '18 at 21:12
  • 2
    This error is also likely to happen after running `brew upgrade` which will install a newer version of mysql than previously installed. – johnsampson May 23 '19 at 17:47
  • worked for me . mysqld stop then brew services start mysql – vaibhavmaster Dec 16 '19 at 06:05
  • work - "brew services start mysql" – jonathasborges1 Nov 20 '21 at 17:13
  • I'm getting the same problem in Monterey and have tried every single suggestion on this page, including completely wiping out MySQL and the databases and reinstalling. Still getting the error. – dauber Mar 12 '22 at 04:13
  • check your mysql directory location and give the permission like sudo chown -R _mysql:mysql /-your-root-directories-/mysql for my pc it is sudo chown -R _mysql:mysql /opt/homebrew/var/mysql and then restart the mysql server sudo mysql.server start – pradeep _spidy Sep 01 '22 at 07:32

40 Answers40

228

You'll need to start MySQL before you can use the mysql command on your terminal. To do this, run brew services start mysql. By default, brew installs the MySQL database without a root password. To secure it run: mysql_secure_installation.

To connect run: mysql -uroot. root is the username name here.

Md Mazedul Islam Khan
  • 5,318
  • 4
  • 40
  • 66
178

This happened after the homebrew install and occurs due to permission issues. The following commands fixed the issue.

sudo chown -R _mysql:mysql /usr/local/var/mysql

sudo mysql.server start
Nirojan Selvanathan
  • 10,066
  • 5
  • 61
  • 82
  • 4
    you are awesome @nirojan, I was hitting my head to the wall :thumsup: – Ravi Sharma Feb 19 '18 at 07:33
  • Cool. I can solve my problem when change to another mac admin account :) – William Wong Garay Jul 12 '18 at 15:21
  • Thanks a million. I've been cracking my head for more than 5 hours now. Seen multiple answers on the internet and only this helped. – Stylishcoder Jul 16 '18 at 15:01
  • 1
    Kudos! But when I restarted my MacBook, I have the same issue. – Junior Gantin Sep 24 '18 at 09:45
  • On my Mac, I had to `chown -R myuser /usr/local/var/mysql` (where myuser is my username). That immediately triggered a dialog asking if mysql was allowed to have incoming connections. – FreshSnow Dec 09 '18 at 15:57
  • even if its not from brew the permission issues happens on many systems. – Talk is Cheap Show me Code Apr 22 '19 at 05:45
  • chown: /usr/local/var/mysql: No such file or directory From brew install notes: mysql@5.7 is keg-only, which means it was not symlinked into /usr/local, because this is an alternate version of another formula. – gvanto Dec 06 '19 at 12:43
  • 12
    I'm getting this: ` ERROR! The server quit without updating PID file (/var/lib/mysql/Saranshs-MacBook-Pro-2.local.pid).` OS: Catalyna mysql: 5.7.29 – saran3h Jan 20 '20 at 16:56
  • 4
    me too: Starting MySQL . ERROR! The server quit without updating PID file (/usr/local/var/mysql/localhost.pid). – Yvan Mar 10 '20 at 08:53
  • 8
    I got this error after run the commands `The server quit without updating PID file` – Duy Nguyen Aug 05 '20 at 15:27
  • Did not fix here. I got `ERROR! The server quit without updating PID file (/usr/local/var/mysql/XXX-XXX-XXX.local.pid)` – Victor Nov 24 '20 at 04:11
  • 3
    Nothing on this page is working for me after doing a brew uninstall of mysql@5.7 then install mysql@5.6 even though I followed brew's instructions to the letter. The error started after I rebooted the Mac (Big Sur). Changing permissions and restarting the brew service doesn't help. Changing them back to my username and group doesn't either. I get the updating PID file error as well. I'm stumped. It appears it's trying to pull from /tmp when Big Sur doesn't work like that. I'm not sure where to update that. – SteveExdia Jun 29 '21 at 20:23
  • worked for me. Thanks – Rafiq Jun 21 '23 at 18:05
148

It's probably because MySQL is installed but not yet running. [...] To verify that it's running, open up Activity Monitor and under "All Processes", search and verify you see the process "mysqld".

You can start it by installing "MySQL.prefPane".

The above quote is from the blog Obscured Clarity, "Install MySQL on Mac OS X", where you can also find the complete tutorial that I found most helpful.

blackgreen
  • 34,072
  • 23
  • 111
  • 129
shammerw0w
  • 1,931
  • 1
  • 13
  • 10
  • 139
    I just ran `mysqld` and that was all, this was an issue caused by _poor shutting down_ due to a sort of _hard reset/shut-down_ of the system. – ProfNandaa Oct 19 '15 at 12:08
  • 6
    None of the suggested methods worked. For me, it was running, however, there was a permission issue. Running `sudo chown -R _mysql:mysql /usr/local/var/mysql && sudo brew services restart mysql@5.7` solved the issue – FooBar Oct 26 '18 at 14:08
  • When looking in Activity Monitor, the mysqlId is running; to work around this just stop mysql then restart it. – JpersaudCodezit Nov 26 '19 at 14:43
  • 3
    ✅ For me was `sudo chown -R your_user /usr/local/var/mysql/ && mysql.server start` after a hard reset – Dan Palmieri Apr 23 '21 at 09:21
  • The brew service mysql@5.6 is running, and using `sudo chown -R _mysql:mysql /usr/local/var/mysql && sudo brew services restart mysql@5.6` didn't fix the issue. Changing them back to my perms and restarting didn't either. I had previously uninstalled mysql@5.7 then installed mysql@5.6 and added the .zshrc alias for mysql. On to the next SO answer :/ yay Mac – SteveExdia Jun 29 '21 at 20:20
52

Run: brew info mysql

And follow the instructions. From the description in the formula:

Set up databases to run AS YOUR USER ACCOUNT with:
    unset TMPDIR
    mysql_install_db --verbose --user=`whoami` --basedir="$(brew --prefix mysql)" --datadir=/usr/local/var/mysql --tmpdir=/tmp

To set up base tables in another folder, or use a different user to run
mysqld, view the help for mysql_install_db:
    mysql_install_db --help

and view the MySQL documentation:
  * http://dev.mysql.com/doc/refman/5.5/en/mysql-install-db.html
  * http://dev.mysql.com/doc/refman/5.5/en/default-privileges.html
Sunderam Dubey
  • 1
  • 11
  • 20
  • 40
Gaurav Agarwal
  • 14,664
  • 4
  • 29
  • 41
42

As others have pointed out this is because MySQL is installed but the service isn't running. There are many ways to start the MySQL service and what worked for me is the below.

To start the service:

  1. Go to "System Preference"
  2. At the bottom pane there should be MySql icon.
  3. Double click that to launch the 'MySQL Server Status' and press the button 'Start MySQL Server'

My env:

Mac Yosemite 10.10.3

Installed Package: /Volumes/mysql-advanced-5.6.24-osx10.8-x86_64

Ithar
  • 4,865
  • 4
  • 39
  • 40
  • @HosMercury can you confirm that you have MySQL installed – Ithar Mar 09 '17 at 12:08
  • I download and install mysql from official Mysql web page. This solution works for me. Thanks :) – 鄭元傑 Jul 20 '17 at 03:04
  • 1
    Hi, i downloaded and installed mysql from official web page as well, but in the preference pane the server is not activated (red dot), when I click 'start sql server' it turns 'green' for a second and back to red, nothing happens. I tried 'chown' , symlink to tmp/mysql.socket, uninstall/re-install, brew install mysql, but all failed. the brew install gives me an unsatisfied error, something about requiring Sierra or higher OS. I am running el capitan. Any help would be appreciated. – Spencer Trinh Dec 18 '18 at 14:14
34

Solutions revolve around:

  • changing MySQL's permissions

    sudo chown -R _mysql:mysql /usr/local/var/mysql
    
  • Starting a MySQL process

    sudo mysql.server start
    

Just to add on a lot of great and useful answers that have been provided here and from many different posts, try specifying the host if the above commands did not resolve this issue for you, i.e

mysql -u root -p h127.0.0.1
mondieki
  • 1,771
  • 3
  • 16
  • 24
28

The designated data directory /usr/local/var/mysql/ is unusable. You can remove all files that the server added to it.

MacOS:
$brew services stop mysql
$brew services list
$brew uninstall  mysql

$brew install mysql
$brew postinstall mysql

If Any error found then run those cmd
! Warning: this will delete any databases on this server:
$sudo rm -rf /usr/local/var/mysql
$sudo rm /usr/local/etc/my.cnf
$brew postinstall mysql


$brew services start mysql
$mysql_secure_installation
enter image description here Completed All process of secure installation then run
$mysql -u root -p

Congratulations you’ve just set up mysql!

andrewtweber
  • 24,520
  • 22
  • 88
  • 110
Israt Jahan Simu
  • 1,040
  • 13
  • 7
20

Warning - this method will remove all of your databases in the /usr/local/var/mysql folder

I had MySQL installed with Homebrew, and the only thing that fixed this for me was re-installing MySQL.

On my company laptop, I didn't have permission to uninstall MySQL from my computer via Homebrew:

$ brew uninstall mysql --ignore-dependencies
Uninstalling /usr/local/Cellar/mysql/8.0.12... (255 files, 233.0MB)
Error: Permission denied @ dir_s_rmdir - /usr/local/Cellar/mysql/8.0.12

So instead, I removed and reinstalled MySQL manually:

$ sudo rm -rf /usr/local/Cellar/mysql
$ brew cleanup
$ sudo rm -rf /usr/local/var/mysql
$ brew install mysql

And that worked!

Community
  • 1
  • 1
yndolok
  • 5,197
  • 2
  • 42
  • 46
19

Looks like your mysql server is not started. I usually run the stop command and then start it again:

mysqld stop
mysql.server start

Same error, and this works for me.

Prakhar Agarwal
  • 2,724
  • 28
  • 31
15

Below I'm including the latest instructions from brew install mysql so newer searches for this issue can benefit:

$ brew install mysql
==> Downloading https://homebrew.bintray.com/bottles/mysql-5.6.26.yosemite.bottle.1.tar.gz
######################################################################## 100.0%
==> Pouring mysql-5.6.26.yosemite.bottle.1.tar.gz

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

In my case I loaded mysql now via launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist and was then able to launch $ mysql and be on my way.

Sunderam Dubey
  • 1
  • 11
  • 20
  • 40
ggentzke
  • 341
  • 2
  • 6
12

This problem related to /usr/local/var/mysql folder access, I remove this folder and reinstall mysql.

  1. uninstall mysql with brew :

    brew uninstall mysql

  2. sudo rm -r /usr/local/var/mysql

  3. brew install mysql@8.0

  4. mysql -u root

This solution works fine for me! BUT YOU LOST ALL YOUR DATABASES! WARNING!

Sunderam Dubey
  • 1
  • 11
  • 20
  • 40
barsmaga
  • 155
  • 1
  • 7
  • 5
    This will more than likely fix the problem, however to future readers, be warned that this will wipe out all your databases. It's basically a hard re-install of MySQL. I know the context of the question was a fresh install, but some people that are scanning may just try this without knowing of the damage it could cause on an existing/production install. – efru Jun 13 '19 at 22:42
  • 2
    This isn't actually a solution. This is "Have you tried turning it on and off again?" – Berry M. Sep 24 '19 at 13:21
10

This fixed my issue when I restarted the mysql service. Just run:

brew services start mysql
Pang
  • 9,564
  • 146
  • 81
  • 122
pmventura
  • 157
  • 1
  • 2
  • 7
10

In my case it was simply a matter of deleting a lock file.

sudo rm -f /tmp/mysql.sock.lock
Brad Johnson
  • 111
  • 1
  • 3
  • I tired everything, several times installing, uninstalling, cleaning, purging, removing using brew in mac bigsur OS. Finally, this solution worked for me. Atleast I have moved further with and able to login in to MYSQL via terminal. Thank you! – Shivani Dec 02 '20 at 06:33
9

Ough, that took me a while to figure out. I saw it in a comment. After installing mysql using brew, and starting the service (perhaps using sudo brew services start mysql) then run:

$ mysqld

And MySQL should be running for your thereafter.

FooBar
  • 5,752
  • 10
  • 44
  • 93
7

For me it was simple as running:

/usr/local/opt/mysql/bin/mysqld_safe

instead of mysqld

Kenny Cason
  • 12,109
  • 11
  • 47
  • 72
  • 1
    This worked for me. Not sure why, but it may be related to a Mac OS restart bug on my machine – kraftydevil Jun 11 '20 at 01:48
  • turns out I need to run this command every time I restart my machine. I'm happy I have something to get it up and running, but I wish there was something more persistent – kraftydevil Aug 17 '20 at 16:32
4

After working on this for several hours what worked for me was go to /etc/mysql/ and edit the my.cnf file. Add the following

[client]
port = 3306
socket = /var/run/mysqld/mysqld.sock
Jackstine
  • 486
  • 4
  • 12
  • 1
    This did the trick for me too, though for my os/mysql version it was: /etc/my.conf, and the socket was in /var/lib/mysql/mysql.sock /var/log/mysqld.log should point you to where the socket file is. – keithpjolley Jun 10 '17 at 23:34
  • Add skip_ssl in the same file if it doesn't work – Patrick Aug 24 '21 at 10:15
  • This worked for me for rh7.9. only file path and socket path was different. file path : /etc/my.conf socket path : /var/lib/mysql/mysql.sock which can be search using sudo find / -type s command – DevMJ Jun 01 '23 at 17:52
4

I went through this issue and I managed to run mysql server using below solution

Install mysql through .dmg(https://dev.mysql.com/downloads/mysql/5.7.html), you will get mysql service panel in system preferences then start mysql from the panel and try

mysql -u root -p

Images attached for reference

System Preferences

Mysql panel

Aravind Vemula
  • 1,571
  • 17
  • 22
4

just hit "brew services start mysql" in terminal

Abdulrahman Masoud
  • 1,096
  • 8
  • 12
3

I found the solution to my problem. It was indeed because my MySQL server was not running.

It was caused by MySQL not being correctly set up on my machine, thus not being able to run.

To remedy this, I used a script which installs MySQL on Mac OSX Mountain Lion, which must have installed missing files.

Here is the link: http://code.macminivault.com/

Important Note: This script sets the root password as a randomly generated string, which it saves on the Desktop, so take care not to delete this file and to note the password. It also installs MySQL manager in your system preferences. I'm also not sure if removes any existing databases, so be careful about that.

shrewdbeans
  • 11,971
  • 23
  • 69
  • 115
3

AFTER USING ALL THE ABOVE SOLUTIONS, NOTHING WORKED FOR ME BUT THIS WORKED.

I you have installed MySQL using HomeBrew then check System Preferences > MySQL in your mac that MySQL Server is stopped if it is running stop itenter image description here by clicking on Stop MySQL Server and start MySQL from terminal writing the command mysqlserver.start.

If it doesn't work you can also try:-

If you have also installed MySQL workbench then just uninstall MySQL workbench and MySQL and after that install MySQL first and then MySQL workbench.

Mohit Chachra
  • 81
  • 1
  • 5
2

I would recommend you to run

  mysql.server start

before going to

  mysql -u root -p

so as to make sure that the mysql server is running before trying to login into it

This happens many times what you start/restart a machine where by no mysql server is running.

mwangaben
  • 877
  • 10
  • 11
2

Probably you might have faced some issues during the homebrew mysql installation and mysql services might not be running. If that is the case, then it might be worth trying below steps to reinstall mysql properly and then try to connect.

sudo chown -R $(whoami) /usr/local/var

sudo chown -R $(whoami) /Library/Caches/Homebrew

brew uninstall mysql

brew install mysql

mysql.server start   

mysql -uroot  
buddemat
  • 4,552
  • 14
  • 29
  • 49
jlawrence
  • 21
  • 2
1

I have tried every possible way to solve this issue, like ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock, uninstall and reinstall mysql, make sure mysql is running on xampp but none of it still worked.

Finally, I open up my.cnf (config file) and copy the socket path (make sure to copy the full path else it won't work). Then I perform this command in my terminal

mysql --socket=/Applications/XAMPP/xamppfiles/var/mysql/mysql.sock

Lo, and behold, mysql launchs.

This solution will only work if your MySQL is shown running on Xampp/Ampps, but in terminal it is still not connecting to the right socket when you have already attempted something like:

./mysql -u root

or

brew services start mysql
Sunderam Dubey
  • 1
  • 11
  • 20
  • 40
Kate Lee
  • 69
  • 8
  • I also tried every suggested solution from this post, and it has not worked. Do you need xampp installed? i am not familiar with this. I only installed mysql server GPL version from official website (.DMG). I don't believe I have this app--XAMPP. Can you please elaborate? Thanks. – Spencer Trinh Dec 18 '18 at 14:24
  • `brew services start mysql` is the one worked for me. Thanks – davthecoder Aug 01 '23 at 11:26
1

I keep coming back to this post, I've encountered this error several times. It might have to do with importing all my databases after doing a fresh install.

I'm using homebrew. The only thing that used to fix it for me:

sudo mkdir /var/mysql
sudo ln -s /tmp/mysql.sock /var/mysql/mysql.sock

This morning, the issue returned after my machine decided to shut down overnight. The only thing that fixed it now was to upgrade mysql.

brew upgrade mysql
jnaklaas
  • 1,619
  • 13
  • 16
1

After trying many solutions, seems like the one that finally did the trick was to connect by IP. No longer file sockets getting deleted randomly.

Just update your MySQL client config (e.g. /usr/local/etc/my.cnf) with:

[client]
port = 3306
host=127.0.0.1
protocol=tcp
Nicodemuz
  • 3,539
  • 2
  • 26
  • 32
1

Homebrew will absolutely never repair the permissions using a standard reinstall, and chasing down which folder/file is corrupted will take longer than it is worth.

In this case - blow away the mysql install manually and reinstall via homebrew. Takes about 2 minutes.

cd /usr/local/var

sudo rm -rf mysql

brew install mysql

Homebrew installs mysql insecure by default, so if you want a password:

mysql_secure_installation

Then fire it up.

mysql -uroot

etusm
  • 4,082
  • 1
  • 30
  • 26
1

After installing MySQL on my mac m1 macOS Monterey, using brew install mysql I got this info:

[System] [MY-013169] [Server] /opt/homebrew/Cellar/mysql/8.0.27_1/bin/mysqld (mysqld 8.0.27) initializing of server in progress as process 3624

[ERROR] [MY-010457] [Server] --initialize specified but the data directory has files in it. Aborting.

[ERROR] [MY-013236] [Server] The designated data directory /opt/homebrew/var/mysql/ is unusable. You can remove all files that the server added to it.

[ERROR] [MY-010119] [Server] Aborting

[System] [MY-010910] [Server] /opt/homebrew/Cellar/mysql/8.0.27_1/bin/mysqld: Shutdown complete (mysqld 8.0.27)  Homebrew.

and this warning:

Warning: The post-install step did not complete successfully You can
try again using:   brew postinstall mysql

After that I try to start MySQL using brew services start mysql, and I got this error:

ERROR 2002 (HY000): Can't connect to local MySQL server through socket
'/tmp/mysql.sock' (2)

I managed to fix it using:

> rm -rf ~/opt/homebrew/var/mysql/
> brew postinstall mysql

Now you can connect with mysql -uroot or mysql -uroot -p.

Ivan
  • 189
  • 2
  • 3
0

only this has made the trick for me brew services start --all (after trying all answers)

0

I managed to solve this issue by changing localhost to 127.0.0.1

  • Can you add some details to this, like what config file did you change? What was the previous value. The phrase "changing localhost to 127.0.0.1" sounds like you are editing your `/etc/hosts` file and it should already be 127.0.0.1 . – silicontrip Feb 13 '21 at 22:17
  • On your command add ip address instead of localhost mysql -h 127.0.0.1 -u root -p – Mkhululi Cooper Ncube Kamzilan Feb 14 '21 at 17:10
0

For my case, just specify host as 127.0.0.1, instead of localhost:

$ bin/mysql -uroot -p -h127.0.0.1
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.26

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>
Liu Yan
  • 63
  • 4
0

if you are using Kali linux you might want to specify the host explicitly

do that with mysql -h 127.0.0.1 -u root where 127.0.0.1 is your localhost

0

None worked. I just reinstall mysql (don't worry your data is stay untouched).

then start using

sudo mysql.server start

That's all. brew services mysql start not starting mysql.

On MacOS Monterey.

imikay
  • 742
  • 1
  • 8
  • 17
  • thanks for your suggestion. It got a progress on my Mac. However, I still run into another error. like the following. ➜ ~ sudo mysql.server start Starting MySQL .Logging to '/opt/homebrew/var/mysql/HHT-Notebook.local.err'. . ERROR! The server quit without updating PID file (/opt/homebrew/var/mysql/HHT-Notebook.local.pid). – Hong Sep 29 '22 at 19:31
-1

In my case right after installing the MAMP accessing mysql from the terminal was giving the same socket error. At the end all it wanted was a restart and it's working.

Diwaker Tripathi
  • 438
  • 3
  • 12
-1

A lot of other helpful responses here, but nothing fixed this for me. Ultimately nothing I found on this site or others would get any version of MySQL from Homebrew working for me.

It was super painless to just download the DMG from https://dev.mysql.com/downloads/file/?id=479114 (find the appropriate version you need) and let the wizard install it for me. The only other manual step was adding /usr/local/mysql/bin to my PATH.

I'd recommend this option if brew is giving you trouble.

Update - if this still doesn't fix it, try completely purging mysql before installing via DMG. Follow these instructions: https://gist.github.com/vitorbritto/0555879fe4414d18569d

Patrick
  • 1,227
  • 14
  • 17
  • i installed via the DMG file too, but i still get this socket error. mysql --version works for me and --help, but nothing else. I added to path in order to get the --version and --help commands to work. can you please provide some advice? thanks. – Spencer Trinh Dec 18 '18 at 14:19
  • See the update about purging mysql first. That's been fixing it for myself and several coworkers. – Patrick Dec 25 '18 at 17:18
-1

Try this

rm -rf /usr/local/var/mysql && brew postinstall mysql@5.7 && brew services restart mysql@5.7
Golam Sorwar
  • 1,255
  • 15
  • 12
-1

Encountered a similar problem after upgrading to Catalina OS. After running mysqld command, I found that there was some issue with the logs file. It could be different for others.

$ mysqld

Issue was

2019-10-16T04:58:59.174474Z 0 [ERROR] Could not open file '/var/log/mysql/error.log' for error logging: No such file or directory
2019-10-16T04:58:59.174508Z 0 [ERROR] Aborting

Resolved it by creating it and applying proper permissions.

sudo mkdir -p /var/log/mysql
sudo touch /var/log/mysql/error.log
sudo chown -R _mysql:mysql /var/log/mysql/

Restart MySQL

brew services restart mysql@5.7

Issue was resolved.

mysql -uroot -proot
Saif Khan
  • 1
  • 2
-1

Running sudo chown _mysql /usr/local/var/mysql/* helped me finally after trying multitude of options from all these SO answers. The issue with permissions probably arose from improper shutdown of the machine.

Nasif Imtiaz Ohi
  • 1,563
  • 5
  • 24
  • 45
-1

If you are on OSX and have XAMPP,then please follow these steps:

Thanks to Jackstine's answer, I was able to do the following:

$ cat ~/.my.cnf

[mysql]

# CLIENT #
port                           = 3306
socket                         = /Applications/XAMPP/xamppfiles/var/mysql/mysql.sock

I hope this helps me again when I forget, in the future!

Felipe Valdes
  • 1,998
  • 15
  • 26
-1

1)->First start the SQL server 2)(if not exists)you have to create an 'etc' dir at where you installed mysql->in that create a file named 'mysql.sock'. 3)then execute the below line

 ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock

4)restart the server

5)and find the path for 'mysql.sock' by executing below line

mysql -u root -p -h 127.0.0.1 -e "select @@socket"

now you can see the path ->copy that path 6)after copied execute the below line

mysql -u (username) -p -S (paste the path you copied)

7)Now ,it works.

Babiyan
  • 1
  • 2
-4
  1. Uninstall MySQL.
  2. Remove /usr/local/var/mysql/.
  3. Install MySQL.
Grant Miller
  • 27,532
  • 16
  • 147
  • 165
Amod Kulkarni
  • 51
  • 1
  • 3
  • 2
    Will this not blow away all databases you may have? Seems like a rather heavy-handed solution to me, especially considering it's probably just a problem of MySQL not running. – Martin Tournoij Aug 21 '18 at 23:33
  • yes it will , but as per the question , this was a fresh install and hence the assumption was that there would ot be any databases. – Amod Kulkarni Feb 10 '19 at 16:36