Skip to content

Commit

Permalink
feat: provision to connect mysql on custom port
Browse files Browse the repository at this point in the history
  • Loading branch information
saurabh6790 committed Aug 13, 2024
1 parent 667878c commit bacf86a
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions agent/site.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ def create_database_access_credentials(self, mode, mariadb_root_password):
]
for query in queries:
command = (
f"mysql -h {self.host} -uroot -p{mariadb_root_password}"
f"mysql -h {self.host} -uroot -p{mariadb_root_password} -P {self.port}"
f' -e "{query}"'
)
self.execute(command)
Expand All @@ -325,7 +325,7 @@ def revoke_database_access_credentials(self, user, mariadb_root_password):
]
for query in queries:
command = (
f"mysql -h {self.host} -uroot -p{mariadb_root_password}"
f"mysql -h {self.host} -uroot -p{mariadb_root_password} -P {self.port}"
f' -e "{query}"'
)
self.execute(command)
Expand Down Expand Up @@ -355,7 +355,7 @@ def restore_site_tables(self):
output = self.execute(
"set -o pipefail && "
f"gunzip -c '{backup_file_path}' | "
f"mysql -h {self.host} -u {self.user} -p{self.password} "
f"mysql -h {self.host} -u {self.user} -p{self.password} -P {self.port}"
f"{self.database}",
executable="/bin/bash",
)
Expand Down Expand Up @@ -504,7 +504,7 @@ def tablewise_backup(self):
"set -o pipefail && "
"mysqldump --single-transaction --quick --lock-tables=false "
f"-h {self.host} -u {self.user} -p{self.password} "
f"{self.database} '{table}' "
f"{self.database} -P {self.port} '{table}' "
f" | gzip > '{backup_file}'",
executable="/bin/bash",
)
Expand Down Expand Up @@ -572,7 +572,7 @@ def restore_touched_tables(self):
output = self.execute(
"set -o pipefail && "
f"gunzip -c '{backup_file}' | "
f"mysql -h {self.host} -u {self.user} -p{self.password} -P{self.port}"
f"mysql -h {self.host} -u {self.user} -p{self.password} -P {self.port}"
f"{self.database}",
executable="/bin/bash",
)
Expand All @@ -587,7 +587,7 @@ def drop_new_tables(self):
data = {"dropped": {}}
for table in new_tables:
output = self.execute(
f"mysql -h {self.host} -u {self.user} -p{self.password} "
f"mysql -h {self.host} -u {self.user} -p{self.password} -P {self.port}"
f"{self.database} -e 'DROP TABLE `{table}`'"
)
data["dropped"][table] = output
Expand Down Expand Up @@ -669,7 +669,7 @@ def timezone(self):
)
try:
timezone = self.execute(
f"mysql -h {self.host} -u{self.database} -p{self.password} "
f"mysql -h {self.host} -u{self.database} -p{self.password} -P {self.port}"
f'-sN -e "{query}"'
)["output"].strip()
except Exception:
Expand All @@ -680,7 +680,7 @@ def timezone(self):
def tables(self):
return self.execute(
"mysql --disable-column-names -B -e 'SHOW TABLES' "
f"-h {self.host} -u {self.user} -p{self.password} {self.database}"
f"-h {self.host} -u {self.user} -p{self.password} -P {self.port} {self.database}"
)["output"].split("\n")

@property
Expand Down Expand Up @@ -713,7 +713,7 @@ def optimize_tables(self):
for table in tables:
query = f"OPTIMIZE TABLE `{table}`"
self.execute(
f"mysql -sN -h {self.host} -u{self.user} -p{self.password}"
f"mysql -sN -h {self.host} -u{self.user} -p{self.password} -P {self.port}"
f" {self.database} -e '{query}'"
)

Expand Down Expand Up @@ -789,7 +789,7 @@ def get_database_size(self):
" GROUP BY `table_schema`"
)
command = (
f"mysql -sN -h {self.host} -u{self.user} -p{self.password}"
f"mysql -sN -h {self.host} -u{self.user} -p{self.password} -P {self.port}"
f" -e '{query}'"
)
database_size = self.execute(command).get("output")
Expand Down Expand Up @@ -838,7 +838,7 @@ def get_database_free_size(self):
" GROUP BY `table_schema`"
)
command = (
f"mysql -sN -h {self.host} -u{self.user} -p{self.password}"
f"mysql -sN -h {self.host} -u{self.user} -p{self.password} -P {self.port}"
f" -e '{query}'"
)
database_size = self.execute(command).get("output")
Expand All @@ -859,7 +859,7 @@ def get_database_free_tables(self):
" OR `data_free` > 100 * 1024 * 1024)"
)
command = (
f"mysql -sN -h {self.host} -u{self.user} -p{self.password}"
f"mysql -sN -h {self.host} -u{self.user} -p{self.password} -P {self.port}"
f" -e '{query}'"
)
output = self.execute(command).get("output")
Expand Down

0 comments on commit bacf86a

Please sign in to comment.