はじめに
Docker勉強し始めです。
あまり詳しくありません。
環境
- MacOS High Sierra (10.13.4)
- Docker for Mac 18.06.1-ce-mac73 (26764)
質問概要
Amazon Linux2のDockerイメージに、MySQLをyum install
し、
mysqlコマンドで接続しようとすると、
ERROR 2003 (HY000): Can't connect to MySQL server on '127.0.0.1' (111)
と言われる原因と解決方法を知りたいです。
質問詳細/やったことなど
最終的に、docker-compose.yml
とDockerfile
に落とし込みたいのですが、
コマンドを確認するため以下の手順にしております。
まず、AmazonLinux2のイメージをdocker pull
し、
そこにyum install
でMySQL 5.7をインストールしました。
なお、Docker上で行っているものはすべてroot権限なので「#」表記が正しいですが、
markdownでコメント扱いになるので、あえて「$」で表記しています。
bash
1# Amazon Linux2を引っ張ってくる 2$ docker pull amazonlinux:2.0.20180622.1 3 4# 落としたAmazonLinux2のイメージにsshで入る 5$ docker run -it amazonlinux:2.0.20180622.1 bash 6 7# MySQL5.7をインストールできるように、リポジトリを読み込む 8$ yum localinstall -y https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm 9 10# MySQL5.7のインストール 11$ yum install -y mysql mysql-server
上記コマンドはすべて成功したようで、特にエラーなどはありませんでした。
この後、
$ mysql -u root
を実行すると、
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock'
が表示されました。
なので、
touch /var/lib/mysql/mysql.sock
を行い、ファイルを作成後再度、mysql -u root
を実行しましたが、
同じエラーが出ました。
mysqlをrestartしていないのが問題かと思い、
$ /usr/sbin/mysqld restart
とすると、
2018-10-22T04:25:58.993611Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). 2018-10-22T04:25:58.995886Z 0 [Note] /usr/sbin/mysqld (mysqld 5.7.24) starting as process 192 ... 2018-10-22T04:25:58.997389Z 0 [ERROR] Fatal error: Please read "Security" section of the manual to find out how to run mysqld as root! 2018-10-22T04:25:58.997447Z 0 [ERROR] Aborting 2018-10-22T04:25:58.997478Z 0 [Note] Binlog end 2018-10-22T04:25:59.000258Z 0 [Note] /usr/sbin/mysqld: Shutdown complete
と怒られたので、Stack Overflowで見つけた以下コマンドを実行してみましたが、駄目でした…
$ /usr/sbin/mysqld restart --user=root
もしかして、接続ホストをきめないといけないのかと思い、
$ mysql -h 127.0.0.1 -u root -P 3306
としましたが、
ERROR 2003 (HY000): Can't connect to MySQL server on '127.0.0.1' (111)
となります。
これはどの様に回避するのでしょうか?
ご存知の方がいらっしゃいましたら、ご教示いただけますと幸いです。
追記
どうも、MySQLのプロセスが立ち上がってない…?
$ ps ax | grep mysql
↑自分しか出ない
エラーログを一度全クリア後、
/usr/sbin/mysqld --user=root
↓ エラーログ
2018-10-22T05:47:42.185394Z 0 [Note] /usr/sbin/mysqld (mysqld 5.7.24) starting as process 427 ... 2018-10-22T05:47:42.188000Z 0 [Note] InnoDB: PUNCH HOLE support available 2018-10-22T05:47:42.188038Z 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins 2018-10-22T05:47:42.188047Z 0 [Note] InnoDB: Uses event mutexes 2018-10-22T05:47:42.188054Z 0 [Note] InnoDB: GCC builtin __atomic_thread_fence() is used for memory barrier 2018-10-22T05:47:42.188061Z 0 [Note] InnoDB: Compressed tables use zlib 1.2.11 2018-10-22T05:47:42.188068Z 0 [Note] InnoDB: Using Linux native AIO 2018-10-22T05:47:42.188238Z 0 [Note] InnoDB: Number of pools: 1 2018-10-22T05:47:42.188320Z 0 [Note] InnoDB: Using CPU crc32 instructions 2018-10-22T05:47:42.189333Z 0 [Note] InnoDB: Initializing buffer pool, total size = 128M, instances = 1, chunk size = 128M 2018-10-22T05:47:42.196081Z 0 [Note] InnoDB: Completed initialization of buffer pool 2018-10-22T05:47:42.198297Z 0 [Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man page of setpriority(). 2018-10-22T05:47:42.209708Z 0 [Note] InnoDB: Highest supported file format is Barracuda. 2018-10-22T05:47:42.221513Z 0 [Note] InnoDB: Creating shared tablespace for temporary tables 2018-10-22T05:47:42.221578Z 0 [Note] InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ... 2018-10-22T05:47:42.263084Z 0 [Note] InnoDB: File './ibtmp1' size is now 12 MB. 2018-10-22T05:47:42.264346Z 0 [Note] InnoDB: 96 redo rollback segment(s) found. 96 redo rollback segment(s) are active. 2018-10-22T05:47:42.264381Z 0 [Note] InnoDB: 32 non-redo rollback segment(s) are active. 2018-10-22T05:47:42.265052Z 0 [Note] InnoDB: Waiting for purge to start 2018-10-22T05:47:42.315545Z 0 [Note] InnoDB: 5.7.24 started; log sequence number 1210075 2018-10-22T05:47:42.316198Z 0 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool 2018-10-22T05:47:42.316278Z 0 [Note] Plugin 'FEDERATED' is disabled. mysqld: Table 'mysql.plugin' doesn't exist 2018-10-22T05:47:42.316411Z 0 [ERROR] Can't open the mysql.plugin table. Please run mysql_upgrade to create it. 2018-10-22T05:47:42.316411Z 0 [Note] InnoDB: Buffer pool(s) load completed at 181022 5:47:42 2018-10-22T05:47:42.316588Z 0 [ERROR] Too many arguments (first extra is 'start'). 2018-10-22T05:47:42.316607Z 0 [Note] Use --verbose --help to get a list of available options! 2018-10-22T05:47:42.316616Z 0 [ERROR] Aborting 2018-10-22T05:47:42.316627Z 0 [Note] Binlog end 2018-10-22T05:47:42.316750Z 0 [Note] Shutting down plugin 'ngram' 2018-10-22T05:47:42.316762Z 0 [Note] Shutting down plugin 'partition' 2018-10-22T05:47:42.316778Z 0 [Note] Shutting down plugin 'BLACKHOLE' 2018-10-22T05:47:42.316786Z 0 [Note] Shutting down plugin 'ARCHIVE' 2018-10-22T05:47:42.316806Z 0 [Note] Shutting down plugin 'PERFORMANCE_SCHEMA' 2018-10-22T05:47:42.316840Z 0 [Note] Shutting down plugin 'MRG_MYISAM' 2018-10-22T05:47:42.316847Z 0 [Note] Shutting down plugin 'MyISAM' 2018-10-22T05:47:42.316861Z 0 [Note] Shutting down plugin 'INNODB_SYS_VIRTUAL' 2018-10-22T05:47:42.316868Z 0 [Note] Shutting down plugin 'INNODB_SYS_DATAFILES' 2018-10-22T05:47:42.316874Z 0 [Note] Shutting down plugin 'INNODB_SYS_TABLESPACES' 2018-10-22T05:47:42.316880Z 0 [Note] Shutting down plugin 'INNODB_SYS_FOREIGN_COLS' 2018-10-22T05:47:42.316886Z 0 [Note] Shutting down plugin 'INNODB_SYS_FOREIGN' 2018-10-22T05:47:42.316892Z 0 [Note] Shutting down plugin 'INNODB_SYS_FIELDS' 2018-10-22T05:47:42.316898Z 0 [Note] Shutting down plugin 'INNODB_SYS_COLUMNS' 2018-10-22T05:47:42.316904Z 0 [Note] Shutting down plugin 'INNODB_SYS_INDEXES' 2018-10-22T05:47:42.316910Z 0 [Note] Shutting down plugin 'INNODB_SYS_TABLESTATS' 2018-10-22T05:47:42.316916Z 0 [Note] Shutting down plugin 'INNODB_SYS_TABLES' 2018-10-22T05:47:42.316922Z 0 [Note] Shutting down plugin 'INNODB_FT_INDEX_TABLE' 2018-10-22T05:47:42.316928Z 0 [Note] Shutting down plugin 'INNODB_FT_INDEX_CACHE' 2018-10-22T05:47:42.316934Z 0 [Note] Shutting down plugin 'INNODB_FT_CONFIG' 2018-10-22T05:47:42.316940Z 0 [Note] Shutting down plugin 'INNODB_FT_BEING_DELETED' 2018-10-22T05:47:42.316955Z 0 [Note] Shutting down plugin 'INNODB_FT_DELETED' 2018-10-22T05:47:42.316962Z 0 [Note] Shutting down plugin 'INNODB_FT_DEFAULT_STOPWORD' 2018-10-22T05:47:42.316968Z 0 [Note] Shutting down plugin 'INNODB_METRICS' 2018-10-22T05:47:42.316974Z 0 [Note] Shutting down plugin 'INNODB_TEMP_TABLE_INFO' 2018-10-22T05:47:42.316980Z 0 [Note] Shutting down plugin 'INNODB_BUFFER_POOL_STATS' 2018-10-22T05:47:42.316986Z 0 [Note] Shutting down plugin 'INNODB_BUFFER_PAGE_LRU' 2018-10-22T05:47:42.316992Z 0 [Note] Shutting down plugin 'INNODB_BUFFER_PAGE' 2018-10-22T05:47:42.316998Z 0 [Note] Shutting down plugin 'INNODB_CMP_PER_INDEX_RESET' 2018-10-22T05:47:42.317004Z 0 [Note] Shutting down plugin 'INNODB_CMP_PER_INDEX' 2018-10-22T05:47:42.317010Z 0 [Note] Shutting down plugin 'INNODB_CMPMEM_RESET' 2018-10-22T05:47:42.317016Z 0 [Note] Shutting down plugin 'INNODB_CMPMEM' 2018-10-22T05:47:42.317022Z 0 [Note] Shutting down plugin 'INNODB_CMP_RESET' 2018-10-22T05:47:42.317028Z 0 [Note] Shutting down plugin 'INNODB_CMP' 2018-10-22T05:47:42.317034Z 0 [Note] Shutting down plugin 'INNODB_LOCK_WAITS' 2018-10-22T05:47:42.317040Z 0 [Note] Shutting down plugin 'INNODB_LOCKS' 2018-10-22T05:47:42.317046Z 0 [Note] Shutting down plugin 'INNODB_TRX' 2018-10-22T05:47:42.317052Z 0 [Note] Shutting down plugin 'InnoDB' 2018-10-22T05:47:42.317157Z 0 [Note] InnoDB: FTS optimize thread exiting. 2018-10-22T05:47:42.317275Z 0 [Note] InnoDB: Starting shutdown... 2018-10-22T05:47:42.419178Z 0 [Note] InnoDB: Dumping buffer pool(s) to /var/lib/mysql/ib_buffer_pool 2018-10-22T05:47:42.419688Z 0 [Note] InnoDB: Buffer pool(s) dump completed at 181022 5:47:42 2018-10-22T05:47:43.958962Z 0 [Note] InnoDB: Shutdown completed; log sequence number 1210094 2018-10-22T05:47:43.962226Z 0 [Note] InnoDB: Removed temporary tablespace data file: "ibtmp1" 2018-10-22T05:47:43.962259Z 0 [Note] Shutting down plugin 'MEMORY' 2018-10-22T05:47:43.962269Z 0 [Note] Shutting down plugin 'CSV' 2018-10-22T05:47:43.962279Z 0 [Note] Shutting down plugin 'sha256_password' 2018-10-22T05:47:43.962294Z 0 [Note] Shutting down plugin 'mysql_native_password' 2018-10-22T05:47:43.962420Z 0 [Note] Shutting down plugin 'binlog' 2018-10-22T05:47:43.964954Z 0 [Note] /usr/sbin/mysqld: Shutdown complete
参考にしたサイト様

回答3件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/10/22 07:15