私は 2 つのスクリプトを持っています。いくつかの異なることを行い、2 番目のスクリプトを呼び出すメインのスクリプトと、MySQL をインストールする 2 番目のスクリプトです。
私のメインスクリプトから、私は次のようなことをします:
...
read -p "Set the password for the database [min. 4 characters]: " MPASS
# Install MySQL
path/to/setup-mysql.sh "$MPASS"
mysql --user="root" --password=${MPASS} -e "GRANT ALL ON *.* TO root@'${IPADDRESS}' IDENTIFIED BY '${MPASS}';"
mysql --user="root" --password=${MPASS} -e "GRANT ALL ON *.* TO root@'%' IDENTIFIED BY '${MPASS}';"
service mysql restart
mysql --user="root" --password=${MPASS} -e "SET GLOBAL validate_password_policy = 'LOW'; SET GLOBAL validate_password_length = 4; CREATE USER 'johndoe'@'${IPADDRESS}' IDENTIFIED BY '${MPASS}';"
mysql --user="root" --password=${MPASS} -e "GRANT ALL ON *.* TO 'johndoe'@'${IPADDRESS}' IDENTIFIED BY '${MPASS}' WITH GRANT OPTION;"
mysql --user="root" --password=${MPASS} -e "GRANT ALL ON *.* TO 'johndoe'@'%' IDENTIFIED BY '${MPASS}' WITH GRANT OPTION;"
mysql --user="root" --password=${MPASS} -e "FLUSH PRIVILEGES;"
次setup-mysql.sh
のようになります。
#!/bin/bash
export DEBIAN_FRONTEND=noninteractive
debconf-set-selections <<< "mysql-community-server mysql-community-server/data-dir select ''"
debconf-set-selections <<< "mysql-community-server mysql-community-server/root-pass password ${1}"
debconf-set-selections <<< "mysql-community-server mysql-community-server/re-root-pass password ${1}"
apt-get install -y mysql-server
# Start mysql on boot
update-rc.d mysql defaults
# Configure Password Expiration
echo "default_password_lifetime = 0" >> /etc/mysql/my.cnf
# Configure Access Permissions For Root
sed -i '/^bind-address/s/bind-address.*=.*/bind-address = */' /etc/mysql/my.cnf
私には、これはうまくいくように見えますが、bash が次の行を実行すると、次のようになります。
mysql --user="root" --password=${MPASS} -e "GRANT ALL ON *.* TO root@'${IPADDRESS}' IDENTIFIED BY '${MPASS}';"
パスワードが間違っていると言われます。手動でログインしようとすると、うまくいきません。そして、パスワード フィールド ( mysql -u root
) をスキップすると機能します。したがって、パスワードはまったく設定されていません。
また、 で行うecho $1
とsetup-mysql.sh
、何が含まれているかが適切に表示さMPASS
れます。
debconf-set-selections
MySQL インストールのパスワードが正しく設定されないのはなぜですか。私はここで本当に混乱しています。