When I used local mysql in the rails project for the first time in a while, mysql stopped working. The solution is described below.
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.
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"
Starting MySQL SUCCESS!
If so, the installation of mysql is successful.
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
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.