###前提・実現したいこと
Docker の CeontOS7 のイメージから作成したコンテナにMySQLをインストールしました。
これをDBとして仮運用し、外部からも接続できるようにしたいです。
外部から扱うためにユーザーを作成しようと思った段階で躓いています。
rootのパスワードは設定したものになっていてそれでmysqlに入ることができます。
ですが新しいユーザーを作ることろでエラーが出ています。
###発生している問題・エラーメッセージ
下記のシェルスクリプトを実行した時のエラー
-== Complete Install ==- mysqld Ver 5.7.14 for Linux on x86_64 (MySQL Community Server (GPL)) mysql: [Warning] Using a password on the command line interface can be insecure. Please use --connect-expired-password option or invoke mysql in interactive mode. [root@6034835b0dda /]#
mysqlUserSetting.sqlの実行行をコメントアウトしてシェルスクリプトを実行し、
手動でmysqlにrootで入ってユーザーを作成しようとすると以下のようになりました。
[root@5b3fbe7c80df /]# mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 2 Server version: 5.7.14 Copyright (c) 2000, 2016, 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. mysql> CREATE USER mysqluser; ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement. mysql>
###該当のソースコード
コンテナは以下のように作成しました。
$ docker run --privileged -d -P -i -t -p 3306:3306 --name db_server -v ホストパス:/app_db centos /sbin/init
接続は以下のように行っています。
$ docker exec -it db_server /bin/bash
コンテナ作成後、接続して/app_db以下に入っているシェルスクリプトを実行しています。
#!/bin/sh # vim yum -y install vim-enhanced # mysql yum -y localinstall http://dev.mysql.com/get/mysql57-community-release-el7-7.noarch.rpm yum info mysql-community-server yum -y install mysql-community-server systemctl enable mysqld.service systemctl restart mysqld echo " -== Complete Install ==-" mysqld --version # Allow access without pw to mysql echo 'skip-grant-tables' >> /etc/my.cnf systemctl restart mysqld.service mysql -u root < /cha_db/mysqlResetRootPw.sql # del last line (skip-grant-tables) sed -i -e '$d' /etc/my.cnf systemctl restart mysqld.service mysql -u root -pdevmysql < /app_db/mysqlUserSetting.sql
mysqlResetRootPw.sqlの中身
SQL
1use mysql 2UPDATE user SET authentication_string=password('devmysql') WHERE user='root'; 3flush privileges;
mysqlUserSetting.sqlの中身
SQL
1CREATE USER mysqluser; 2CREATE USER mysqluser IDENTIFIED BY [PASSWORD] 'devmysql'; 3SELECT user,host FROM mysql.user;
回答2件
あなたの回答
tips
プレビュー