Skip to content

Commit cd09784

Browse files
Port changes from K8s PR to avoid --initialize-insecure (#625)
1 parent 8d7bf94 commit cd09784

File tree

2 files changed

+12
-15
lines changed

2 files changed

+12
-15
lines changed

lib/charms/mysql/v0/mysql.py

+6-9
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ def wait_until_mysql_connection(self) -> None:
133133
# Increment this major API version when introducing breaking changes
134134
LIBAPI = 0
135135

136-
LIBPATCH = 83
136+
LIBPATCH = 84
137137

138138
UNIT_TEARDOWN_LOCKNAME = "unit-teardown"
139139
UNIT_ADD_LOCKNAME = "unit-add"
@@ -1027,7 +1027,7 @@ def render_mysqld_configuration( # noqa: C901
10271027
config.write(string_io)
10281028
return string_io.getvalue(), dict(config["mysqld"])
10291029

1030-
def configure_mysql_users(self, password_needed: bool = True) -> None:
1030+
def configure_mysql_users(self) -> None:
10311031
"""Configure the MySQL users for the instance."""
10321032
# SYSTEM_USER and SUPER privileges to revoke from the root users
10331033
# Reference: https://dev.mysql.com/doc/refman/8.0/en/privileges-provided.html#priv_super
@@ -1065,13 +1065,10 @@ def configure_mysql_users(self, password_needed: bool = True) -> None:
10651065

10661066
try:
10671067
logger.debug(f"Configuring MySQL users for {self.instance_address}")
1068-
if password_needed:
1069-
self._run_mysqlcli_script(
1070-
configure_users_commands,
1071-
password=self.root_password,
1072-
)
1073-
else:
1074-
self._run_mysqlcli_script(configure_users_commands)
1068+
self._run_mysqlcli_script(
1069+
configure_users_commands,
1070+
password=self.root_password,
1071+
)
10751072
except MySQLClientError:
10761073
logger.error(f"Failed to configure users for: {self.instance_address}")
10771074
raise MySQLConfigureMySQLUsersError

src/mysql_vm_helpers.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -353,12 +353,6 @@ def reset_root_password_and_start_mysqld(self) -> None:
353353
mode="w",
354354
encoding="utf-8",
355355
) as _sql_file:
356-
_sql_file.write(
357-
f"ALTER USER 'root'@'localhost' IDENTIFIED BY '{self.root_password}';\n"
358-
"FLUSH PRIVILEGES;"
359-
)
360-
_sql_file.flush()
361-
362356
try:
363357
subprocess.check_output([
364358
"sudo",
@@ -371,6 +365,12 @@ def reset_root_password_and_start_mysqld(self) -> None:
371365
"Failed to change permissions for temp SQL file"
372366
)
373367

368+
_sql_file.write(
369+
f"ALTER USER 'root'@'localhost' IDENTIFIED BY '{self.root_password}';\n"
370+
"FLUSH PRIVILEGES;"
371+
)
372+
_sql_file.flush()
373+
374374
_custom_config_file.write(f"[mysqld]\ninit_file = {_sql_file.name}")
375375
_custom_config_file.flush()
376376

0 commit comments

Comments
 (0)