I am trying to build a Python script to automate MySQL installs, so far it creates the mysql user, and downloads, untars & installs the rpm bundle for MySQL 8. Post-install, I am trying to login as mysql root user with the temporary password using the mysql connector, in order to change the password. The way I am trying to connect looks like this: def login_to_mysql_db_inst(username, password): mydb = mysql.connector.connect( host="localhost", user=username, password=password ) print(mydb) return mydb if __name__ == "__main__": create_mysql_user(target_user) #create mysql user download_mysql(db_version) #download and unzip mysql files make_dirs_fn() #create data and log directories chown_dirs_fn() #grant permissions and ownership on directories to mysql user ##need to update /etc/cfengine-hostclasses.txt resolve_dependencies() #remove files that may conflict with the install install() #installs mysql write_config_to_file(cfengine_hostclass_lines, '/etc/cfengine-hostclasses.txt') ##write lines into /etc/cfengine-hostclasses.txt write_config_to_file(mysql_config_lines, '/etc/my.cnf') ##write lines into /etc/my.cnf run_cmd(["service","mysqld","start"]) #start mysql services run_cmd(["service","mysqld","status"]) ##check status of mysql services run_cmd(["chkconfig", "mysqld", "on"]) #enable mysqld.service -- enabling auto start temp_password = get_temporary_mysql_password() login_to_mysql_db_inst('root',temp_password) curr = mydb.cursor() curr.execute("ALTER USER 'root'@'localhost' IDENTIFIED BY '*************';") When I try this, I get an expired-password error Traceback (most recent call last): File "/usr/local/lib64/python3.6/site-packages/mysql/connector/connection_cext.py", line 236, in _open_connection self._cmysql.connect(**cnx_kwargs) _mysql_connector.MySQLInterfaceError: Your password has expired. To log in you must change it using a client that supports expired passwords. During handling of the above exception, another exception occurred: Traceback (most recent call last): File "mysql_install_script.py", line 283, in <module> login_to_mysql_db_inst('root',temp_password) File "mysql_install_script.py", line 250, in login_to_mysql_db_inst password=password File "/usr/local/lib64/python3.6/site-packages/mysql/connector/__init__.py", line 272, in connect return CMySQLConnection(*args, **kwargs) File "/usr/local/lib64/python3.6/site-packages/mysql/connector/connection_cext.py", line 85, in __init__ self.connect(**kwargs) File "/usr/local/lib64/python3.6/site-packages/mysql/connector/abstracts.py", line 1028, in connect self._open_connection() File "/usr/local/lib64/python3.6/site-packages/mysql/connector/connection_cext.py", line 242, in _open_connection sqlstate=exc.sqlstate) mysql.connector.errors.DatabaseError: 1862 (HY000): Your password has expired. To log in you must change it using a client that supports expired passwords. I am able to manually reset it in the terminal by entering mysql -u root -p {temp_password} and then using the ALTER USER command to reset the password, but we are looking at a way to automate this via a python script. Would very much appreciate any ideas? Continue reading...