[RAILS] Can't connect to local MySQL server through socket'/tmp/mysql.sock' (2) error

error contents

When I tried to create a database with the rails app,

$ bundle exec rake db:create
warning ../../../package.json: No license field
Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
Couldn't create 'hello_rails_development' database. Please check your configuration.
rake aborted!
Mysql2::Error::ConnectionError: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

Error occurred.

solution

mysql cannot be started (Can't connect to local MySQL server through socket'/tmp/mysql.sock' (2)) https://qiita.com/carotene4035/items/e00076fe3990b9178cc0 I restarted the mysql server referring to the article in.

$ sudo mysql.server restart
Password:
Sorry, try again.
Password:
Sorry, try again.
Password:
sudo: 3 incorrect password attempts

However, I was told that I needed a password, and I had forgotten my MySQL password, so I used this article as a reference to eliminate the MySQL password. (If true, you should write the password in database.yml of the rails app ...) How to reset if you forget the root password of MySQL 8.x in Mac local environment https://qiita.com/miriwo/items/1880e9d2ebcfd3c0e60d

$ mysql.server stop
$ mysqld_safe --skip-grant-tables &
$ mysql -u root
$ mysql.server status
$ kill [number]
$ ps aux| grep mysqld
$ kill [number]
$ mysql.server restart
$ bundle exec rake db:create

I was able to create the database safely.

Recommended Posts

Can't connect to local MySQL server through socket'/tmp/mysql.sock' (2) error
Can't connect to local MySQL server through socket'/tmp/mysql.sock' (2) error remedy
ERROR 2002 (HY000) when starting MySQL: Can't connect to local MySQL server through socket'/tmp/mysql.sock' (2)
Can't connect to local MySQL server through socket'/var/lib/mysql/mysql.sock' (2) until resolution.
docker + mysql can't connect / Can't connect to local MySQL server through socket'var / run / mysqld / mysqld.sock' (2)
[Java] Connect to MySQL
[Java] [SQL Server] Connect to local SQL Server 2017 using JDBC for SQL Server
To connect from Spring to MySQL on virtual server (unsolved)
Connect to MySQL 8 with Java
[Android] Connect to MySQL (unfinished)
Connect to Rails server with iPhone
Connect from Java to MySQL using Eclipse
Solution that gives an error when trying to connect to DB (MySQL) in Java
Connect to Aurora (MySQL) from a Java application
Unable to connect to chromedriver error when running SystemSpec
Error deploying rails5 + Mysql to heroku with Docker-compose