termux怎么安装mysql
时间 : 2023-08-08 08:09:02声明: : 文章内容来自网络,不保证准确性,请自行甄别信息有效性

要在Termux上安装MySQL,你需要按照以下步骤操作:

1. 首先,打开Termux并确保你的Termux环境是最新的。你可以通过运行以下命令来更新Termux:

pkg update

2. 接下来,安装必需的依赖软件包。在Termux中,运行以下命令安装必需的软件包:

pkg install wget openssl-tool proot -y

3. 下载和安装MariaDB的二进制文件。在Termux中,运行以下命令:

mkdir $HOME/mariadb

cd $HOME/mariadb

wget https://github.com/termux/proot-distro/releases/download/v3.5.2/ubuntu-16.04.tar.gz

proot --link2symlink tar -xf ubuntu-16.04.tar.gz

4. 设置root密码和MySQL用户。在Termux中,运行以下命令:

proot -0 -r /data/data/com.termux/files/home/mariadb/ubuntu-16.04 -b /dev -b /sys -b /proc -b /storage -w /root apt update

proot -0 -r /data/data/com.termux/files/home/mariadb/ubuntu-16.04 -b /dev -b /sys -b /proc -b /storage -w /root apt install -y mysql-server

proot -0 -r /data/data/com.termux/files/home/mariadb/ubuntu-16.04 -b /dev -b /sys -b /proc -b /storage -w /root apt clean

proot -0 -r /data/data/com.termux/files/home/mariadb/ubuntu-16.04 -b /dev -b /sys -b /proc -b /storage -w /root apt autoremove

proot -0 -r /data/data/com.termux/files/home/mariadb/ubuntu-16.04 -b /dev -b /sys -b /proc -b /storage -w /root apt update

proot -0 -r /data/data/com.termux/files/home/mariadb/ubuntu-16.04 -b /dev -b /sys -b /proc -b /storage -w /root apt install -y pwgen

root_password=$(pwgen -1s 32)

mysql -u root -e "ALTER USER 'root'@'localhost' IDENTIFIED BY '$root_password';"

mysql -u root -p -e "CREATE USER 'termux'@'localhost' IDENTIFIED BY '$root_password';"

mysql -u root -p -e "GRANT ALL PRIVILEGES ON *.* TO 'termux'@'localhost' WITH GRANT OPTION;"

mysql -u termux -p -e "CREATE DATABASE termux;"

在运行这些命令时,注意替换`ubuntu-16.04`为你在第3步中下载的文件的名称。

5. 最后,启动MySQL服务器。在Termux中,运行以下命令:

proot -0 -r /data/data/com.termux/files/home/mariadb/ubuntu-16.04 -b /dev -b /sys -b /proc -b /storage -w /root service mysql start

现在,你已经成功在Termux上安装了MySQL。你可以使用以下命令连接到MySQL:

mysql -u termux -p

输入密码后,你就可以开始使用MySQL了。