How to setup MySQL on MacOS (Getting Started) - mysql

I have been running all my apps with Rails and PostgreSQL, which was very easy to setup using brew install postgresql and brew services start postgresql. With MySQL is proving to be a very big pain.
How do I setup MySQL from 0 and clean up all the mess I made?
I have downloaded MySQL Community Server 8.0.21 on my MacOS and registered a root password during the setup.
After that I have run the folowing commands that render the following errors.
$ mysql -u root -p
# ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (61)
$ mysql.server start
# Starting MySQL
# ./usr/local/Cellar/mysql/8.0.21_1/bin/mysqld_safe: line 144: /usr/local/var/mysql/Victors-MBP.err: Permission denied
# /usr/local/Cellar/mysql/8.0.21_1/bin/mysqld_safe: line 144: /usr/local/var/mysql/Victors-MBP.err: Permission denied
# /usr/local/Cellar/mysql/8.0.21_1/bin/mysqld_safe: line 199: /usr/local/var/mysql/Victors-MBP.err: Permission denied
# /usr/local/Cellar/mysql/8.0.21_1/bin/mysqld_safe: line 144: /usr/local/var/mysql/Victors-MBP.err: Permission denied
# ERROR! The server quit without updating PID file (/var/run/mysql/mysqld.pid).
$ brew doctor
$ brew uninstall mysql
$ brew cleanup
$ brew install mysql
# The whole setup works, but every attempt to run the server still renders the same errors.
$ mysql_secure_installation
# after inputting the correct root password...
# Error: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (61)
Please help. I have tried many more different setups and corrections, none of which have worked.
Thank you in advance!

MySQL has a simple Macintosh installer and a control-panel that goes along with it ... shows up in "System Preferences." Are you sure that the server is actually running? Betcha it ain't.

This worked: https://superuser.com/a/603027/1220403
Basically execute this command:
$ mysql -u root mysql
And you'll be able to set a password using ALTER USER and access the mysql command line. Also, you'll be able to start the server.

Related

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

Since I've updated my Mac to the lastest OS version (Ventura 13.2) and I'he made some cleanup (hopefully I didn't remove any important file). I can't connect to mySql
I've insatlled mysql with brew (long before this update) and it always has worked fine.
When I run brew services start mysql in my terminal it looks to work (Successfully started mysql (label: homebrew.mxcl.mysql))
But, as soon as I run mysql -u root -p and I enter my password I have the following error message ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
When I explore /tmp directory I see that /tmp/mysql.sock is a symlink to /var/lib/mysql/mysql.sock but mysql directory doesn't exist in /var/lib.
After extensive research I didn't find how to "get" this directory.
I've found many entries in StackOverflow with the same title, I've tried almost all answer but none seems to work. especialy in my case I'm using brew and macOS ventura.
Typicaly for ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' the accepted answer is not about brew.
I've tried brew reinstall mysql.
I've tried as well mysql -h 127.0.0.1 -u root -p in this case the error is ERROR 2003 (HY000): Can't connect to MySQL server on '127.0.0.1:3306' (61).
I've tried to run mysqld and then brew services start mysql, in this case I have the following error
Bootstrap failed: 5: Input/output error
Try re-running the command as root for richer errors.
Error: Failure while executing; `/bin/launchctl bootstrap gui/502 /Users/CedMacBook1/Library/LaunchAgents/homebrew.mxcl.mysql.plist` exited with 5.
I've tried to change my password using sudo mysqladmin -u root password -p and once again I have the error error: 'Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)'.
It looks like mysql is runningm, I've ran ps aux | grep mysqld and get the following line:
CedMacBook 21853 0,0 0,0 34400496 2728 s000 S+ 7:53 0:00.01 grep mysqld
Finally I've checked my /usr/local/etc/my.cnf and I have the following
# Default Homebrew MySQL server config
[mysqld]
socket=/tmp/mysql.sock
# Only allow connections from localhost
bind-address = 127.0.0.1
port=3306
mysqlx-bind-address = 127.0.0.1
At this stage I'd be happy to swipe out everything... if I could save all my database
Please help, I don't know what else to try

Homebrew - brew mysql 8 - Error: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

