Home>

I got into trouble while creating the original application, and I uninstalled MySQL once and reinstalled it. After execution, when I ran rails s to connect to the local host on the terminal, the following error occurred.

$rails s
dlopen (/Users/user/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/mysql2-0.5.3/lib/mysql2/mysql2.bundle, 9): Library not loaded:/usr/local/opt/[email protected]/lib/libmysqlclient.18.dylib (LoadError)
  Referenced from: /Users/user/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/mysql2-0.5.3/lib/mysql2/mysql2.bundle
  Reason: image not found-/Users/user/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/mysql2-0.5.3/lib/mysql2/mysql2.bundle
What I tried

① Check with brew info mysql

$brew info mysql
mysql: stable 8.0.21 (bottled)
Open source relational database management system
https://dev.mysql.com/doc/refman/8.0/en/
Conflicts with:
  mariadb (because mysql, mariadb, and percona install the same binaries)
  percona-server (because mysql, mariadb, and percona install the same binaries)
/usr/local/Cellar/mysql/8.0.21_1 (290 files, 293.7MB) *
  Poured from bottle on 2020-09-14 at 16:11:54
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/mysql.rb
License: GPL-2.0
==>Dependencies
Build: cmake ✘
Required: openssl @ 1.1 ✔, protobuf ✔
==>Caveats
We've installed your MySQL database without a root password. To secure it run:
    mysql_secure_installation
MySQL is configured to only allow connections from localhost by default
To connect run:
    mysql -uroot
To have launchd start mysql now and restart at login:
  brew services start mysql
Or, if you don't want/need a background service you can just run:
  mysql.server start
==>Analytics
install: 70,150 (30 days), 200,477 (90 days), 807,629 (365 days)
install-on-request: 67,942 (30 days), 194,554 (90 days), 774,283 (365 days)
build-error: 0 (30 days)


② Move the symbolic link referring to the following article
https://qiita.com/wktk/items/a1df946b64b7adbcb346

Postscript

By unifying the MySQL version to 5.6, Library not loaded: libmysqlclient.18.dylib (LoadError) when running rails s in the terminal is resolved.
However, when I started MySQL, the following error occurred.

$mysql -u root -p
Enter password:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket'/tmp/mysql.sock' (2)

I have reinstalled MysQL, but for some reason my password has to be authenticated, or I don't seem to have root privileges.