Sometimes you don’t need a big, full-scale database server — you just need a lightweight SQL environment that runs directly on your phone. With Termux , you can set up a mini SQL server like SQLite or even MySQL right on your Android device. This is perfect for learning databases, testing queries, or running small apps without carrying a laptop everywhere.
In this guide, we’ll go step-by-step on installing and hosting a SQL server in Termux, so you can manage databases anytime, anywhere. We’ll also include tips for keeping your setup secure, similar to how you would protect a small business cybersecurity plan.
Why Run a SQL Server on Termux?
Running SQLite or MySQL in Termux can be useful for:
- Testing SQL queries without a desktop or cloud server.
- Developing apps that require local database storage.
- Learning SQL commands in a hands-on environment.
- Hosting small, personal databases on the go.
It’s also a great skill-building project, much like the ideas in Quick Termux Projects that you can try at home.
Option 1: Hosting SQLite on Termux
SQLite is perfect if you want something lightweight that doesn’t require a constant server process. It stores the database in a single file and runs directly from the command line.
Installing SQLite
pkg update && pkg upgrade -y
pkg install sqlite
To create a new database:
sqlite3 my_database.db
Inside the SQLite shell, you can run SQL commands like:
CREATE TABLE users(id INTEGER PRIMARY KEY, name TEXT, email TEXT);
INSERT INTO users (name, email) VALUES ('Alice', 'alice@example.com');
SELECT * FROM users;
Exit with:
.exit
Option 2: Hosting MySQL (MariaDB) on Termux
If you want something closer to a production environment, MySQL (or its open-source fork MariaDB) is the way to go.
Installing MariaDB
pkg update && pkg upgrade -y
pkg install mariadb
Starting the MySQL Server
mysqld_safe &
Secure the installation (set root password and remove test DBs):
mysql_secure_installation
Logging Into MySQL
mysql -u root -p
Once inside the MySQL prompt, you can create and manage databases:
CREATE DATABASE testdb;
USE testdb;
CREATE TABLE products(id INT PRIMARY KEY, name VARCHAR(50), price DECIMAL(10,2));
INSERT INTO products VALUES(1, 'Laptop', 1200.00);
SELECT * FROM products;
Accessing Your Database Remotely
If you want to connect to your SQL server from another device, you can use Ngrok to expose the MySQL port securely over the internet. But remember — exposing a database server to the internet without proper security is risky. The same way you protect against cyber threats, you need to protect your SQL server.
Best Practices for Security
- Always set strong passwords for database users.
- Limit access to local network or specific IP addresses.
- Regularly back up your databases, just like you would safeguard data in network security.
- Use a VPN like Surfshark when accessing the database over public Wi-Fi.
Why This is a Game-Changer
Hosting a mini SQL server on your phone means you can test apps, learn database administration, or even keep private offline databases without needing a cloud subscription. It’s especially useful for developers, students, or cybersecurity learners who want full control of their environment — similar to hosting your own web server in Termux.
Final Thoughts
Whether you choose SQLite for simplicity or MySQL for more robust features, running a mini SQL server on Termux is straightforward and powerful. You get hands-on SQL experience and the flexibility to work from anywhere, without needing expensive hosting services.
In the same way that linking cybersecurity to business risk helps you stay ahead of threats, having a portable SQL server helps you stay productive and ready for any database challenge.
Top comments (0)