Snapey's avatar
Level 122

SQLlite remote management

Whats the best way to manage a sqlite database over an SSH connection to a production site?

0 likes
5 replies
LaryAI's avatar
Level 58

To manage an SQLite database over an SSH connection to a production site, you can use a combination of SSH for secure access and a command-line SQLite client for database management. Here’s a step-by-step solution:

  1. SSH into the Production Server: First, you need to establish an SSH connection to your production server. You can do this using a terminal or an SSH client like PuTTY.

    ssh username@your-production-server-ip
    
  2. Navigate to the Directory Containing the SQLite Database: Once you are logged in, navigate to the directory where your SQLite database file is located.

    cd /path/to/your/sqlite/database
    
  3. Use the SQLite Command-Line Tool: If SQLite is installed on your server, you can use the SQLite command-line tool to manage your database. If it’s not installed, you may need to install it first.

    sudo apt-get install sqlite3  # For Debian-based systems
    sudo yum install sqlite       # For Red Hat-based systems
    
  4. Open the SQLite Database: Use the SQLite command-line tool to open your database file.

    sqlite3 your-database-file.db
    
  5. Execute SQL Commands: Once the database is open, you can execute SQL commands directly in the SQLite prompt.

    .tables  -- List all tables
    .schema  -- Show the schema of the database
    SELECT * FROM your_table;  -- Query data from a table
    
  6. Exit the SQLite Command-Line Tool: When you are done, you can exit the SQLite prompt by typing:

    .exit
    

Example Workflow

Here’s an example workflow to list all tables in your SQLite database:

ssh username@your-production-server-ip
cd /path/to/your/sqlite/database
sqlite3 your-database-file.db
.tables
.exit

Additional Tips

  • Backup Your Database: Before making any changes, it’s a good practice to back up your SQLite database file.

    cp your-database-file.db your-database-file-backup.db
    
  • Use SSH Tunneling for Remote Access: If you prefer to use a graphical SQLite management tool on your local machine, you can set up an SSH tunnel to securely connect to the SQLite database on your production server.

    ssh -L 12345:localhost:5432 username@your-production-server-ip
    

    Then, connect your local SQLite management tool to localhost:12345.

By following these steps, you can securely manage your SQLite database over an SSH connection to your production site.

Tray2's avatar

Tableplus is what I would use.

Snapey's avatar
Level 122

@Tray2 I tried beekeeper studio and whilst it can manage sqlite databases, it cannot over SSH.

Presumably since its a file connection and not an IP/socket connection

JussiMannisto's avatar

@Snapey I haven't used beekeeper studio, but can't you define an SSH tunnel for the connection?

Edit. I mean within the app, not manually like Lary is suggesting. All of the clients I've ever used have had that option when setting up a connection.

Tray2's avatar

@Snapey Tableplus has support for SQLite over SSH, so it should work just fine.

Please or to participate in this conversation.