Created
September 15, 2023 02:15
-
-
Save guangrei/314343b10901c18bea83acfab3f637ca to your computer and use it in GitHub Desktop.
script untuk mengganti password pada MariaDB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*-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