How to Connect to Database
Learn how to connect Excel directly to external databases like SQL Server, MySQL, or Oracle to import live data without manual copying. This skill enables real-time data analysis, eliminates manual entry errors, and lets you refresh data instantly—essential for business intelligence and large-scale data workflows.
Why This Matters
Database connections automate data retrieval, ensure accuracy, and save hours of manual work—critical for data analysts, financial teams, and enterprise users managing large datasets.
Prerequisites
- •Active database account with connection credentials (server address, username, password)
- •Database driver installed (ODBC driver or native SQL driver)
- •Network access to the database server
- •Basic understanding of SQL queries (optional but helpful)
Step-by-Step Instructions
Open Data Tab and Access External Data
Click Data tab > Get & Transform Data > Get Data > From Database (SQL Server Database for SQL, or From Other Sources for MySQL/Oracle).
Enter Database Connection Details
Input Server name, Database name, and select either Windows or SQL Server authentication. Enter username and password if required, then click OK.
Select Tables or Write SQL Query
Browse available tables in Navigator window, select the table(s) needed, or click Advanced Options to write a custom SQL query for filtered data.
Load Data into Excel
Click Load to import data directly into a new worksheet, or Load To to choose specific cell placement or create a pivot table instead.
Refresh Connection and Manage Updates
Right-click the imported table > Refresh to update data. Use Data > Queries & Connections to manage, edit, or schedule automatic refreshes.
Alternative Methods
Using Power Query (Advanced)
Data > Get & Transform Data > New Query > From Database allows more granular control over transformations and combines multiple queries before loading.
ODBC Data Source Connection
Set up a system-wide ODBC data source in Windows, then use Data > Get Data > From ODBC for a pre-configured connection without re-entering credentials.
Direct Connection String Method
In advanced scenarios, use VBA or Python scripting to establish connections with custom connection strings for automation and scheduled refreshes.
Tips & Tricks
- ✓Test your connection with a small query first before pulling large datasets to verify credentials work correctly.
- ✓Use Data > Queries & Connections pane to view all active database connections and manage them from one location.
- ✓Enable automatic refresh on Data > Query Options to keep data current without manual updates.
- ✓Write efficient SQL queries with WHERE and GROUP BY clauses to reduce file size and load times.
- ✓Store sensitive credentials in Excel's secure connection settings rather than in formulas or VBA code.
Pro Tips
- ★Use scheduled refresh in Excel for Microsoft 365 to automatically update your database connection on a set schedule without opening the file.
- ★Combine multiple database tables using Power Query's Merge feature to create normalized datasets before loading.
- ★Create parameterized queries with Excel cells to filter database results dynamically based on user input.
- ★Leverage DirectQuery in Power BI for real-time database connections when Excel's refresh limitations are restrictive.
Troubleshooting
Verify your database user account has SELECT permissions on the target tables. Contact your database administrator to grant appropriate privileges. Test credentials using a database client tool first.
Optimize your SQL query by adding WHERE filters, removing unnecessary columns, and using indexes. Consider importing only required data subsets instead of entire large tables.
If using file-based connections (DSN), the ODBC source may be unavailable on the new computer. Re-establish the connection or use direct connection strings instead of file DSNs.
Check if source data structure changed (columns deleted/renamed). Update your query and reload, or manually adjust column mappings in the connection properties.
Related Excel Formulas
Frequently Asked Questions
Can I connect to multiple databases simultaneously?
Will my database credentials be saved in the Excel file?
How often can I refresh database connections?
What databases does Excel support?
Can I edit the SQL query after importing data?
This was one task. ElyxAI handles hundreds.
Sign up