How to connect a flask docker container to planetscale? #455
-
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 7 replies
-
Hello, In the Docker image you're using, you shouldn't need to download a CA bundle, you can point to the system CA bundle at this location: You also don't want to specify Beyond that, you also want to be sure you're using Here's a simplified version of our from mysql.connector import Error
import mysql.connector
connection = mysql.connector.connect(
host="aws.connect.psdb.cloud",
database="your-database-name",
user="redacted",
password="redacted",
ssl_ca="/etc/ssl/certs/ca-certificates.crt"
)
try:
if connection.is_connected():
cursor = connection.cursor()
cursor.execute("select @@version ")
version = cursor.fetchone()
if version:
print('Running version: ', version)
else:
print('Not connected.')
except Error as e:
print("Error while connecting to MySQL", e)
finally:
connection.close() root@08925b4d8f6e:~# python test.py
Running version: ('8.0.21-Vitess',) |
Beta Was this translation helpful? Give feedback.
-
I am using windows os and getting :- from flask import Flask, render_template, request, redirect, url_for from datetime import datetime app = Flask(name) app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql+pymysql://vgzq84iy5bw4tvwqessi:pscale_pw_****@aws.connect.psdb.cloud/todo?ssl_ca=/etc/ssl/certs/ca-certificates.crt' class Todo(db.Model):
@app.route('/', methods=['GET', 'POST'])
@app.route('/update') @app.route('/delete') if name == "main": |
Beta Was this translation helpful? Give feedback.
Hello,
In the Docker image you're using, you shouldn't need to download a CA bundle, you can point to the system CA bundle at this location:
/etc/ssl/certs/ca-certificates.crt
.You also don't want to specify
ssl_cert
orssl_key
, only the system CA bundle should be necessary to verify the PlanetScale server.Beyond that, you also want to be sure you're using
mysql-connector-python
and not the outdatedmysql-connector
package.Here's a simplified version of our
mysql-connector-python
example that I was able to run in the same Docker image you're starting with:From https://planetscale.com/blog/connect-to-a-mysql-database-in-python#connect-to-mysql-with-the-mysql-connector