Redash
Redash is an open-source business intelligence (BI) tool that supports various data sources, such as MySQL and PostgreSQL. It provides an intuitive web interface to explore and visualize your data. This article shows how to connect Redash to AnalyticDB for MySQL.
Prerequisites
-
Redash is installed. For instructions, see the Redash official documentation.
-
The IP address of the server where Redash is running is in the AnalyticDB for MySQL cluster's whitelist. For instructions, see whitelist.
-
If you want to connect to a Spark JDBC endpoint, you must also create a Spark Interactive resource group.
Connect to an AnalyticDB for MySQL endpoint
-
After you start Redash, enter
http://<IP address>:<port number>in your browser to open the Redash web interface.IP address: The IP address of the Redash server.Port number: The default port is 5000. If port 5000 is already in use, you can specify a different port when you start Redash. -
In the left navigation pane, click Settings. On the Data Sources tab, click +New Data Source.
-
In the Create a New Data Source dialog box, configure the following parameters, and then click Create.
Parameter
Description
Type Selection
Select MySQL from the drop-down list.
Configuration
Name
A custom name for the data source.
Host
The connection endpoint of your AnalyticDB for MySQL cluster.
-
If Redash is installed on an ECS instance in the same VPC as the AnalyticDB for MySQL cluster, enter the ECS.
-
If Redash is installed on a local server, enter the public endpoint.
Port
The port number. The value is fixed at 3306.
User
The database account for the AnalyticDB for MySQL cluster.
Password
The password for the AnalyticDB for MySQL database account.
Database Name
The database in the AnalyticDB for MySQL cluster.
-
-
In the left navigation pane, click . In the editor, write a SQL statement and click Execute.
If the query runs successfully, the results appear in a table below the editor. This confirms a successful connection to the AnalyticDB for MySQL endpoint.
-
After the SQL statement runs, you can click + Add Visualization to create a visualization from the results. For more information, see the Redash official documentation.
In the Visualization Editor dialog box, set Visualization Type to Chart and Chart Type to Bar. Configure the X Column (for example,
name) and Y Columns (for example,age). A real-time preview of the bar chart appears on the right. After you confirm the settings, click Save.
Connect to a Spark JDBC endpoint
Prepare the environment
-
(Optional) Copy the adb_spark.png file to the target path.
-
For a source code deployment of Redash, the target path is
<root directory of the source code>/client/app/assets/images/db-logos/. -
For a Docker image deployment of Redash, the target path is
</app directory>/client/dist/images/db-logos/.NoteThe /app directory is in the
redash_server,redash_scheduler,redash_adhoc_worker, andredash_scheduled_workercontainers.
-
-
Copy the adb_spark_ds.py file to the target path.
-
For a source code deployment of Redash, the target path is
<root directory of the source code>/redash/query_runner/. -
For a Docker image deployment of Redash, the target path is
</app directory>/redash/query_runner/.NoteThe /app directory is in the
redash_server,redash_scheduler,redash_adhoc_worker, andredash_scheduled_workercontainers.
-
-
Add the
'redash.query_runner.adb_spark_ds'configuration parameter to the__init__.pyfile.-
Path of the
__init__.pyfile:For a source code deployment of Redash, the target path is
<root directory of the source code>/redash/settings/__init__.py.For a Docker image deployment of Redash, the target path is
</app directory>/redash/settings/__init__.py.NoteThe /app directory is in the
redash_server,redash_scheduler,redash_adhoc_worker, andredash_scheduled_workercontainers. -
The parameter format is as follows:
default_query_runners = [ 'redash.query_runner.athena', 'redash.query_runner.big_query', ........ 'redash.query_runner.uptycs', 'redash.query_runner.adb_spark_ds' ]
-
Procedure
-
Access the Redash web interface. In the left navigation pane, click Settings. On the Data Sources tab, click +New Data Source.
-
In the Create a New Data Source dialog box, configure the following parameters, and then click Create.
Parameter
Description
Type Selection
Select ADB Spark from the drop-down list.
Configuration
Name
A custom name for the data source.
Host
The connection endpoint for the Spark Interactive resource group. For information about how to obtain the endpoint, see Prepare the environment.
Port
The port number for the Spark Interactive resource group. The value is fixed at 10000.
Database
The database in the AnalyticDB for MySQL cluster.
Username
The database account for the AnalyticDB for MySQL cluster.
Password
The password for the AnalyticDB for MySQL database account.
Resource Group
The name of the Spark Interactive resource group.
-
In the left navigation pane, click . In the editor, write a SQL statement and click Execute.
For example, run the query
select * from test_db.test_tbl. If the query runs successfully, the results appear on the Table tab. -
After the SQL statement runs, you can click + Add Visualization to create a visualization from the results. For more information, see the Redash official documentation.
In the Visualization Editor dialog box, set Visualization Type to Chart and Chart Type to Bar. For the X Column, select
name, and for the Y Columns, selectage. A preview of the bar chart appears on the right. After you confirm the settings, click Save.