0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)のエラー

Posted at

エラー内容

railsのアプリでデータベースを作成しようとしたところ、

$ 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)

のエラーが発生。

解決策

mysqlが起動できない(Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2))
https://qiita.com/carotene4035/items/e00076fe3990b9178cc0
の記事を参考にmysqlサーバーを再起動しました。

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

しかし、Passwordが必要と言われ、MySQLのパスワードはとっくに忘れていたので、こちらの記事を参考にMySQLのパスワードを無しにしました。(本当ならrailsアプリのdatabase.ymlにパスワードを記述するべきですが。。。)
Mac ローカル環境の MySQL 8.x のrootパスワードを忘れた時のリセット方法
https://qiita.com/miriwo/items/1880e9d2ebcfd3c0e60d

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

で無事にデータベースを作成できました。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?