> 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/18.-connecting-your-local-database.md).

# 18. Connecting Your Local Database

This guide will help you connect your local database to AI2sql using ngrok. By following these steps, you can securely expose your local database to AI2sql, enabling seamless integration.

### Step 1: Install ngrok

#### 1.1 Download ngrok

* Go to the [ngrok download page](https://ngrok.com/download).
* Download the appropriate version for your operating system.

#### 1.2 Install ngrok

* Extract the downloaded file to a directory accessible from the command line.

#### 1.3 Create an ngrok Account

* Sign up for a free ngrok account at [ngrok signup page](https://dashboard.ngrok.com/signup).

#### 1.4 Authenticate ngrok

* Copy your auth token from the ngrok dashboard.
* Open your terminal and run the following command, replacing `<your_auth_token>` with the token you copied:

  ```sh
  ngrok authtoken <your_auth_token>
  ```

### Step 2: Start ngrok Tunnel

#### 2.1 Start the Tunnel

* For a local MySQL database running on port 3306, run the following command:

  ```sh
  ngrok tcp 3306
  ```

#### 2.2 Copy the Forwarding URL

* After starting the tunnel, ngrok will provide a forwarding URL in the format `tcp://0.tcp.ngrok.io:12345`.
* Copy this URL; you will need it to connect AI2sql to your local database.

### Step 3: Connect ngrok URL to AI2sql

#### 3.1 Open AI2sql

* Log in to your AI2sql account.

#### 3.2 Navigate to Database Connectors

* Go to the database connectors section within AI2sql.

#### 3.3 Add a New Database Connection

* Click on "Add New Connection" or a similar option.

#### 3.4 Enter Connection Details

* **Database URL:** Paste the ngrok forwarding URL you copied earlier (e.g., `tcp://0.tcp.ngrok.io:12345`).
* **Username:** Enter your local database username.
* **Password:** Enter your local database password.
* **Database Name:** Enter the name of your local database.

<div align="left"><figure><img src="/files/A41z8FnlDXAbxRhC5ziN" alt="" width="375"><figcaption></figcaption></figure></div>

<div align="left"><figure><img src="/files/WfrBcYEeWcBM22x9Pkdj" alt="" width="375"><figcaption></figcaption></figure></div>

#### 3.5 Save the Connection

* Save the new database connection settings.

#### 3.6 Test the Connection

* Use the test connection feature (if available) to ensure everything is set up correctly.

### Step 4: Using the Database in AI2sql

* You can now use your local database in AI2sql as if it were a cloud-based database.
* Enjoy the features and benefits of AI2sql with your local data securely connected.

### Troubleshooting

#### Common Issues

* **Tunnel Not Working:** Ensure ngrok is running and you have copied the correct forwarding URL.
* **Authentication Failed:** Double-check your database username and password.
* **Connection Timeout:** Verify that your local database is running and accessible.

#### Getting Help

* Visit the [ngrok documentation](https://ngrok.com/docs) for more detailed information.
* Check the AI2sql help center for additional support.


---

# 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/18.-connecting-your-local-database.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.
