# Connecting to SQLite from the command line

> Open and query a SQLite database over SSH using the sqlite3 command-line program and its built-in commands.

Source: https://helpcenter.ruachost.com/developers/databases/connecting-to-sqlite-from-the-command-line/

SQLite is a lightweight, serverless database engine. On **ruachost.com**, you can connect to SQLite databases directly from the command line using the `sqlite3` program.

## Why Use the Command Line?

- Quick and easy access to SQLite databases.
- Run SQL queries without needing a GUI.
- Useful for debugging, scripting, and development.

## Steps to Connect to SQLite

### Step 1: Log in via SSH

- Use SSH to connect to your hosting account:

```bash
ssh username@yourserver.ruachost.com
```

### Step 2: Run the `sqlite3` Command

- At the command line, type:

  ```bash
  sqlite3 example.db
  ```

- Replace `example.db` with the name of your database file.
- If the file does not exist, SQLite will create it.
- If the file exists, SQLite will open the database contained in it.

## Step 3: Use SQLite Commands

Once inside the `sqlite>` prompt, you can run SQL queries and special commands:

- ### Show tables

  ```
  .tables
  ```

- ### View table structure

  ```bash
  .schema tablename
  ```

- ### List all commands

  ```bash
  .help
  ```

- ### Exit SQLite

```bash
.quit
```

> **Important Notes:**
- SQLite databases are stored as disk files, making them portable across systems.
- You can copy `.db` files between 32‑bit and 64‑bit systems without issues.
- Always back up your database file before making major changes.
- SQLite is transactional, ensuring data integrity even in case of crashes.
