Super detailed! How to install MySQL on Android Termux and achieve remote access to the public network through intranet penetration

Preface

Although Android, as a mobile device, was 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, 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 as a source, so the community adopted a branch approach to avoid this risk.

Next, we will install the MariaDB (mysql) database on the Android phone termux through a few simple steps, and combine it with cpolar intranet penetration to achieve remote connection access in the public network environment.

1. Install MariaDB

Termux also officially packages MariaDB, so it is very convenient to install:

pkg install mariadb

Verify whether the installation is successful and check the version information

mysql --version

Version information appears indicating successful installation.

image-20230511105447233

Start the database and use the command that comes with Linux nohupto start it in the background.

nohup mysqld &

After starting, you can see the process PID number

image-20230511111209798

If you want to close it mysql, you can execute:

kill -9 PID

2. Install cpolar intranet penetration tool

After successfully installing the MySQL database on Android termux, we continue to install cpolar on termux, create a secure tunnel for intranet penetration, and expose MySQL to the public network, so that the MySQL database on termux can be remotely connected to different networks.

Using cpolar does not require a public IP, setting up a router, or buying a cloud server. It supports http/https/tcp protocols and can be used for free without any traffic restrictions.

cpolar official website : https://www.cpolar.com/

Create a sources.list.dfolder:

mkdir -p $PREFIX/etc/apt/sources.list.d

Add cpolar to download source files

echo "deb [trusted=yes] http://termux.cpolar.com termux extras" >> $PREFIX/etc/apt/sources.list.d/cpolar.list

Update repository

pkg update

Install cpolar

pkg install cpolar

Install the termux service. Note: After the installation is complete, remember to close and restart termux for it to take effect!!

pkg install termux-services

After restarting termux, then启动cpolar内网穿透

sv up cpolar

设置开机自启

sv-enable cpolar

Also: command to stop cpolar service

sv down cpolar

And, cpolar.yml main configuration file path location

$PREFIX/etc/cpolar/cpolar.yml

Then we enter it in the mobile browser http://localhost:9200and you can see the cpolar web UI management interface. You can log in using the email account registered on the cpolar official website.

image-20230509155942139

3. Create secure tunnel mapping mysql

After logging in to the cpolar web UI management interface, we click Tunnel Management - Create Tunnel on the left dashboard. Since the default mysql connection is port 3306, we need 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 name type: Choose a random domain name
  • Region: Select China VIP

Click创建

image-20230511133502882

After creation, open the online tunnel list. You can view the generated random public network tcp address and copy it. Note that tcp:// does not need to be copied.

4. Public network remote connection

After we created the public network address above, we next use a tool to test remote connection. This article uses a relatively popular database connection tool software. Open the tool navicatinterface and enter our public network address and corresponding port above. Because when creating There is no password set, so we don't need to fill in the password. Click Test Connection. If the connection is successful, it means normal.

Similarly, other connection tools also use the same connection method.

image-20230511134615494

5. Fixed remote connection address

Since we used a free random temporary address when creating the tunnel above, the generated public network address will change randomly within 24 hours. If we want the data tunnels between different devices to exist stably for a long time, we need further settings (since fixed TCP tunnels will occupy cpolar server resources for a long time, this service has to be included in the VIP project).

To establish a stable TCP data tunnel, you need to first reserve a fixed TCP address in the backend of the cpolar official website.

20230519093033

We log in to the cpolar official website backend, click on the reservation on the left dashboard, and find 保留的TCP地址:

  • Region: Select China VIP here, you can also choose other regions
  • Description: Customizable remarks

Click on the right保留

image-20230511153139329

After filling in this information, click 保留the button on the right to fix the tunnel in the backend of the cpolar official website. At this time cpolar will generate a tunnel tcp port

image-20230511153205122

Then we return to the browser cpolar web ui management interface, open it 隧道列表, find the random temporary TCP tunnel created before, and enter 编辑the page:

image-20230511153321327

Select the port type 固定TCP端口, then paste the tunnel port we obtained from the cpolar official website into the column, and then click the button 预留的TCP地址below更新

image-20230511153415936

Then check the online tunnel list again, and you can find that the public address corresponding to the mysql tunnel has become the fixed address reserved by our official website.

image-20230511153512015

After configuring the public network address of remote MySQL to be fixed, let's test the connection using the fixed public network address. It can also be connected to termux MySQL remotely.

Now as long as this tunnel is kept online, we can remotely connect to Termux MySQL through this public network address.

image-20230511153921009

Reprinted from cpolar pole cloud article: Android Termux installs MySQL, and intranet penetration enables remote access to the public network

Guess you like

Origin blog.csdn.net/xz2935117143/article/details/133701606