Skip to content

Instantly share code, notes, and snippets.

@guangrei
Created September 15, 2023 02:15
Show Gist options
  • Save guangrei/314343b10901c18bea83acfab3f637ca to your computer and use it in GitHub Desktop.
Save guangrei/314343b10901c18bea83acfab3f637ca to your computer and use it in GitHub Desktop.
script untuk mengganti password pada MariaDB
# -*-coding:utf8;-*-
import subprocess
"""
script untuk mengubah password MariaDB pada xampp docker.
ganti root@123 dengan password yang diinginkan dan tidak mudah ditebak!
author: guangrei
"""
# Perintah MySQL yang akan dijalankan
mysql_commands = """
USE mysql;
UPDATE user SET Password=PASSWORD('root@123') WHERE User='root' AND Host='localhost';
FLUSH PRIVILEGES;
"""
# Membuka proses MySQL
mysql_process = subprocess.Popen(
["mysql", "--user=root"],
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True # Untuk bekerja dengan teks
)
# Mengirim perintah-perintah MySQL ke proses
output, error = mysql_process.communicate(input=mysql_commands.strip())
if len(error.strip()):
print(error)
exit(1)
else:
print("success!")
# Menutup proses MySQL
mysql_process.terminate()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment