_mysql_exceptions.OperationalError: (2026, 'SSL connection error: SSL_CTX_set_tmp_dh failed')
is thrown at me when I try to run my script which connects to my SQL server.
I installed MySQLdb via conda. I've read that this may be an openssl issue, but I'm having trouble downgrading that as well.
based on This answer.
I got the answer:'https://dev.mysql.com/doc/refman/5.7/en/data-directory-initialization.html'
'shell> bin/mysql_ssl_rsa_setup'
If you want to deploy the server with automatic support for secure connections, use the mysql_ssl_rsa_setup utility to create default SSL and RSA files
More information here
I was able to fix this my using mysql.connector instead of importing MySQLdb in my python scripts
Related
I'm trying to run a python script through a cronjob inside my EKS cluster. When it tries to connect to my aurora instance, it fails stating that I'm using an unsupported SSL protocol.
unsupported protocol log trace
Any clue? The aurora's mysql version is 5.6, the python is 3.8 and the mysql connector package is 8.0.25
Even though the actual error message is a little different but I'm guessing this is most likely related to the missing TLS certificate issue stated here.
You should probably have the certificate available to the pod/cronjob you are trying to run in the cluster.
I've been trying to connect to a MySQL database remotely but I keep getting the error:
2055: Lost connection to MySQL server at 'local.mysql.database.azure.com:3306', system error: 1 [SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1045)
Using the exact same connection details I am able to connect to the database through MySQL Workbench and through Node. For some reason the connection won't go through in python.
This user's as not created to require SSL.
I've been trying to figure out the problem but I'm drawing blanks.
Below is my python login block.
config = {
'host':'local.mysql.database.azure.com',
'user':'user#local',
'password':'password',
'database':'random_db'
}
I've been able to connect to a MySQL instance on the Google Cloud Platform with the exact same connection block but it doesn't work for the Azure connection. I've looked for differences between the two platforms which could have caused this and the only thing I could find was that the Azure MySQL version was 5.7.32log while the GCP was 8.0.18.
I am also currently running python 3.7.0, not sure if that changes anything.
Is there another module I could use if that is the problem, or do I need to downgrade something? I have no idea.
According to this 5.7.29 is the latest 5.7 supported so 5.7.32 would give wrong version error.
Can't connect my code to my MySQL DB due to the authentication plugin
I'm trying to connect my code to a newly installed MySQL DB. I am aware that on MySQL 8.X and above, the authentication type is set to sha2 by default and I've read that I need to "force" a different authentication plug-in (auth_plugin='mysql_native_password').
well... I did it but I still get the same error message:
"Authentication plugin '{0}' is not supported".format(plugin_name))
mysql.connector.errors.NotSupportedError: Authentication plugin 'caching_sha2_password' is not supported
What else should I do?
Thanks
import mysql.connector as Sql
myDB = Sql.connect(
host="localhost",
user="dbadmin",
password="myPassword",
auth_plugin="mysql_native_password"
)
print(myDB)
This indeed solved my issue:
I had the same problem and passing auth_plugin='mysql_native_password' did not work,
because I accidentally installed mysql-connector instead of mysql-connector-python (via
pip3). Just to leaving this here in case it helps someone.
Authentication plugin 'caching_sha2_password' is not supported
I used to connect to my AWS-RDS instance this way
import MySQLdb
db = MySQLdb.connect(host=os.getenv('RDS_ENDPOINT'),
user=os.getenv('RDS_USER'),
passwd=os.getenv('RDS_PWD'),
db=os.getenv('RDS_DB'))
or with the help of sqlalchemy, but today it seem to refuse to work with the error (2006, 'SSL connection error: SSL_CTX_set_tmp_dh failed')
I tried to update all the python packages (mysqlclient, sqlalchemy), reinstall mysqlclient-dev, manually reinstall OpenSSL v1.1.1a but still the same error.
[EDIT]
I manage to connect to the same database using the MySQL CLI
mysql --user=$RDS_USER --host=$RDS_ENDPOINT --password=$RDS_PWD $RDS_DB
[SOLUTION]
It seems that this is a driver issue. I tried with mysqlclient for python 3 and got this error. Next I tried with mysql.connector as recommanded but I got encoding issues (as stated in the sqlalchemy doc). Finally, I ended with the pymysql driver which seems to work with sqlalchemy.
Upgrade mysqlclient package fixed the problem.
I have an Azure web app with a Flask template. I want it to connect to a SQL database. I made one. I installed pymssql. For testing purposes I added to the views.py in the root folder:
import pymssql
conn = pymssql.connect(server='mydb.database.windows.net', user='mydbnameadmin#mydb', password='secret', database='mydb')
I first tested locally on my kubuntu box. To make sure I was getting a connection, I entered the wrong password, and the server threw an error. I entered it correctly and the error disappeared. Cool. Also the SQL dashboard on the azure portal reported sucessfull connections. So then I pushed my changes (including updating the requirements.txt) to my github repo and it was sucked into my web application. When I tried running the web app, on the index page:
The page cannot be displayed because an internal server error has
occurred.
After turning on and inspecting the detailed logs all I get it:
HTTP Error 500.0 - Internal Server Error
The page cannot be displayed because an internal server error has occurred.
Most likely causes:
IIS received the request; however, an internal error occurred during the processing of the request. The root cause of this error depends on which module handles the request and what was happening in the worker process when this error occurred.
IIS was not able to access the web.config file for the Web site or application. This can occur if the NTFS permissions are set incorrectly.
IIS was not able to process configuration for the Web site or application.
The authenticated user does not have permission to use this DLL.
The request is mapped to a managed handler but the .NET Extensibility Feature is not installed.
IIS. What's that doing here? I thought MS was trendy and hosted this service on a linux box 0_0
I remove the second line
conn = pymssql.connect(server='mydb.database.windows.net', user='mydbnameadmin#mydb', password='secret', database='mydb')
and the error disappeared. If I run a server locally, which still uses the Azure SQL server, I don't have any issues.
This seems to be the same issue I have:
https://social.msdn.microsoft.com/Forums/sqlserver/en-US/e20bb2a3-bdbe-4e49-8b92-b36fe50577da/having-trouble-deploying-flask-app-into-azure-with-azure-database?forum=windowsazurewebsitespreview&prof=required
but they say whether they actually got it working with a SQL database...
what do people think?
Thanks
my requirements.txt
alembic==0.7.7
azure==0.11.1
Flask==0.10.1
Flask-Migrate==1.5.0
Flask-Script==2.0.5
Flask-SQLAlchemy==2.0
futures==3.0.3
itsdangerous==0.24
Jinja2==2.8
Mako==1.0.1
MarkupSafe==0.23
pymssql==2.1.1
python-dateutil==2.4.2
six==1.9.0
SQLAlchemy==1.0.8
Werkzeug==0.10.4
wheel==0.24.0
Per my understanding, Azure Web sites are hosted on Windows Server 2012 VM by default, which would not install FreeTDS and also we don't have permission to install it. And the pymssql is based on FreeTDS.
So we can use pyodbc to connect the Azure SQL as a workaround way to handle it in ease.
I was able to successfully connect my Python code to a SQL Database on Azure using the pymssql 2.1 library.
I don't know if this is what is causing the problem but I did include a couple of extra parameters in my connection string... maybe that will help. I specified the driver explicitly and the Encrypt parameter since SSL is always enabled for SQL Azure (I believe)
myConnection = pyodbc.connect('Driver={SQL Server};'
'Server=tcp:1234567.database.windows.net,1433;'
'Database=MyAzureDatabase;'
'Uid=geekgirl#123456;Pwd=abcdef;'
'Encrypt=yes')
If that doesn't work, maybe try adding some error handling around the connect statement to try and get a more specific error message.
Fingers crossed!
I had this problem, but I eventually realized it was because I was using the 64-bit version of Python in Visual Studio, but Azure only supports the 32-bit version.
I was seeing:
DLL load failed: %1 is not a valid Win32 application.
Once I switched to installing and using the 32-bit version I was able to use Flask and pyodbc with no problems.