This topic describes how to connect to a PolarDB for AI cluster and the requirements for AI SQL statements.
Connect to a cluster
When you use the PolarDB for AI feature, regardless of whether you connect to the cluster by using DMS, connect to the cluster by using a client, or connect to the cluster by using the command line, you must use the PolarDB Cluster Endpoint instead of the PolarDB Primary Endpoint to connect to the cluster. On the Database Connection page, you can view two types of connection endpoints: the Primary Endpoint and the Cluster Endpoint. We recommend that you use the Cluster Endpoint. Its mode is Read/Write (automatic read/write splitting). Copy the corresponding private address or public address to connect to the cluster. If you need other connection methods, you can click Create Custom Endpoint.
Notes
Connect from the command line
To use a hint when connecting from the command line, add the -c option. For example:
mysql -h<your_cluster_endpoint> -P<port> -u<your_username> -p<your_password> -c
Connect using DMS
By default, DMS connects using the Primary Endpoint. To use the Cluster Endpoint instead, follow these steps:
-
After connecting to the cluster using DMS, find your target cluster in the left-side navigation pane under . Right-click the cluster and select Edit.
-
In the dialog box that appears, change the to Connection String, enter the Cluster Endpoint, and then click Save.
The original SQL console uses the Primary Endpoint to connect to the cluster. After you change the Connection String, close the original SQL console and open a new one to execute SQL statements.
AI SQL specification
In PolarDB for AI, SQL statements that support features and models are called PolarDB extended SQL, or AI SQL.
When you execute an AI SQL statement, you must prefix it with /*polar4ai*/. The statement is then added to the audit log.
For example:
/*polar4ai*/CREATE FEATURE test_graph_1 WITH (feature_class='graph') AS (SELECT ip, user_id FROM small_sample limit 30);