I recently configured SSL on my MySQL server and it appears to have broken my python application. I can connect to the the server fine via command line:
user@kiosk:~$ mysql -u <user> -p -h <remote host>
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 19
Server version: 5.7.25-0ubuntu0.18.04.2 (Ubuntu)
Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
And SSL seems to be working on the connection:
mysql> \s
--------------
mysql Ver 14.14 Distrib 5.7.25, for Linux (x86_64) using EditLine wrapper
Connection id: 19
Current database:
...
SSL: Cipher in use is DHE-RSA-AES256-SHA
....
Threads: 1 Questions: 17 Slow queries: 0 Opens: 106 Flush tables: 1 Open tables: 99 Queries per second avg: 0.007
The user is configured to require SSL, and I'm not currently using the CA/client-cert/client-key on my client to connect (as I understand it, this is optional).
My python script uses a simple connection:
db_ip_address = raw_input('Ip Address: ')
db_username = raw_input('Username: ')
db_passwd = raw_input('Password: ')
try:
db = mysql.connector.connect(
host=db_ip_address,
user=db_username,
passwd=db_passwd,
)
cursor = db.cursor()
connected = True
except Exception as e:
installer.fatal('\r\n Failed to connect to SQL server please try again \r\n')
print traceback.format_exception_only(type(e), e)[0]
Which is now failing with the following error:
ProgrammingError: 1045 (28000): Access denied for user '<user>'@'<IP>' (using password: YES)
I'm assuming this is due to my SSL config, but I'm not entirely sure why things work fine from the mysql CLI, but not from my script?
Any insight would be greatly appreciated.