How to run a Direct Query on an ArchivesSpace database with a Read Only account
Problem/Question
A user wants to generate a custom report using a SQL query.
Resolution
If you need to run a query directly on an ArchivesSpace database, you can use Microsoft Excel to pass the MySQL query without having to pre-load the tables.
Prerequisites
You will need:
- A Read-Only MySQL account and password (usually created by your hosting provider or if locally hosted your database administrator)
- Microsoft Excel with Power Query installed
- The ADO.NET Driver for MySQL (Connector/NET) installed on the local machine
- You may need a local administrator account on your machine to install the supporting items listed above
Steps
-
Launch Microsoft Excel (you'll need at least a version that supports Power Query)
-
Select the Data tab and then Get Data | From Database | From MySQL Database (Some versions of Excel have New Query | From Database instead)
-
On the MySQL database screen that appears, select the Advanced options, and complete the form by entering:
- Server IP
- The database name (archivesspace)
- A Command timeout in minutes value
- The SQL select statement/query
-
Leave the default 'Include relationship columns' checked and click OK.
-
The query results will load into Excel in the Power Query Editor window.
Additional Notes
- The query results can be refreshed at any time using the Refresh button in Excel
- You can save the Excel workbook with the connection information for future use
- Consider creating views in the database for frequently-used complex queries
- Always test your queries with LIMIT clauses first to avoid overwhelming Excel with large result sets