Are you curious about bringing the power of the MySQL database to your Android device by using Termux?
If you’re curious, in this article, I will show you how to install MySQL in Termux and its usage.
What is MySQL
MySQL is a tool that is used for organising and managing data. It was free to use and open source. Most people use MySQL to store and manage data for their websites and web applications. MySQL is developed and maintained by a company called Oracle.
How to install MySQL in Termux
To use MySQL in Termux, we will install the Mariadb tool, which is a fork of MySQL. Mariadb is a similar tool to MySQL. Here’s how you can install MySQL in Termux with the help of Mariadb.
Open your Termux and copy and paste the following commands one by one to install MySQL data management system in Termux:
- Update and upgrade Termux packages:
apt update && apt upgrade -y
- Install Mariadb as it is a fork of MySQL.
pkg install mariadb -y
- Allow Termux access to device internal storage.
termux-setup-storage
- Once the MariaDB installation is complete, start the server by:
mysqld_safe &
- Open another session in Termux and log in to the MySQL server:
mysql -u root
After following those simple commands, MySQL will be successfully installed in your Termux.
How to use MySQL in Termux
Here are some MySQL Termux commands that you can use to use the MySQL server in Termux.
- Use this command to create a new database:
CREATE DATABASE my_database;
- To see all databases:
show databases;
- To use a database:
use my_database;
- To see tables of a database:
show tables;
- Create a new table and insert some data into it:
USE my_database;CREATE TABLE my_table (id INT, data VARCHAR(100));INSERT INTO my_table (id, data) VALUES (1, 'Sample Data');
- View data in a table:
SELECT * FROM my_table;
- To update data in a table:
UPDATE my_table SET name = 'example data 3' WHERE id = 1;
- To Deleting data from a table:
DELETE FROM my_table WHERE id = 1;
- Create a new user and grant appropriate privileges:
GRANT ALL ON my_database.* TO 'my_user'@'localhost' IDENTIFIED BY 'my_password';FLUSH PRIVILEGES;
- Exiting MariaDB
exit
These are some of the basic MySQL commands that you can use in Termux to use MySQL.
Conclusion
MySQL installation in Termux is a simple and easy process that users can easily install and use SQL data management system directly on their Android devices.
You can use MySQL for various purposes, like development, testing, or learning.
In this article, I have provided an easy guide on how to install MySQL in Termux.
I have also provided some basic MySQL commands so that you can use MySQL in Termux easily.