docker@default:~$ docker run --name mysqld -e MYSQL_DATABASE=mydb -e MYSQL_USER=user -e MYSQL_PASSWORD=password -e MYSQL_ROOT_PASSWORD=admin -d mysql
// MySQL にLogin
docker@default:~$ docker run --link mysqld:mysql -it --rm mysql bash
// MySQL にLogin 後、環境変数をチェック
root@95825593d169:/# env
// DB にlogin しようとして、error
root@95825593d169:/# mysql -u root -p mydb Enter password: ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
// 上記エラー時、mysqld.sock が'/var/run/mysqld/mysqld.sock'にあるかどうかを確認
root@95825593d169:/# ls -al /var/run/mysqld/
// mysqld.sock がない場合、以下のコマンドで作成
root@95825593d169:/# touch /var/run/mysqld/mysqld.sock
// ディレクトリの所有者変更(不要かも)
root@95825593d169:/# chown mysqld:mysql /var/run/mysqld
// MySQL を再起動
root@95825593d169:/# /etc/init.d/mysql restart
// ログフォルダを設定していないと、以下のWarning
No directory, logging in with HOME=/ 2017-06-22T05:59:53.076720Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). 2017-06-22T05:59:54.729911Z 0 [Warning] InnoDB: New log files created, LSN=45790 2017-06-22T05:59:54.991579Z 0 [Warning] InnoDB: Creating foreign key constraint system tables. 2017-06-22T05:59:55.300196Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 03cdccff-5710-11e7-b6a7-0242ac110005. 2017-06-22T05:59:55.314362Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened. 2017-06-22T05:59:55.337119Z 1 [Warning] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option. 2017-06-22T05:59:56.130826Z 1 [Warning] 'user' entry 'root@localhost' ignored in --skip-name-resolve mode. 2017-06-22T05:59:56.130938Z 1 [Warning] 'user' entry 'mysql.sys@localhost' ignored in --skip-name-resolve mode. 2017-06-22T05:59:56.130978Z 1 [Warning] 'db' entry 'sys mysql.sys@localhost' ignored in --skip-name-resolve mode. 2017-06-22T05:59:56.131009Z 1 [Warning] 'proxies_priv' entry '@ root@localhost' ignored in --skip-name-resolve mode. 2017-06-22T05:59:56.131069Z 1 [Warning] 'tables_priv' entry 'sys_config mysql.sys@localhost' ignored in --skip-name-resolve mode.
// 最初に作ったDB, User が消えていたので、ルートでログイン
root@95825593d169:/# mysql -u root -p
// 消えたユーザを作成する
CREATE USER 'user' IDENTIFIED BY 'password'; GRANT ALL ON mydb.* TO 'user'@'%' IDENTIFIED BY 'password';
0 件のコメント:
コメントを投稿