Solution when mysql stops working on mac (Rails project running)

After a long time using local mysql, it stopped working

When I used local mysql in the rails project for the first time in a while, mysql stopped working. The solution is described below.

For the time being, delete all the existing mysql

The data will disappear, but let's reinsert it with seed data. As a result, it is fast. If the old mysql is bad, it will take a lot of time to resolve it, so if you do not start mysql with docker and connect, let's delete mysql with brain death.

--How to delete community edition mysql

rm -rf ~/Library/PreferencePanes/My*
sudo rm /usr/local/mysql
sudo rm -rf /usr/local/mysql*
sudo rm -rf /Library/StartupItems/MySQLCOM
sudo rm -rf /Library/PreferencePanes/My*
sudo rm -rf /Library/Receipts/mysql*
sudo rm -rf /Library/Receipts/MySQL*
sudo rm -rf /private/var/db/receipts/*mysql*
sudo rm /Library/LaunchDaemons/com.oracle.oss.mysql.mysqld.plist

--How to delete mysql entered by brew

$ brew uninstall mysql
sudo rm -rf /usr/local/Cellar/mysql*
sudo rm -rf /usr/local/bin/mysql*
sudo rm -rf /usr/local/var/mysql*
sudo rm -rf /usr/local/etc/my.cnf
sudo rm -rf /usr/local/share/mysql*
sudo rm -rf /usr/local/opt/mysql*
sudo rm -rf /etc/my.cnf

If you run both of the above, all mysql should disappear.

install mysql with brew

This time I will use brew to install mysql. Currently, if you do brew install mysql, 8 series of mysql will be installed, so install 5.7 safely.

brew install [email protected]

Put the following line in the configuration file of the shell you are using to pass the path. (For bash ~/.bash_profile)

export PATH="/usr/local/opt/[email protected]/bin:$PATH"
mysql.server start
Starting MySQL
 SUCCESS!

If so, the installation of mysql is successful.

Run a Rails project that was launched in the past

The following are the points of interest when running a rails project.

If it is a project that executed bundle install in the past, I think that the gem is installed according to the version of mysql that was installed at that time, so when I execute rails db: create, the following error appears and mysql surroundings I'm angry! I think you will see the error.

> rails db:create
rails aborted!
LoadError: dlopen

So uninstall the gem with the following command.

bundle exec gem uninstall mysql2

do it

bundle install 

Let's re-insert the mysql2 gem. If you get an error here

bundle config --local build.mysql2 "--with-ldflags=-L/usr/local/opt/openssl/lib"

Try running the above command before bundle install.

reference: https://qiita.com/akiko-pusu/items/aef52b723da2cb5dc596

Recommended Posts

Solution when mysql stops working on mac (Rails project running)
When Gradle build stops when importing on Mac
Ruby on Rails Tutorial Troublesome notes when running on Windows
[Rails / MySQL] Mac environment construction
When log data accumulates in Rails and the environment stops working
Ruby on Rails installation method [Mac edition]
I can't install rails on my mac
Relative path when running tomcat on eclipse
MySQL is not running stably ... Rails app is not running.