How to Connect Tableau Public to MySQL Database
Trying to visualize data from your MySQL database without splurging on Tableau Desktop? You've come to the right place. While Tableau Public is an incredible free tool for building data visualizations, it has one major limitation: it can't connect directly to live databases like MySQL. This article will walk you through the effective and straightforward workarounds to get your MySQL data into Tableau Public so you can start creating insightful dashboards.
Why You Can't Connect Tableau Public Directly to MySQL
The core difference between Tableau Public and its paid counterpart, Tableau Desktop, lies in the data connection options. Tableau Public is designed to work with static, local files. This means it connects beautifully to formats like:
Microsoft Excel
Text files (CSV, TSV)
JSON files
PDF files
Spatial files (Shapefiles, KML)
Tableau Desktop, on the other hand, is built for business environments and includes a vast library of native connectors to live databases - MySQL, PostgreSQL, Amazon Redshift, Google BigQuery, and dozens of others. This “live connection” capability is a premium feature.
So, when you open Tableau Public and look for a MySQL connector, you won't find one. Attempting to connect directly is a dead end. But don’t worry, that doesn't mean your data is stuck in your database. You just need a different approach.
The Workaround: Using a MySQL Data Extract
The solution is to use a Tableau Data Extract. Instead of trying to maintain a live, active connection to your database, you’ll create a snapshot of your data at a specific point in time. This snapshot is saved in a highly optimized, compressed format called a .hyper file.
Here’s the basic idea:
Use a tool that can connect to MySQL (we'll cover this below).
Connect to your database and select the tables you need.
Export that data as a
.hyperextract file.Open that
.hyperfile with Tableau Public.
Once the extract is created, Tableau Public can open and analyze it with lightning speed, because it's no longer querying a remote database - it's working with a local, optimized file. The main trade-off is that your data isn't real-time. If new rows are added to your MySQL database, they won't automatically appear in your dashboard. You'll need to re-create the extract to refresh the data. For publicly shared vizzes, portfolios, and learning projects, this is often a perfectly acceptable compromise.
Step-by-Step: Connecting MySQL to Tableau Public
This process requires using the Tableau Desktop free trial to act as a bridge between your MySQL database and Tableau Public. It’s the easiest official way to generate the .hyper file you need.
Step 1: Install the MySQL Connector
Before any version of Tableau can communicate with a MySQL database, it needs the proper driver. This piece of software acts as a translator between Tableau and MySQL.
Navigate to the official MySQL Connector/ODBC download page.
Choose your operating system (e.g., Microsoft Windows).
Download and install the appropriate version (usually the 64-bit MSI Installer).
With this driver installed, your computer now knows how to handle connection requests to a MySQL server.
Step 2: Start Your Tableau Desktop Free Trial
To access the MySQL connector, you'll need Tableau Desktop. Head over to the Tableau website and download the 14-day free trial. Don't worry, you won't need the paid version permanently - just long enough to create your extracts.
Pro Tip: Wait to start your trial until you have your MySQL database credentials ready. This ensures you can make the most of the 14-day window to create all the extracts you need for your project.
Step 3: Connect Tableau Desktop to Your MySQL Database
Now, open the Tableau Desktop application you just installed. You'll be greeted by the connect screen. This is where the magic happens.
On the left-hand pane under "To a Server," click on More...
From the list, select MySQL. A connection dialog box will open.
Fill in your database credentials:
Server: The IP address or hostname of your MySQL server (e.g.,
localhostif it's on your machine, or a remote IP like123.45.67.89).Port: The default port for MySQL is
3306. Only change this if you're using a custom configuration.Database: The specific database name you want to connect to.
Username: Your MySQL username.
Password: Your MySQL password.
Click Sign In.
If you encounter an error, double-check your credentials. Are you sure the password is correct? For remote databases, common issues include firewalls blocking port 3306 or your public IP address not being whitelisted by the database administrator.
Step 4: Select Your Data and Create the Extract (.hyper) File
Once successfully connected, you will be taken to the "Data Source" screen. On the left side, you'll see a list of all the tables available in your database.
Drag the table you need from the left pane onto the main canvas area (where it says "Drag tables here"). For example, you might pull over your
orderstable.If you need to join tables, you can drag another table onto the canvas. Tableau will often automatically create the join if it recognizes a shared key (like
customer_id). You can click the join icon (the overlapping circles) to modify the join type (inner, left, right).This is the most crucial step: In the top-right corner of the Data Source page, you'll see two radio buttons: Live and Extract. Select Extract.
Now, navigate to the first worksheet by clicking the "Sheet 1" tab at the bottom of the window.
Because you selected "Extract," Tableau will immediately prompt you to save the extract file. This dialog will ask you to choose a location to save your
.hyperfile. Give it a descriptive name (e.g.,quarterly_sales_data.hyper) and save it.
This process might take a few moments, as Tableau is querying your MySQL server, pulling all the required data, and compressing it into the optimized .hyper format on your computer.
Step 5: Open the Extract in Tableau Public
Your work in Tableau Desktop is now finished! You can close it. The .hyper file you saved is the key that unlocks everything.
Open the Tableau Public application.
On the connect screen, under "Connect," find the option for Tableau Extract. Depending on your version, it might be listed directly or under "More..."
Navigate to the
.hyperfile you just saved and open it.
Your data is now loaded and ready for analysis in Tableau Public. You can build charts, create dashboards, and perform all the visualizations you need, completely free of charge.
An Alternative Method: Using a Scripting Language
If you'd rather not use the Tableau Desktop trial or if you're comfortable with a bit of code, you can use a scripting language like Python to achieve the same result. The idea is to write a script that connects to MySQL, fetches the data, and saves it into a format Tableau Public can read, like a CSV file.
This approach gives you more control and is easily automatable, which is great for refreshing your data regularly.
Here’s a simple example using Python with the pandas and SQLAlchemy libraries:
1. Install the Necessary Libraries
If you don't have them installed, open your terminal or command prompt and run:
pip install pandas sqlalchemy pymysql
2. Write the Python Script
Create a new Python file (e.g., get_data.py) and use this script as a template. Be sure to replace the placeholder connection details with your own.
import pandas as pd from sqlalchemy import create_engine
Replace with your MySQL connection details
db_user = 'your_username' db_password = 'your_password' db_host = 'your_server_ip' db_port = '3306' db_name = 'your_database'
Create the database connection string
connection_str = f"mysql+pymysql://{db_user}:{db_password}@{db_host}:{db_port}/{db_name}"
Establish the engine connection
try: engine = create_engine(connection_str) print("Connection to MySQL DB successful!") except Exception as e: print(f"Error connecting to MySQL DB: {e}") exit()
Write your SQL query here
sql_query = "SELECT * FROM sales_transactions WHERE sale_date > '2023-01-01'"
Execute the query and load the data into a pandas DataFrame
df = pd.read_sql(sql_query, engine)
Save the DataFrame to a CSV file
output_file = 'sales_data_2023.csv' df.to_csv(output_file, index=False)
print(f"Data has been successfully exported to {output_file}")
3. Open the CSV in Tableau Public
Run this script. It will generate a file named sales_data_2023.csv in the same directory. You can then open Tableau Public and connect directly to this new CSV file.
Tips for Working with Data Extracts
Filter Before Extracting: If your table has millions of rows but you only need data from the last year, add a data source filter in Tableau Desktop before creating the extract. This will make your extract file smaller and faster to generate.
Aggregate in SQL: For large datasets, consider performing aggregations directly in your SQL query. If you only need to visualize monthly sales totals, you don't need to extract every individual transaction. A
GROUP BYclause can significantly reduce the size of your extract.Schedule Your Refreshes: Since extracts are static, decide on a refresh cadence. Will you need to update it daily, weekly, or monthly? If you're using the Python script method, you can use your operating system's task scheduler (like cron on macOS/Linux or Task Scheduler on Windows) to run the script automatically.
Final Thoughts
Connecting Tableau Public to a MySQL database is entirely possible, even without native support. By using the Tableau Desktop free trial to generate a .hyper extract file, you can easily pull your database data into Tableau's powerful visualization environment, a perfect solution for public-facing reports and portfolio projects.
This process works great for static projects, but manually creating extracts can feel repetitive, especially when you need up-to-date answers quickly. We built Graphed to remove this friction. Just connect your data sources - including direct database connections - one time, and you can build auto-updating dashboards simply by asking questions in plain English. Instead of juggling trials and scripts, you can just ask, "Show me product sales by region for the last 90 days," and get a live, interactive dashboard in seconds.