@@ -18,7 +18,7 @@ register_database mysql
1818
1919if [[ -z " $MYSQL_SERVICE_NAME " ]]; then
2020 MYSQL_SERVICE_NAME=mysql
21- if is_fedora && ! is_oraclelinux ; then
21+ if is_fedora; then
2222 MYSQL_SERVICE_NAME=mariadb
2323 elif [[ " $DISTRO " =~ trixie| bookworm| bullseye ]]; then
2424 MYSQL_SERVICE_NAME=mariadb
@@ -44,15 +44,9 @@ function cleanup_database_mysql {
4444 apt_get purge -y mysql* mariadb*
4545 sudo rm -rf /var/lib/mysql
4646 sudo rm -rf /etc/mysql
47- return
48- elif is_oraclelinux; then
49- uninstall_package mysql-community-server
50- sudo rm -rf /var/lib/mysql
5147 elif is_fedora; then
5248 uninstall_package mariadb-server
5349 sudo rm -rf /var/lib/mysql
54- else
55- return
5650 fi
5751}
5852
@@ -68,8 +62,6 @@ function configure_database_mysql {
6862
6963 if is_ubuntu; then
7064 my_conf=/etc/mysql/my.cnf
71- elif is_oraclelinux; then
72- my_conf=/etc/my.cnf
7365 elif is_fedora; then
7466 my_conf=/etc/my.cnf
7567 local cracklib_conf=/etc/my.cnf.d/cracklib_password_check.cnf
@@ -101,13 +93,20 @@ function configure_database_mysql {
10193 restart_service $MYSQL_SERVICE_NAME
10294 fi
10395
96+ # MariaDB 10.4+ on modern Debian/Ubuntu uses unix_socket auth by default
97+ # See https://mariadb.org/authentication-in-mariadb-10-4/
98+ local use_mariadb_socket_auth=False
99+ if is_ubuntu && [ " $MYSQL_SERVICE_NAME " == " mariadb" ]; then
100+ if [[ ! " $DISTRO " =~ bookworm| bullseye ]]; then
101+ use_mariadb_socket_auth=True
102+ fi
103+ fi
104+
104105 # Set the root password - only works the first time. For Ubuntu, we already
105106 # did that with debconf before installing the package, but we still try,
106107 # because the package might have been installed already. We don't do this
107- # for Ubuntu 22.04+ because the authorization model change in
108- # version 10.4 of mariadb. See
109- # https://mariadb.org/authentication-in-mariadb-10-4/
110- if ! (is_ubuntu && [[ ! " $DISTRO " =~ trixie| bookworm| bullseye ]] && [ " $MYSQL_SERVICE_NAME " == " mariadb" ]); then
108+ # for MariaDB with socket auth because the root password is managed differently.
109+ if [[ " $use_mariadb_socket_auth " != " True" ]]; then
111110 sudo mysqladmin -u root password $DATABASE_PASSWORD || true
112111 fi
113112
@@ -129,19 +128,20 @@ function configure_database_mysql {
129128 restart_service $MYSQL_SERVICE_NAME
130129 fi
131130
132- # In mariadb e.g. on Ubuntu socket plugin is used for authentication
133- # as root so it works only as sudo. To restore old "mysql like" behaviour,
134- # we need to change auth plugin for root user
135- # TODO(frickler): simplify this logic
136- if is_ubuntu && [[ ! " $DISTRO " =~ bookworm| bullseye ]] && [ " $MYSQL_SERVICE_NAME " == " mariadb" ]; then
137- # For Ubuntu 22.04+ we follow the model outlined in
138- # https://mariadb.org/authentication-in-mariadb-10-4/
139- sudo mysql -e " ALTER USER $DATABASE_USER @localhost IDENTIFIED VIA mysql_native_password USING PASSWORD('$DATABASE_PASSWORD ');"
131+ # Configure database user authentication
132+ if [[ " $use_mariadb_socket_auth " == " True" ]]; then
133+ # Allow both unix_socket (for sudo mysql) and password auth
134+ # Using OR allows restacking without needing to reset auth in unstack
135+ sudo mysql -e " ALTER USER $DATABASE_USER @localhost IDENTIFIED VIA unix_socket OR mysql_native_password USING PASSWORD('$DATABASE_PASSWORD ');"
140136 fi
141- if ! (is_ubuntu && [[ ! " $DISTRO " =~ bookworm| bullseye ]] && [ " $MYSQL_SERVICE_NAME " == " mariadb" ]); then
142- # Create DB user if it does not already exist
137+
138+ # Create remote access user and grant privileges (needed for all distros)
139+ if [[ " $use_mariadb_socket_auth " == " True" ]]; then
140+ # Use sudo mysql since we have socket auth
141+ sudo mysql -e " CREATE USER IF NOT EXISTS '$DATABASE_USER '@'%' identified by '$DATABASE_PASSWORD ';"
142+ sudo mysql -e " GRANT ALL PRIVILEGES ON *.* TO '$DATABASE_USER '@'%';"
143+ else
143144 sudo mysql $cmd_args -e " CREATE USER IF NOT EXISTS '$DATABASE_USER '@'%' identified by '$DATABASE_PASSWORD ';"
144- # Update the DB to give user '$DATABASE_USER'@'%' full control of the all databases:
145145 sudo mysql $cmd_args -e " GRANT ALL PRIVILEGES ON *.* TO '$DATABASE_USER '@'%';"
146146 fi
147147
226226 fi
227227 # Install mysql-server
228228 if [[ " $INSTALL_DATABASE_SERVER_PACKAGES " == " True" ]]; then
229- if is_oraclelinux; then
230- install_package mysql-community-server
231- elif is_fedora; then
229+ if is_fedora; then
232230 install_package mariadb-server mariadb-devel mariadb
233231 sudo systemctl enable $MYSQL_SERVICE_NAME
234232 elif is_ubuntu; then
0 commit comments