Skip to content

Commit 83ca80d

Browse files
committed
CI: Use caching_sha2_password in MySQL 8.0 and newer
1 parent 8dbc5b5 commit 83ca80d

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

ci/setup.sh

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ set -eux
44

55
# Change the password to be empty.
66
CHANGED_PASSWORD=false
7+
CHANGED_PASSWORD_SHA2=false
78
# Change the password to be empty, recreating the root user on mariadb < 10.2
89
# where ALTER USER is not available.
910
# https://stackoverflow.com/questions/56052177/
@@ -45,13 +46,13 @@ fi
4546
# Install MySQL 8.0 if DB=mysql80
4647
if [[ -n ${DB-} && x$DB =~ ^xmysql80 ]]; then
4748
sudo bash ci/mysql80.sh
48-
CHANGED_PASSWORD=true
49+
CHANGED_PASSWORD_SHA2=true
4950
fi
5051

5152
# Install MySQL 8.4 if DB=mysql84
5253
if [[ -n ${DB-} && x$DB =~ ^xmysql84 ]]; then
5354
sudo bash ci/mysql84.sh
54-
CHANGED_PASSWORD=true
55+
CHANGED_PASSWORD_SHA2=true
5556
fi
5657

5758
# Install MariaDB 10.6 if DB=mariadb10.6
@@ -120,6 +121,11 @@ if [ "${CHANGED_PASSWORD}" = true ]; then
120121
# https://www.percona.com/blog/2016/03/16/change-user-password-in-mysql-5-7-with-plugin-auth_socket/
121122
sudo mysql ${MYSQL_OPTS} -u "${DB_SYS_USER}" \
122123
-e "ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY ''"
124+
elif [ "${CHANGED_PASSWORD_SHA2}" = true ]; then
125+
# In MySQL 5.7, the default authentication plugin is mysql_native_password.
126+
# As of MySQL 8.0, the default authentication plugin is changed to caching_sha2_password.
127+
sudo mysql ${MYSQL_OPTS} -u "${DB_SYS_USER}" \
128+
-e "ALTER USER 'root'@'localhost' IDENTIFIED WITH caching_sha2_password BY ''"
123129
elif [ "${CHANGED_PASSWORD_BY_RECREATE}" = true ]; then
124130
sudo mysql ${MYSQL_OPTS} -u "${DB_SYS_USER}" <<SQL
125131
DROP USER 'root'@'localhost';

0 commit comments

Comments
 (0)