LoginSignup
0
0

More than 3 years have passed since last update.

MySQLのエラーでDjangoアプリがローカルで実行できなくなったときの話

Posted at

久しぶりにDjangoのアプリケーションを立ち上げようと以下のコマンドを打ったところ
python.manage.py runserver
こんなエラーが。前は動いてたはずなのに何故
django.db.utils.OperationalError: (2003, "Can't connect to MySQL server on '127.0.0.1' ([Errno 111] Connection refused)")

MySQLの起動確認

$ mysql.server start
Starting MySQL
.... * The server quit without updating PID file (/home/linuxbrew/.linuxbrew/var/mysql/***.pid).

PIDファイルとは,Linux上であるサービスが起動したときに作成されるファイルで,プロセス番号が割り振られているらしい.サービスが動いているかどうかの判断基準になる.
***は端末名

空のPIDファイルを作ってみる

$ touch /home/linuxbrew/.linuxbrew/var/mysql/***.pid

$ mysql.server restart
 * MySQL server PID file could not be found!
Starting MySQL
.rm: cannot remove '/tmp/mysql.sock': Operation not permitted
2020-03-20T18:09:18.611443Z mysqld_safe Fatal error: Can't remove the socket file:
/tmp/mysql.sock.
Please remove the file manually and start /home/linuxbrew/.linuxbrew/Cellar/mysql/8.0.18_1/bin/mysqld_safe again;
mysqld daemon not started
 * The server quit without updating PID file (/home/linuxbrew/.linuxbrew/var/mysql/***.pid).

/tmp/mysql.sock削除&再チャレンジ

$ sudo rm /tmp/mysql.sock
$ touch /home/linuxbrew/.linuxbrew/var/mysql/***.pid
$ mysql.server restart
 * MySQL server PID file could not be found!
Starting MySQL
... *
$ mysql -u root
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.18 Homebrew

Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

通った!

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