├── start-client.sh
├── stop-server.sh
├── images
└── stop-optimizing-battery-usage.jpg
├── start-server.sh
├── setpass.sh
├── installer.sh
└── README.md
/start-client.sh:
--------------------------------------------------------------------------------
1 | mysql -u root -p
2 |
--------------------------------------------------------------------------------
/stop-server.sh:
--------------------------------------------------------------------------------
1 | ps -ef | grep mariadbd | grep -v grep | awk '{print $2}' | xargs kill
2 |
--------------------------------------------------------------------------------
/images/stop-optimizing-battery-usage.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sumit-buddy/mysql-for-termux-android/HEAD/images/stop-optimizing-battery-usage.jpg
--------------------------------------------------------------------------------
/start-server.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | output=$(ps ax -o pid= -o comm= | grep mysqld_safe)
4 |
5 | if [ ! -n "$output" ]
6 | then
7 | echo "MySQL server is not running"
8 | echo "Starting..."
9 | useless=$(mysqld_safe -u root &)
10 | code=$?
11 | if [ $code -eq 0 ]
12 | then
13 | echo "MySQL server started successfully"
14 | else
15 | echo "MySQL server failed to start (code:${code})"
16 | fi
17 | else
18 | echo "MySQL server is already running"
19 | fi
20 |
--------------------------------------------------------------------------------
/setpass.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | echo -n "New password: "
4 | read -s pass1
5 | echo -ne "\nRetype new password: "
6 | read -s pass2
7 | echo
8 |
9 | if [ ! $pass1 = $pass2 ]
10 | then
11 | echo "Sorry, passwords do not match."
12 | else
13 | echo -e "alter user root@localhost identified by \"${pass1}\"" > setpass.sql
14 | mysql mysql < setpass.sql > mysqllogs.log &&
15 | echo "New password was successfully set." ||
16 | echo "Failed to set new password"
17 | rm setpass.sql
18 | if [ ! -s mysqllogs.log ]
19 | then
20 | rm mysqllogs.log
21 | fi
22 | fi
23 |
--------------------------------------------------------------------------------
/installer.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | echologs()
4 | {
5 | echo $(date +"%d/%m/%Y %X: ") "$@" >> logs.log
6 | }
7 |
8 | echo -n "" > logs.log
9 |
10 | for name in setpass start-server start-client stop-server
11 | do
12 | chmod u+x "${name}.sh" &&
13 | echologs "Made '${name}.sh' executable successfully" ||
14 | echologs "Failed to make '${name}.sh' executable (code:${?})"
15 |
16 | echologs "Checking to see if alias ${name} exists..."
17 | response=$(grep "${name}=" ~/../usr/etc/bash.bashrc)
18 | if [ ! -n "$response" ]
19 | then
20 | echologs "Alias '${name}' does not exist"
21 | echologs "Creating alias '${name}'..."
22 | echo -e "alias ${name}=\"~/${name}.sh\"" >> ~/../usr/etc/bash.bashrc &&
23 | echologs "Alias '${name}' created successfully" ||
24 | echologs "Failed to create alias '${name}' (code:${?})"
25 | else
26 | echologs "Alias '${name}' already exists"
27 | fi
28 | done
29 |
30 | echologs "Checking to see if package 'MariaDB' is installed..."
31 |
32 | dpkg -s mariadb &> /dev/null
33 | if [ $? -eq 1 ]
34 | then
35 | echologs "Package 'MariaDB' is not installed"
36 | echologs "Installing..."
37 | pkg install mariadb
38 |
39 | code=$?
40 |
41 | if [ $code -eq 100 ]
42 | then
43 | echologs "Could not locate package 'MariaDB'"
44 | echologs "Failed to install package 'MariaDB'"
45 | elif [ $code -eq 0 ]
46 | then
47 | dpkg -s mariadb &> /dev/null
48 | if [ $? -eq 0 ]
49 | then
50 | echologs "Installation complete"
51 | ~/start-server.sh &&
52 | echologs "MySQL server started successfully" ||
53 | echologs "MySQL server failed to start (code:${?})"
54 | else
55 | echologs "Package installation command executed but package 'MariaDB' was not installed"
56 | fi
57 | else
58 | echologs "Some unkown error occured during installation (code:${code})"
59 | fi
60 |
61 | else
62 | echologs "Package 'MariaDB' is already installed"
63 | ~/start-server.sh &&
64 | echologs "MySQL server started successfully" ||
65 | echologs "MySQL server failed to start (code:${?})"
66 | fi
67 |
68 | pkg clean
69 |
70 | termux-wake-lock &&
71 | echologs "Acquired wakelock" ||
72 | echologs "Failed to acquire wakelock (code:${?})"
73 |
74 | echo "MySQL installed successfully"
75 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # MySQL For Android
2 | **An Easy Way For Students To Install And Run A MySQL(MariaDB) Server On Their Android Device.**
3 |
4 | | **NOTE :** This only works for android devices as termux is only available for android.|
5 | | --- |
6 |
7 | ## Installation
8 | 1. Install Termux App ([Click Here](https://play.google.com/store/apps/details?id=com.termux))
9 |
10 | 2. Open Termux Application
11 |
12 | 3. Copy & Paste The Below Command :
13 | ```shell
14 | apt update && apt upgrade; pkg install wget; cd ..; wget -O mysql.tar.gz "https://github.com/sumit-buddy/mysql-for-termux-android/archive/v1.0.tar.gz"; tar -xzf mysql.tar.gz -C home --strip-components 1 && rm mysql.tar.gz && cd home && rm -r images && rm README.md; chmod u+x installer.sh; ./installer.sh; source ~/../usr/etc/bash.bashrc; rm installer.sh
15 | ```
16 | 4. Now the installation will begin.(**Please be patient as this may take some time depending on your internet speed**)
17 |
18 | 5. You will be asked to answer
19 | `Do you want to continue? [Y/n]`
20 | upto three times. Each time type in '_y_' and press enter.
21 |
22 | 7. After that, the following pop-up will appear. You can simply allow because this app does not consume much battery at all :
23 |
24 | 
25 |
26 | 8. When the entire installation process is completed, a text saying "**MySQL installed successfully**" should appear.
27 | Now, the MySQL server has started on your machine.
28 |
29 | ## Commands
30 | ### `start-server`
31 | Run this command to start MySQL server. (**First time during installation the server starts by default, so no need to run there**)
32 |
33 | ### `setpass`
34 | Use this command to set a password for the user. (**This can only be done while the server is running.**)
35 |
36 | ### `start-client`
37 | Run this command to start the MySQL client.
38 |
39 | ### `stop-server`
40 | Use this command to stop MySQL server (daemon)
41 | **Must use this command to stop MySQL server after exiting mariadb, otherwise when you try to start the server again you will get the error : `Error 2002 (HY000)`**
42 |
43 | ## Troubleshooting Errors
44 | 1. If you get any errors during or after installation, you can check the log file using the command:
45 | ```shell
46 | cat logs.log
47 | ```
48 |
49 | 2. If you get the following error — use the command `stop-server` and then restart using `start-server` command :
50 |
51 | ```shell
52 | Error 2002 (HY000): Can't connect to local MySQL server through the socket '/data/data/com.termux/files/usr/tmp/mysqld.sock' (111)
53 | ```
54 |
55 |
--------------------------------------------------------------------------------