Resolve Mysql2 :: Error :: ConnectionError

Environment / version

I'm doing it locally Ruby v2.5.1 Rails v5.2.4 MySQL v8.0.19

what happened?

After creating a rails project, I encountered this error when I tried `rails s'

Mysql2::Error::ConnectionError (Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)):

How did you solve it?

As you can see from the error statement, you can immediately tell that it is "Ah, MySQL".

Since it says ConnectionError, you can immediately tell that it is not connected.

Check out database.yml.

default: &default
  adapter: mysql2
  encoding: utf8
  pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
  username: root
  password:
  socket: /tmp/mysql.sock

  ---Omitted below---

The password of the yml file is missing. During this time, I forgot to set a password for MySQL.

I was able to connect even if I hadn't set it before, but it seems that it didn't connect well this time because I set it.

default: &default
  adapter: mysql2
  encoding: utf8
  pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
  username: root
  password: password #Postscript
  socket: /tmp/mysql.sock

I feel relieved when this screen appears. Cute kids

スクリーンショット 2020-07-09 9.32.37.png

Thank you for reading to the end. I hope it helps you even a little.

Recommended Posts

Resolve Mysql2 :: Error :: ConnectionError
I get Mysql2 :: Error :: ConnectionError in the production environment
Mysql2 :: Error: Table'relationships' already exists
[Deployment error] Mysql2 :: Error: Table'~' already exists: CREATE TABLE `~`
[rails s error] md5.bundle and mysql installation error