> For the complete documentation index, see [llms.txt](https://ai2sql.gitbook.io/ai2sql/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ai2sql.gitbook.io/ai2sql/9.-database-connectors/9.2.-setting-up-database-connections-mysql-sql-server-or-postgresql.md).

# 9.2. Setting up database connections (MySQL, SQL Server, or PostgreSQL)

<figure><img src="/files/MVt5BTCVMOAvSo24ZwsJ" alt=""><figcaption></figcaption></figure>

1. Navigate to the "Connectors" section from the main menu.
2. Click the "Add Connector" button to open the database connection setup dialog.
3. Select the desired database type (MySQL, SQL Server, or PostgreSQL) and provide the necessary connection information, such as hostname, port, username, and password.
4. Provide Connection Information
   * **Hostname or IP address**: Enter the server name or IP address where the database is hosted. Make sure it's accurate and reachable from your network. If possible, use the IP address instead of the DNS name to avoid resolution issues.
     * If your database server is hosted on your local machine or within your private network, entering "localhost" or a private IP address (e.g., 192.168.x.x) might not work if the AI2sql platform is hosted externally. In such cases, you may need to set up port forwarding or use a VPN/SSH tunnel to securely expose your database server to the internet. For help connecting to a local database, visit [connecting to localhost](/ai2sql/18.-connecting-your-local-database.md)
   * **Port**: Provide the port number on which your database server is listening for connections. This value is usually the default port for your chosen database type (e.g., 3306 for MySQL, 5432 for PostgreSQL, 1433 for SQL Server). It's not necessary to enter the port number for SQL Server.
   * **Database Name**: Enter the name of the database you want to connect to. Ensure that it's spelled correctly and case-sensitive, if applicable.
   * **Authentication**: Select the appropriate authentication method (e.g., username/password) based on your database server's configuration.
   * **Username**: If using username/password authentication, enter the username with the necessary privileges to access the database.
   * **Password**: If using username/password authentication, enter the password associated with the provided username.
   * Add the AI2sql connector's IPs to your firewall's whitelist, if necessary. (52.151.220.65,52.151.220.76,52.151.220.92,52.151.220.113,52.151.220.203,52.151.220.211,\
     20.119.16.24)

<mark style="color:green;">Note: If the direct connection to your database does not work for you, as an alternative, you can add your DDL (Data Definition Language) script to AI2sql. This way, you can still use our platform to generate SQL queries without directly connecting to your database. Follow the guide below to learn how to add your DDL script to AI2sql:</mark> [<mark style="color:green;">https://ai2sql.gitbook.io/ai2sql/3.-managing-tables/3.1.-importing-tables-using-ddl</mark>](https://ai2sql.gitbook.io/ai2sql/3.-managing-tables/3.1.-importing-tables-using-ddl)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://ai2sql.gitbook.io/ai2sql/9.-database-connectors/9.2.-setting-up-database-connections-mysql-sql-server-or-postgresql.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
