import os
import winreg
def add_mysql_to_path(mysql_path):
# Get the System PATH variable registry key
key = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, 'SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment', 0, winreg.KEY_ALL_ACCESS)
# Fetch the current PATH value
path_value, _ = winreg.QueryValueEx(key, 'Path')
# Append the MySQL path if it's not already present
if mysql_path not in path_value:
path_value += ';' + mysql_path
# Set the updated PATH value
winreg.SetValueEx(key, 'Path', 0, winreg.REG_EXPAND_SZ, path_value)
# Notify about the successful addition
print('MySQL path added to the system PATH variable. Please restart your command prompt.')
else:
# Notify that the path is already present
print('MySQL path is already in the system PATH variable.')
# Close the registry key
winreg.CloseKey(key)
# Provide the MySQL installation path
mysql_installation_path = r'C:\Program Files\MySQL\MySQL Server XXXX\bin'
add_mysql_to_path(mysql_installation_path)