ERROR 2002 (HY000) while using brewed mysql - 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

Related

Can't find mysqld.sock: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2 "No such file or directory")

I've just registered to Stack Overflow because I really can't get out of this problem since 2 days ago. I use Xampp.
So, I'm following this Laravel tutorial and when from the terminal I type in the project directory or every elsewhere directory mysql or mysql -uroot -p it gives me this error:
Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2 "No such file or directory")
I have mariadb that I've installed from https://mariadb.org/
My OS is Ubuntu 16.04 LTS ( here I typed lsb_release -a )
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 16.04.2 LTS
Release: 16.04
Codename: xenial
By doing cd /var/run/ and then ll I discovered that the directory /var/run/mysqld doesn't exist, and the mysql.sock file neither.
So I googled a bit and I found this where they talk about the /etc/my.cnf file but I discovered by doing some cd commands that I don't have even this file. ( But I've just noticed that I have a /etc/mysql/my.cnf and /etc/mysql/my.cnf.fallback file )
Anithing else ? Oh, yes. Uninstalling mariadb and installing mysql would not resolve the problem because I have issues with the dpkg packages.
I also tried a lot of times installing and uninstalling xamp, laravel dir, mysql, mariadb...
I don't really know what to do. :(((
I got it!
So, first I removed every trace of MariaDB with these commands:
sudo service mysql stop
sudo apt-get --purge remove "mysql*
sudo rm -rf /etc/mysql/
Then I reinstalled it:
apt-get update
apt-get upgrade
apt-get install mariadb-server
Now mariaDB works. However I still have problems with xampp because his Mysql database has a conflict with my mariaDB. So I changed the Xampp Mysql port from 3306 to 3308 and all works fine.

MySQL (mysql_secure_installation) won't work after installing through homebrew: Can't connect through socket

When just installing mysql on OSX through homebrew like so: brew install mysql and I try to run the command mysql_secure_installation as brew suggests, it just gives me the following error:
Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
I tried ALL SOLUTIONS from this thread: Can't connect to local MySQL server through socket homebrew
But alass nothing solved my problem. Any advice to debug?
When I try to check the existance of the socket file:
ls -al /tmp/mysql.sock
It says: No such file or directory.
Did Homebrew maybe forget to install something?
Often this is because of permissions, did you try?
sudo chown -R _mysql:mysql /usr/local/var/mysql
sudo mysql.server start

ERROR! The server quit without updating PID file (/usr/local/mysql/data/Mac.local.pid)

After install, run fine mysql and restart my mac, i get this error, when i call this command line:
sudo /usr/local/mysql/support-files/mysql.server start
Hier the error:
ERROR! The server quit without updating PID file (/usr/local/mysql/data/Mac.local.pid).
And when i try to connect me to mysql -u root -p, this error:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
I try the solution in this link
MySQL does not start when upgrading OSX to Yosemite or El Capitan, but nothing. I also try to change the owner of the mysql folder with:
sudo chown -R _mysql:_mysql /usr/local/mysql/
But nothing.
Any ideas?
Thank
start your mysql in safe_mode.its working for me. hope it would work also for you
/usr/local/mysql/bin/mysqld_safe start
I had to uninstall mysql
brew uninstall mysql#5.7
and reinstall again
brew install mysql#5.7
When I check my terminal I could see this warning
[ERROR] --initialize specified but the data directory has files in it. Aborting.
then I had to do this
rm -rf /usr/local/var/mysql
and open my.cnf like this
nano /usr/local/etc/my.cnf
and remove this line mysqlx-bind-address = 127.0.0.1
then do the post-install like this
brew postinstall mysql#5.7
Which finally worked. I had wasted a whole day on this. Hope someone finds this useful.

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

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

This question already has answers here:
Can't connect to local MySQL server through socket '/var/mysql/mysql.sock' (38)
(43 answers)
Closed 21 days ago.
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?
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.
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
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.
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
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:
Go to "System Preference"
At the bottom pane there should be MySql icon.
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
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
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
Completed All process of secure installation then run
$mysql -u root -p
Congratulations you’ve just set up mysql!
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!
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.
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.
This problem related to /usr/local/var/mysql folder access, I remove this folder and reinstall mysql.
uninstall mysql with brew :
brew uninstall mysql
sudo rm -r /usr/local/var/mysql
brew install mysql#8.0
mysql -u root
This solution works fine for me!
BUT YOU LOST ALL YOUR DATABASES! WARNING!
This fixed my issue when I restarted the mysql service. Just run:
brew services start mysql
In my case it was simply a matter of deleting a lock file.
sudo rm -f /tmp/mysql.sock.lock
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.
For me it was simple as running:
/usr/local/opt/mysql/bin/mysqld_safe
instead of mysqld
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
just hit "brew services start mysql" in terminal
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.
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
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 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.
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.
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
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
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
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
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.
only this has made the trick for me
brew services start --all
(after trying all answers)
I managed to solve this issue by changing localhost to 127.0.0.1
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>
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