April 1 | Jumpstart your data app journey and get live support with Plotly Studio. Reserve your spot.

Connect to your relational database with Plotly

Connect MySQL to Plotly Studio

TRY PLOTLY STUDIO
play-icon

Step-by-step MySQL data connection setup

MySQL is the world's most popular open-source relational database. Known for its reliability, ease of use, and performance, MySQL powers countless web applications, e-commerce platforms, and content management systems worldwide.

Connecting MySQL requires your host address, port, database name, and login credentials. Follow these steps to connect to your MySQL data and visualize it with Plotly Studio:

Step 1: Confirm your MySQL instance is running

MySQL can be running locally on your machine, on a private server, or on a managed cloud host via AWS RDS, Google Cloud SQL, or Azure Database for MySQL. Wherever it lives, you'll need network access to it from Plotly Studio. Make sure your instance is up and that remote connections are allowed if you're not connecting from localhost.

Step 2: Create a dedicated database user (recommended)

Rather than connecting with your root account, it's best practice to create a dedicated user with only the permissions Plotly Studio needs. In your MySQL shell, run:

CREATE USER '[YOUR_USERNAME]'@'%' IDENTIFIED BY '[YOUR_PASSWORD]';
GRANT SELECT ON [YOUR_DATABASE].* TO '[YOUR_USERNAME]'@'%';
FLUSH PRIVILEGES;

Using '%' allows connections from any host. If you'd prefer to restrict access to a specific IP, replace it with your server's IP address.

Step 3: Gather your connection details

Before jumping into Plotly Studio, have these values ready. You can find them in your MySQL client, your cloud provider's dashboard, or from the credentials generated when your database was created.

Step 4: Connect in Plotly Studio

Open a new project in Plotly Studio and ask it to connect to MySQL. It will generate a credentials form. Fill in your Host, Port, Database, Username, and Password, then save. Plotly Studio will authenticate and return a Database Explorer showing all available tables in your schema.

Credentials needed

  • Host: IP address or hostname of your MySQL server (e.g., 127.0.0.1 or db.example.com)
  • Port: typically 3306
  • Database: the name of the schema to connect to
  • Username: your MySQL user
  • Password: your MySQL user's password

Tip: contact us if you need help troubleshooting these steps.

LLM prompts for connecting to MySQL

Plotly Studio uses an AI agent to generate and execute the data connection code for you. The prompts below are ready to copy and paste directly into Plotly Studio's data connection chat. Use them to establish a connection, query your data, or do both in one shot. The global context rules are worth saving to your Plotly Studio global context to keep MySQL connections consistent across projects.

Connection prompt

Connect to a MySQL database using the mysql-connector-python library. Use
mysql.connector.connect() with the provided host, port, database, username, and password.
Verify the connection is active using connection.is_connected(). Upon successful
connection, list all available tables in the target database using a SHOW TABLES query.

Query prompt

Using the established MySQL connection, retrieve all rows from the table [YOUR_TABLE_NAME]
in the [YOUR_DATABASE_NAME] database. Execute the query using a cursor, fetch the results
with fetchall(), and return them as a pandas DataFrame. Use standard MySQL SQL syntax only.

Example one-shot prompt

Connect to a MySQL database using mysql-connector-python with the following credentials:

Host: [YOUR_HOST_OR_IP]
Port: 3306
Database: [YOUR_DATABASE_NAME]
Username: [YOUR_USERNAME]
Password: [YOUR_PASSWORD]

Verify the connection with connection.is_connected(), then retrieve all rows from the table
[YOUR_TABLE_NAME] and return the result as a pandas DataFrame. Display a preview of the
data.

Global context rules

Always use mysql-connector-python as the primary connection library.
Always initialize the connection using mysql.connector.connect() with explicit host, port,
database, user, and password arguments.
Always verify the connection is active with connection.is_connected() before executing
queries.
Always use a cursor to execute queries and fetchall() to retrieve results.
Always return query results as a pandas DataFrame.
Use standard MySQL SQL syntax only. Do not use legacy or non-standard dialects.
Always close the cursor and connection after data has been retrieved.
If the table schema is unknown, run a DESCRIBE [table] query first to confirm column names
and types before building the main query.
If querying large tables, default to adding a LIMIT 10000 clause unless the user explicitly
requests a full pull.
Do not log or expose raw password values in any output or error messages.

Troubleshooting and tips

  • Permissions: The connecting user needs at minimum SELECT privileges on the target database. For Plotly Studio to enumerate tables and schema, SHOW DATABASES and SHOW TABLES permissions are also helpful. Avoid connecting as root in production environments.
  • Default port: MySQL's default port is 3306. If your instance is running on a non-standard port, confirm the correct value with whoever manages the database before connecting.
  • JDBC connections: Plotly Studio uses a JDBC-style connection under the hood. If your organization has custom connection requirements such as SSL certificates, SSH tunneling, or a non-standard auth flow, check with your database administrator before connecting.
  • Cloud providers: The connection flow is identical whether pointing at localhost or a cloud-managed MySQL instance on AWS RDS, Google Cloud SQL, or Azure. The only difference is your Host value — swap 127.0.0.1 for your cloud endpoint URL.

Connect to MySQL in minutes with Plotly Studio

Download today for free and get started with Plotly Studio.

GET STARTED
Bluesky icon
X icon
Instagram icon
Youtube icon
Medium icon
Facebook icon

Product

© 2026
Plotly. All rights reserved.
Cookie Preferences