前提・実現したいこと
初投稿失礼致します。
現在、DockerfileでCentOS7のイメージに
MySQL5.7.26をインストールして
Dockerfileからrootの初期パスワードを変更しようと試みています。
しかし、調べた方法では変更できませんでした。
非対話式での変更が出来ればいいと思います。
発生している問題・エラーメッセージ
mysqladminで変更した場合
shell
1root> mysqladmin password [新しいパスワード] -u root -p=[旧パスワード] 2mysqladmin: [Warning] Using a password on the command line interface can be insecure. 3mysqladmin: connect to server at 'localhost' failed 4error: 'Access denied for user 'root'@'localhost' (using password: YES)'
公式ドキュメントを参考に変更した場合
shell
1root> kill `cat /var/run/mysqld/mysqld.pid` 2root> sed -i -e 's/MyNewPass/[新しいパスワード]/g' init-file.sql 3root> chown -R mysql init-file.sql 4root> mysqld --user=mysql --init-file=init-file.sql 5root> systemctl restart mysqld 6root> mysql -u root -p 7Enter password:[新しいパスワード] 8ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
init-file.sqlの内容
sql
1ALTER USER 'root'@'localhost' IDENTIFIED BY '[新しいパスワード]'; 2FLUSH PRIVILEGES; 3
mysqldで変更した場合
2019/06/09追記
shell
1root> mysql -uroot -p='[旧パスワード]' --connect-expired-password -e "alter user 'root'@'localhost' identified by [新しいパスワード]; flush privileges;" 2mysql: [Warning] Using a password on the command line interface can be insecure. 3ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
試したこと
上記、mysqladminと公式ドキュメントの手順
2019/06/09追記
下記ページ内rootユーザのパスワードを非対話で変更する
mysqldでの変更
補足情報(FW/ツールのバージョンなど)
CentOS:7.6.1818
Docker:18.09.6
docker-compose:1.24.0
MySQL:5.7.26
公式イメージを使っていない理由について
公式イメージではDebianがベースになっているので
CentOSで実装したいと考えて公式イメージで構築しませんでした。
初期パスワードについて
/var/log/mysqld.log
に初期パスワードがあるの確認しました。
対話式での変更が可能であるのも確認済みです。
質問したいこと
Dockerfileからrootの初期パスワードを変更するのは可能でしょうか。
もしくは非対話式でMySQLのroot初期パスワードを変更できますでしょうか。
まだまだ知識不足で申し訳ありません。
ご教授お願い致します。
2019/06/10 追記
rootの初期パスワードを変更したいと明確に表記しました。
回答1件
あなたの回答
tips
プレビュー