How to connect Google cloud SQL with PyMySQL? - mysql

I'm trying to connect GCP SQL database with PyMySQL using SSL. I'm using the following code so far.
conn = pymysql.connect(host=db_connection_name, user=db_user, password=db_password,
port=3306,
ssl={'ssl':{'ca':server-ca.pem,
'key':client-key.pem,
'cert':client-cert.pem}}
I'm getting the following error for this.
ConnectionRefusedError: [WinError 10061] No connection could be made because the target machine actively refused it
How do I solve the error?

Related

Flask App loses connection to MySQL database after about a day

I'm using python flask as a backend, running it as a service in the GCP instance. It is working correctly once started the service. But after a day when I try to make an API call it losses its connection with MySQL and shows the following
error mysql.connector.errors.InterfaceError: 2013:
I tried using pymysql and mysql.connector but facing the same error. Is there any way to solve this?

How do I connect to my RDS MySQL instance programmatically?

Problem
I launched a MySQL RDS instance and was able to successfully connect to it using MySQL Workbench. However, I am still not able to connect to it from my local workstation using the following URI:
'mysql+pymysql://user:password#db_identifier.XXXXXXXXXX.us-east-1.rds.amazonaws.com:3306/db_name'
or the same URI without the port:
'mysql+pymysql://user:password#db_identifier.XXXXXXXXXX.us-east-1.rds.amazonaws.com/db_name'
The error that I receive when I specify this as my database URI and execute a db.create_all() command is:
sqlalchemy.exc.OperationalError:
(pymysql.err.OperationalError)
(2003, "Can't connect to MySQL server on 'db_identifier.XXXXXXXXXX.us-east-1.rds.amazonaws.com'
([WinError 10060] A connection attempt failed because the connected party did not
properly respond after a period of time, or established connection failed because
connected host has failed to respond)")
Question
What can I do to connect using pymysql? And why would it connect with MySQL Workbench and not through this URI?
Context
I am following the tutorial here. This uses SQLAlchemy to execute the SQL statements in Python.
The RDS instance (and its associated subnet/VPC) have the following:
a security group open on port 3306
NACL rules that allow incoming and outgoing traffic
Public Accessibility set to "Yes"
Check my answer on this post, it could be something about the "Public accesibility" option in your rds "Connectivity and Security" section as described here;
https://stackoverflow.com/a/63514997/2934184

Unable to connect to 127.0.0.1:3306 in Mysql

I was creating a very large table using a python data set in the Mysql server, which I today realized was beyond the server's capacity.
Post which I am unable to connect to the server
I get the following error when I try to establish a connection on the MySQL workbench, I also get something similar when I try the same on python using MySQL connector
Following is a screenshot of the error
I tried setting up a new connection as follows, but I receive the same error:
I tried this solution, which is similar but I keep getting the following error
'mysql' is not recognized as an internal or external command,
operable program or batch file.
Is there any other way I can connect, or if there is anything I have to do before I can connect?
127.0.0.1 this server not get . Try to reconnect in another address..

Robot Framework -connect to MS SQL databse - Login error

I am trying to connect to MS SQL server through robot framework on remote machine
I have installed the required libraries and db api
the keyword is as follows
Connect To Database Using Custom Params pymssql database='MSSQL', user='user', password='password', host='192.168..*'
I am getting following error
OperationalError: (18456, "Login failed for user 'user'.DB-Lib error message 20018, severity 14:\nGeneral SQL Server error: Check messages from the SQL Server\nDB-Lib error message 20002, severity 9:\nAdaptive Server connection failed (192.168.86.130:1433)\n")
I even tried the same with pyodbc db api . but facing the error for the same
You have incorrect connection string. Try this one:
DRIVER=\{SQL Server\};SERVER=${host};DATABASE=${db_name};UID=${username};PWD=${password}

Facing connection issue with mysql while connecting with R-10060

I am trying to connect R to the MySql server and getting the following error:
"Error in .local(drv,....)
Failed to connect to database: Error: Lost connection to MySQL server at 'reading authorization packet' , system error :10060"
Please note that I am facing this issue on the localhost.
Check to be sure you can connect using a basic MySQL client from the machine you are running your R code on first. That will help you eliminate firewall, hostname, username, password, etc issues. (Seems likely that is what your problem really is: https://forums.mysql.com/read.php?34,49742,239961).