Posts Tagged ‘ mysql ’

Getting Sequel Pro to read MySQL on MacOS

As a follow-up to the previous post (Installing MySQL on MacOS with Homebrew), to get Sequel Pro working you need to do the following:

Open my.cnf (usually at /usr/local/etc) and add the following line and save:
[mysqld]
default-authentication-plugin=mysql_native_password

Sign into mysql with mysql -u root -p

Set the root user password with:

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '[PASSWORD]';

where [PASSWORD] is a password of your choosing.

Delete my.cnf (MySQL will regenerate it):

sudo rm -rf /usr/local/etc/my.cnf

Restart mysql:

brew services restart mysql

Now Sequel Pro should be able to log into MySQL.

Reference:
Sequel Pro and MySQL connection failed
Cannot find MySQL.sock

Installing MySQL on MacOS with Homebrew

I was trying to install MySQL on MacOS and I followed the instructions to install it via Homebrew:

$ brew install mysql

Pretty easy, but then as I worked along I screwed something up where I could not load mysql in the command line. I would get the following error:

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

So I do the logical step of uninstalling and reinstalling:

$ brew uninstall mysql
$ brew install mysql

I still get the same error. Two hours of browsing StackOverflow later, I figured it out. I failed to notice the following errors during reinstallation:

2019-02-21T01:02:48.455076Z 0 [System] [MY-013169] [Server] /usr/local/Cellar/mysql/8.0.15/bin/mysqld (mysqld 8.0.15) initializing of server in progress as process 18070
2019-02-21T01:02:48.457920Z 0 [ERROR] [MY-010457] [Server] --initialize specified but the data directory has files in it. Aborting.
2019-02-21T01:02:48.457929Z 0 [ERROR] [MY-013236] [Server] Newly created data directory /usr/local/var/mysql/ is unusable. You can safely remove it.
2019-02-21T01:02:48.457994Z 0 [ERROR] [MY-010119] [Server] Aborting
2019-02-21T01:02:48.458203Z 0 [System] [MY-010910] [Server] /usr/local/Cellar/mysql/8.0.15/bin/mysqld: Shutdown complete (mysqld 8.0.15) Homebrew.

This is the key line:
Newly created data directory /usr/local/var/mysql/ is unusable. You can safely remove it.

What do I do? Remove that directory!

$ sudo rm -rf /usr/local/var/mysql/

Then run the post install script:

$ brew postinstall mysql

And voilà, mysql loads!

$ mysql -uroot
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.15 Homebrew

Learn from my fail.