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 vĩ đại local MySQL server through socket '/tmp/mysql.sock' (2)
What does this error mean? How can I fix it?
miken32
42.7k16 gold badges121 silver badges169 bronze badges
asked Mar 16, 2013 at 13:53
shrewdbeansshrewdbeans
12.5k24 gold badges76 silver badges117 bronze badges
16
You'll need vĩ đại start MySQL before you can use the mysql
command on your terminal. To tự this, lập cập brew services start mysql
. By mặc định, 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.
answered Aug 6, năm nhâm thìn at 14:13
mmikmmik
5,9354 gold badges47 silver badges74 bronze badges
6
This happened after the homebrew install and occurs due vĩ đại permission issues. The following commands fixed the issue.
sudo chown -R _mysql:mysql /usr/local/var/mysql
sudo mysql.server start
answered Nov 22, năm nhâm thìn at 8:25
13
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", tìm kiếm 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♦
43.7k28 gold badges154 silver badges150 bronze badges
answered Jan 29, năm trước at 5:12
shammerw0wshammerw0w
1,9861 gold badge13 silver badges10 bronze badges
5
Run: brew info mysql
And follow the instructions. From the mô tả tìm kiếm in the formula:
Set up databases vĩ đại lập cập 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 mix up base tables in another thư mục, or use a different user vĩ đại 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
answered Mar 16, 2013 at 14:02
Gaurav AgarwalGaurav Agarwal
14.8k4 gold badges30 silver badges42 bronze badges
As others have pointed out this is because MySQL is installed but the service isn't running. There are many ways vĩ đại start the MySQL service and what worked for bu is the below.
To start the service:
- Go vĩ đại "System Preference"
- At the bottom pane there should be MySql icon.
- Double click that vĩ đại 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
answered May 6, năm ngoái at 12:04
ItharIthar
5,3854 gold badges44 silver badges41 bronze badges
3
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 vĩ đại 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
answered Mar 27, 2017 at 15:51
mondiekimondieki
1,9714 gold badges18 silver badges24 bronze badges
5
The designated data directory /usr/local/var/mysql/ is unusable. You can remove all files that the server added vĩ đại it.
MacOS:
$brew services stop mysql
$brew services list
$brew uninstall mysql
$brew install mysql
$brew postinstall mysql
If Any error found then lập cập 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
Completed All process of secure installation then run
$mysql -u root -p
Congratulations you’ve just mix up mysql!
andrewtweber
25.5k22 gold badges91 silver badges111 bronze badges
answered Dec 22, 2020 at 17:15
3
Looks lượt thích your mysql server is not started. I usually lập cập the stop command and then start it again:
mysqld stop
mysql.server start
Same error, and this works for bu.
answered Apr 14, 2017 at 8:27
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 bu was re-installing MySQL.
On my company máy tính, I didn't have permission vĩ đại 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!
answered Aug 8, 2018 at 1:56
yndolokyndolok
5,5773 gold badges45 silver badges47 bronze badges
1
Below I'm including the latest instructions from brew install mysql
so sánh 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 vĩ đại 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 vĩ đại launch $ mysql
and be on my way.
answered Oct 1, năm ngoái at 21:41
ggentzkeggentzke
3512 silver badges6 bronze badges
This problem related vĩ đại /usr/local/var/mysql
thư mục access, I remove this thư mục and reinstall mysql.
uninstall mysql with brew :
brew uninstall mysql
sudo rm -r /usr/local/var/mysql
brew install [email protected]
mysql -u root
This solution works fine for me! BUT YOU LOST ALL YOUR DATABASES! WARNING!
answered May 30, 2019 at 6:48
barsmagabarsmaga
1751 silver badge7 bronze badges
2
In my case it was simply a matter of deleting a lock tệp tin.
sudo rm -f /tmp/mysql.sock.lock
answered Jun 7, 2018 at 17:24
3
This fixed my issue when I restarted the mysql service. Just run:
brew services start mysql
Pang
10k146 gold badges85 silver badges124 bronze badges
answered May 2, 2017 at 3:55
pmventurapmventura
1671 gold badge2 silver badges7 bronze badges
Ough, that took bu a while vĩ đại 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.
answered Oct 10, 2018 at 18:40
FooBarFooBar
6,07011 gold badges50 silver badges104 bronze badges
For bu it was simple as running:
/usr/local/opt/mysql/bin/mysqld_safe
instead of mysqld
answered Mar 15, 2017 at 20:34
Kenny CasonKenny Cason
12.3k11 gold badges49 silver badges73 bronze badges
2
After working on this for several hours what worked for bu was go vĩ đại /etc/mysql/ and edit the my.cnf tệp tin. Add the following
[client]
port = 3306
socket = /var/run/mysqld/mysqld.sock
answered May 9, 2017 at 23:03
JackstineJackstine
4844 silver badges12 bronze badges
3
I went through this issue and I managed vĩ đại lập cập 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
answered Jun 24, 2019 at 9:21
Aravind VemulaAravind Vemula
1,6901 gold badge19 silver badges23 bronze badges
just hit "brew services start mysql" in terminal
answered Oct 16, 2020 at 21:37
I found the solution vĩ đại my problem. It was indeed because my MySQL server was not running.
It was caused by MySQL not being correctly mix up on my machine, thus not being able vĩ đại lập cập.
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 sánh take care not vĩ đại delete this tệp tin and vĩ đại note the password. It also installs MySQL manager in your system preferences. I'm also not sure if removes any existing databases, so sánh be careful about that.
answered Mar 18, 2013 at 9:59
shrewdbeansshrewdbeans
12.5k24 gold badges76 silver badges117 bronze badges
I would recommend you vĩ đại lập cập
mysql.server start
before going vĩ đại
mysql -u root -p
so as vĩ đại make sure that the mysql server is running before trying vĩ đại login into it
This happens many times what you start/restart a machine where by no mysql server is running.
answered Oct 13, 2019 at 7:15
mwangabenmwangaben
95710 silver badges12 bronze badges
AFTER USING ALL THE ABOVE SOLUTIONS, NOTHING WORKED FOR ME BUT THIS WORKED.
I you have installed MySQL using HomeBrew then kiểm tra System Preferences > MySQL in your mac that MySQL Server is stopped if it is running stop it 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.
answered May 7, 2021 at 7:53
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 vĩ đại reinstall mysql properly and then try vĩ đại 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
5,26316 gold badges34 silver badges60 bronze badges
answered Nov 15, 2021 at 19:52
2
After trying many solutions, seems lượt thích the one that finally did the trick was vĩ đại connect by IP. No longer tệp tin 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
answered Dec 6, 2019 at 6:10
NicodemuzNicodemuz
4,0342 gold badges28 silver badges32 bronze badges
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 vĩ đại the MySQL monitor. Commands over 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' vĩ đại clear the current input statement.
mysql>
answered Aug 13, 2021 at 10:03
1
I have tried every possible way vĩ đại solve this issue, lượt thích 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 vĩ đại 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 vĩ đại the right socket when you have already attempted something like:
./mysql -u root
or
brew services start mysql
answered Oct 17, 2018 at 11:48
2
only this has made the trick for me
brew services start --all
(after trying all answers)
answered Aug 21, 2019 at 21:44
1
I keep coming back vĩ đại this post, I've encountered this error several times. It might have vĩ đại tự with importing all my databases after doing a fresh install.
I'm using homebrew. The only thing that used vĩ đại 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 vĩ đại shut down overnight. The only thing that fixed it now was vĩ đại upgrade mysql.
brew upgrade mysql
answered Oct 15, 2019 at 8:02
jnaklaasjnaklaas
1,74915 silver badges17 bronze badges
I managed vĩ đại solve this issue by changing localhost vĩ đại 127.0.0.1
answered Feb 13, 2021 at 15:08
2
Homebrew will absolutely never repair the permissions using a standard reinstall, and chasing down which folder/file is corrupted will take longer phàn nàn 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 mặc định, so sánh if you want a password:
mysql_secure_installation
Then fire it up.
mysql -uroot
answered Dec 6, 2021 at 2:12
etusmetusm
4,1801 gold badge31 silver badges27 bronze badges
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 vĩ đại 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 vĩ đại start MySQL using brew services start mysql
, and I got this error:
ERROR 2002 (HY000): Can't connect vĩ đại local MySQL server through socket
'/tmp/mysql.sock' (2)
I managed vĩ đại fix it using:
> rm -rf ~/opt/homebrew/var/mysql/
> brew postinstall mysql
Now you can connect with mysql -uroot
or mysql -uroot -p
.
answered Dec 29, 2021 at 17:44
IvanIvan
2093 silver badges4 bronze badges