preface
Android as a mobile device, although not originally designed as a server, with the advancement of technology we can configure Android as a productivity tool and turn it into a portable Linux.
MariaDB is a fork of the MySQL relational database management system, developed by the community and commercially supported, and designed to remain open source under the GNU GPL. One of the reasons for developing this branch is that after Oracle acquired MySQL, there was a potential risk of closing MySQL, so the community adopted a branching approach to avoid this risk.
Next, we install the MariaDB (mysql) database on the Android phone termux in a few simple steps, and combine with cpolar intranet penetration to achieve remote connection access in the public network environment.
1. Install MariaDB
Termux also officially encapsulates MariaDB, so it is easy to install:
pkg install mariadb
Verify that the installation is successful and view the version information
mysql --version
The version information indicates that the installation was successful
Start the database and start it in the background using the nohup command that comes with Linux
nohup mysqld &
You can see the process PID number after startup
If you want to turn off MySQL, you can do:
kill -9 PID
2. Install the Cpolar intranet penetration tool
After successfully installing the MySQL database on Android termux, we continue to install cpolar on termux to create a secure tunnel through the internal network to expose MySQL to the public network, so that you can remotely connect to the MySQL database on termux under different networks.
cpolar does not require a public IP, does not need to set up a router, and does not need to buy a cloud server. It supports HTTP/HTTPS/TCP protocol and can be used for free without limiting traffic.
Cpolar official website: https://www.cpolar.com/
Create a folder for sources.list.d:
mkdir -p $PREFIX/etc/apt/sources.list.d
Add cpolar to download the source file
echo "deb [trusted=yes] http://termux.cpolar.com termux extras" >> $PREFIX/etc/apt/sources.list.d/cpolar.list
Update the repository
pkg update
Install cpolar
pkg install cpolar
Install the termux service, note: After the installation is completed, remember to close and restart termux to take effect!!
pkg install termux-services
After restarting Termux, then start Cpolar intranet penetration
sv up cpolar
Set up automatic boot
sv-enable cpolar
Also: the command to stop the cpolar service
sv down cpolar
Also, the cpolar.yml main configuration file path location
$PREFIX/etc/cpolar/cpolar.yml
Then in the mobile browser, we enter the http://localhost:9200, we can see the cpolar web UI management interface, and you can log in using the email account registered on the cpolar official website
3. Create a secure tunnel mapping mysql
After logging in to the cpolar web UI management interface, we click on the tunnel management on the left dashboard - create tunnel, since the mysql connection defaults to port 3306, we want to create a TCP tunnel pointing to port 3306:
- Tunnel Name: Customizable, be careful not to repeat it
- Protocol: TCP
- Local address: 3306 (MySQL default port)
- Domain type: Select Random domain
- Region: Select China VIP
Click Create
After the online tunnel list is created, you can view the generated random public TCP address and copy it, note that there is no need to copy tcp://
4. Remote connection to the Internet
Above we create a public network address, next we use the tool remote connection test, this article uses a more popular database connection tool software navicat, open the tool interface, enter our public network address and corresponding port above, because there is no password set when it is created, so we do not need to fill in the password, click to test the connection, the connection is successful means normal.
Similarly, other connection tools have the same connection method.
5. Fixed the remote connection address
Since we used a free random temporary address when creating a tunnel above, the generated public network address will change randomly within 24 hours. If we want to make the data tunnel between different devices stable for a long time, we need further settings (because the fixed TCP tunnel will occupy cpolar server resources for a long time, so this service has to be included in the VIP project).
To establish a stable TCP data tunnel, you need to go to the cpolar official website background to reserve a fixed TCP address.
We log in to the background of cpolar's official website, click on the reservation on the left dashboard, and find the reserved TCP address:
- Region: Choose China VIP here, you can also choose other regions
- Description: Customizable notes
On the right, click Hold
After filling in this information, click the Keep button on the right to fix the tunnel in the background of Cpolar's official website. At this point, Cpolar will generate a tunnel TCP port
Then we return to the browser cpolar web UI management interface, open the tunnel list, find the random temporary TCP tunnel created earlier, and enter the editing page:
Port TypeSelect Fixed TCP Port, then paste the tunnel port we obtained on the cpolar official website into the reserved TCP address bar, and then click the Update button below
Then check the online tunnel list again, and you can find that the public network address corresponding to the tunnel of MySQL has become the fixed address reserved by our official website
After configuring the public address of remote MySQL to be fixed, let's test that using a fixed public network address to connect is also possible to connect remotely to termux MySQL.
Now as long as we keep this tunnel online, we can remotely connect to Termux MySQL through this public network address.