An easy way for students to install and run a MySQL server on their Android device.
Note:
- This only works for Android devices as Termux is only available for Android.
- This is only meant for learning purposes and must not be used for commercial purposes.
- Install the Termux app from F-Droid here.
- Open the application, copy-paste the command given in the next section and press enter. Now the installation will begin. Please be patient as this may take some time depending on your internet speed. During installation, a popup similar to the one shown below will appear, asking you something along the lines of "Stop optimizing battery usage?". Press 'allow' or equivalent. This is required so that the MySQL server can keep running in the background even when the Termux app is closed.
- When the entire installation process is completed, a message saying "MySQL installed successfully" should appear at the end. Now, the MySQL server has started on your machine. Enter the command
setpass
and set the password (for now) as 1234. Note that this sets the password for the user root. Also note that this can only be done while the server is running. - To confirm that the server has been set up correctly, you must first install PyMySQL, which is a Python library that allows you to connect to your MySQL databases through Python, and then run the sample.py file. To do so, enter the command
pip install pymysql
to install it and thenpython sample.py
to run the file. You should see the following output:
You can change your password to something else by entering the commandsetpass
after confirming that the outputs match. - Enter the command
start-client
to start the MySQL client. You will be asked to enter a password. Type in the password you had last set up usingsetpass
. You can now use MySQL commands to create and manage databases on your phone. - Close the Termux application. The MySQL server will keep running in the background. You can use Python libraries, like PyMySQL mentioned before, to create and manage databases through an app like Pydroid (avaialable on Google Play here), which is a Python IDE and compiler for Android.
You can also go to settings and turn off notifications for Termux if you find its permanent notification bothersome.
This is the command to be entered in step 2:
yes | pkg upgrade && pkg in git python -y && cd && git clone "https://github.com/anay-p/mysql-for-termux.git" && cd mysql-for-termux && python installer.py && source ~/../usr/etc/bash.bashrc
-
If you get any errors during or after installation, type into the Termux terminal (after the '$' symbol):
cat logs.log
and submit a screenshot of the output.
-
If you get the following error when you enter
setpass
orstart-client
into the terminal:ERROR 2002 (HY000): Can't connect to local server through socket '/data/data/com.termux/files/usr/var/run/mysqld.sock' (2)
Type into the terminal the command
start-server
to start the MySQL server. You should get this output at the end: "MySQL server started". Now try usingsetpass
/start-client
again and everything should work normally.
If you are still getting errors anyway, then run the commandcat logs.log
and submit a screenshot of the output.