I tried a lot to install MySQL8 via Homebrew on Mac 10.14.5. I was running MySQL 5.7 before that and did the following: I removed MySQL completely via this tutorial: https://coderwall.com/p/os6woq/uninstall-all-those-broken-versions-of-mysql-and-re-install-it-with-brew-on-mac-mavericks
After that I run mysql and got the message that the command was not known. So I installed mysql with brew install mysql. After installation I did brew link --force mysql and got Warning: Already linked: /usr/local/Cellar/mysql/8.0.19
I edited /usr/local/etc/my.cnf and added default-authentication-plugin=mysql_native_password in the [mysqld] section. After that I restartet the service using brew services restart mysql
brew services list shows me this now:
mysql started root /Library/LaunchDaemons/homebrew.mxcl.mysql.plist
mysql#5.7 stopped
However, when I type mysql in the terminal I get this:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
The /tmp/mysql.sock does not exist.
When I change the host in the my.cnf file from localhost to 127.0.0.1 this error will change into this:
ERROR 2013 (HY000): Lost connection to MySQL server at 'reading initial communication packet', system error: 54
Anyone has an idea what's going on here and how I can fix it? I also googled it and found various Threads, some are saying that the permissions must be changed to this sudo chown -R _mysql:mysql /usr/local/var/mysql but this does not change anything in my case.

MySQL Error: Authentication plugin 'caching_sha2_password' cannot be loaded

I just installed MySQL Ver 14.14 Distrib 5.7.22 with Homebrew on my macOS v10.13.4.
I ran the command:
brew install mysql
After the installation completed, as directed by Homebrew, I ran the command:
mysql_secure_installation
and was returned the error: Error: Authentication plugin 'caching_sha2_password' cannot be loaded: dlopen(/usr/local/Cellar/mysql/5.7.22/lib/plugin/caching_sha2_password.so, 2): image not found
I tried a few things like changing default_authentication_plugin to mysql_native_password in the my.cnf file but it still throws the same error.
Next I tried running:
mysql_upgrade -u root
and I was thrown the same error again mysql_upgrade: Got error: 2059: Authentication plugin 'caching_sha2_password' cannot be loaded: dlopen(/usr/local/Cellar/mysql/5.7.22/lib/plugin/caching_sha2_password.so, 2): image not found while connecting to the MySQL server
Upgrade process encountered error and will not continue.
Any help is appreciated.
So, I found the running process of mysqld by sudo lsof -i tcp:3306 then I killed it using sudo kill -9 <PID>.
After this I tried mysql_secure_installation again, but ran into a new error :
Error: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (61)
After trying a few fixes for getting mysql.sock to work, I started the MySQL server with sudo mysql.server start then went ahead with mysql_secure_installation to set password for the root user.
This worked for me finally.
Note: Homebrew asks you to first do mysql_secure_installation before starting the MySQL server for the first time but that just made me run into endless loop of errors.
Restart the mysql server to take the changes in affect and try connecting via mysql with any mysql client.
Otherwise use docker
docker run -p 3306:3306 -e MYSQL_ALLOW_EMPTY_PASSWORD=yes -d mysql --default-authentication-plugin=mysql_native_password
mysql -uroot --protocol tcp
Try in PWD
Related a question.
Authentication plugin 'caching_sha2_password' cannot be loaded
I figured out this should be an issue with the mysql version installed. Just as above you should first find then kill the mysqld process attached on port 3306
sudo lsof -i tcp:3306
sudo kill -9 <Peocess ID>
Then upgrade the mysql installation via brew, in this case:
brew upgrade mysql
This should solve it.Running mysql after the upgrade should start your server after the installation.
e.g mysql -u root -p [your password here]
I got this error in Sequel Pro trying to connect over SSH to an AWS Ubuntu server with MySQL installed locally.
I was using a non-root MySQL user and it gave me that error. It worked when I ran it with the root user and password.

Cannot get MySQL running in Terminal on macOS Sierra

I have been setting up a new laptop for development purposes and when trying to get MySQL to run in the Terminal I get the following message:
$ mysql -u root -p
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
Can somebody please help me out here?
You may get this error because mysql server is not started. For me it solved only by starting mysql server.
to start Mysql server (for Mac OS X), command line in terminal:
sudo /usr/local/mysql/support-files/mysql.server start
or, simply go to your Mac System Preference --> MySQL --> click on start mysql..

Can't connect to local MySQL server through socket '/tmp/mysql.sock' (38)' on FreeBSD

Hello guy's i have this problem :
root#Myname:~ # mysql -p
Enter password:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (38)
root#Myname:~ # chown -R mysql /var/db/mysql
chown: mysql: illegal user name
root#Myname:~ #
I do not know how to fix this please help
System operations : FreeBSD 9.2 x64
It sounds like you've only installed the mysqlXX-client port instead of the server. To install the server (assuming 5.6), you can use the ports system:
cd /usr/ports/databases/mysql56-server
make install
If you haven't installed the ports tree, first run:
portsnap fetch
portsnap extract
To ensure it gets started up on a reboot, you would enable it using the rc.conf system:
echo 'mysql_enable="YES"' >> /etc/rc.conf.local
And then you can start it up:
/usr/local/etc/rc.d/mysql-server start
Let me know if that gets you to where you need to be.