Creating an account
- Log in to the TDSQL Console, select the desired instance, and click the instance name or Manage in the "Operation" column to enter the instance management page.
- Select the Manage Account tab and click Create Account.
- In the pop-up dialog box, enter the account name, host, password, and remarks and click OK after confirming that everything is correct.
The host name is actually the network egress address. If needed, you can enter % to indicate that every IP can be accessible.
- In the permission modification dialog box, after granting permissions as needed, click "Save Settings" to complete the permission granting. If you want to set permissions later, click "Set Later".
The navigation bar on the left provides a graphical interface fully compatible with MySQL management. Permissions can be managed at the column level.
- Return to the account list. Click Modify Permission to modify the user permissions, click Clone Account to completely copy the current account permissions and create a new account, or click More to reset the password or delete the account.
Obtaining the public network address
- Enter the instance details page and click Enable in the public network address bar in the basic info section.
- After this, the public network address and port number can be obtained. TDSQL provides a unique IP and port for access and use.
After creating an account and obtaining its public network address, you can connect to TDSQL through third-party tools and program drivers.
- On Windows, connection methods of command line, client, and JDBC driver are taken as examples.
- On Linux, connection method of command line is taken as an example.
Connecting via Windows command line
- Open the Windows command line and enter the following command in the correct path to MySQL.
mysql -h public network address -P port number -u username -p
Enter password: **********
- After the relevant code is entered correctly, the following message will be displayed, indicating that the database is successfully connected to. Then, you can perform operations on the database.
Welcome to the MySQL monitor. Commands end with ; or \g.
Connecting via Windows client
- Download a standard SQL client such as MySQL Workbench and SQLyog. SQLyog is taken as an example here.
- Open SQLyog, select File > New Connection, enter the corresponding host address, port, username, and password, and click Connect.
- MySQL host address: Enter the public network address obtained earlier.
- Username: Enter the name of the account created earlier.
- Password: Enter the account password.
- Port: Enter the port corresponding to the public network address.
- The following screen will appear after successful connection, where you can perform operations on the database.
Connecting via Windows JDBC driver
TDSQL supports connecting via program drivers. This document uses Java JDBC Driver for MySQL (Connector/J) as an example to describe how to connect to TDSQL.
- Download the .jar package of JDBC from MySQL's official website and import it into the library referenced by Java.
- The code to call JDBC is as follows:
public static final String url = "public network address";
public static final String name = "com.mysql.jdbc.Driver";
public static final String user = "username";
public static final String password = "password";
Connection conn=DriverManager.getConnection("url, user, password");
- After successful connection, you can perform operations on the database.
Because TDSQL needs to mark the shardkey when sharding and inserting data, these operations cannot be called with JDBC.
Connecting via Linux command line
This document takes CentOS 7.2 64-bit on a CVM instance as an example. For CVM instance purchase, see Purchase Method.
- Log in to Linux and enter the command
yum install mysql to download and install a MySQL client from a Tencent Cloud image source with Yum, CentOS' built-in package manager.
complete is displayed on the command line, the MySQL client is successfully installed.
- Enter the command
mysql -h public network address -P port -u username -p to connect to TDSQL. Then, you can perform sharding.
show databases; is taken as an example below: