@@ -100,8 +100,13 @@ function configure_database_mysql {
100100
101101 # Set the root password - only works the first time. For Ubuntu, we already
102102 # did that with debconf before installing the package, but we still try,
103- # because the package might have been installed already.
104- sudo mysqladmin -u root password $DATABASE_PASSWORD || true
103+ # because the package might have been installed already. We don't do this
104+ # for Ubuntu 22.04 (jammy) because the authorization model change in
105+ # version 10.4 of mariadb. See
106+ # https://mariadb.org/authentication-in-mariadb-10-4/
107+ if ! (is_ubuntu && [[ " $DISTRO " == " jammy" ]] && [ " $MYSQL_SERVICE_NAME " == " mariadb" ]); then
108+ sudo mysqladmin -u root password $DATABASE_PASSWORD || true
109+ fi
105110
106111 # In case of Mariadb, giving hostname in arguments causes permission
107112 # problems as it expects connection through socket
@@ -115,13 +120,21 @@ function configure_database_mysql {
115120 # as root so it works only as sudo. To restore old "mysql like" behaviour,
116121 # we need to change auth plugin for root user
117122 if is_ubuntu && [[ " $DISTRO " != " bullseye" ]] && [ " $MYSQL_SERVICE_NAME " == " mariadb" ]; then
118- sudo mysql $cmd_args -e " UPDATE mysql.user SET plugin='' WHERE user='$DATABASE_USER ' AND host='localhost';"
119- sudo mysql $cmd_args -e " FLUSH PRIVILEGES;"
123+ if [[ " $DISTRO " == " jammy" ]]; then
124+ # For Ubuntu 22.04 (jammy) we follow the model outlined in
125+ # https://mariadb.org/authentication-in-mariadb-10-4/
126+ sudo mysql -e " ALTER USER $DATABASE_USER @localhost IDENTIFIED VIA mysql_native_password USING PASSWORD('$DATABASE_PASSWORD ');"
127+ else
128+ sudo mysql $cmd_args -e " UPDATE mysql.user SET plugin='' WHERE user='$DATABASE_USER ' AND host='localhost';"
129+ sudo mysql $cmd_args -e " FLUSH PRIVILEGES;"
130+ fi
131+ fi
132+ if ! (is_ubuntu && [[ " $DISTRO " == " jammy" ]] && [ " $MYSQL_SERVICE_NAME " == " mariadb" ]); then
133+ # Create DB user if it does not already exist
134+ sudo mysql $cmd_args -e " CREATE USER IF NOT EXISTS '$DATABASE_USER '@'%' identified by '$DATABASE_PASSWORD ';"
135+ # Update the DB to give user '$DATABASE_USER'@'%' full control of the all databases:
136+ sudo mysql $cmd_args -e " GRANT ALL PRIVILEGES ON *.* TO '$DATABASE_USER '@'%';"
120137 fi
121- # Create DB user if it does not already exist
122- sudo mysql $cmd_args -e " CREATE USER IF NOT EXISTS '$DATABASE_USER '@'%' identified by '$DATABASE_PASSWORD ';"
123- # Update the DB to give user '$DATABASE_USER'@'%' full control of the all databases:
124- sudo mysql $cmd_args -e " GRANT ALL PRIVILEGES ON *.* TO '$DATABASE_USER '@'%';"
125138
126139 # Now update ``my.cnf`` for some local needs and restart the mysql service
127140
0 commit comments