Termux安装MySQL(mariadb)
安装命令
pkg install mariadb
Installing MariaDB/MySQL system tables in '/data/data/com.termux/files/usr/var/lib/mysql' ...
OK
To start mariadbd at boot time you have to copy
support-files/mariadb.service to the right place for your system
PLEASE REMEMBER TO SET A PASSWORD FOR THE MariaDB root USER !
To do so, start the server, then issue the following command:
'/data/data/com.termux/files/usr/bin/mariadb-secure-installation'
which will also give you the option of removing the test
databases and anonymous user created by default. This is
strongly recommended for production servers.
See the MariaDB Knowledgebase at https://mariadb.com/kb
You can start the MariaDB daemon with:
cd '/data/data/com.termux/files/usr' ; /data/data/com.termux/files/usr/bin/mariadbd-safe --datadir='/data/data/com.termux/files/usr/var/lib/mysql'
You can test the MariaDB daemon with mariadb-test-run.pl
cd '/data/data/com.termux/files/usr/share/mariadb/mariadb-test' ; perl mariadb-test-run.pl
Please report any problems at https://mariadb.org/jira
The latest information about MariaDB is available at https://mariadb.org/.
Consider joining MariaDB's strong and vibrant community:
https://mariadb.org/get-involved/
运行Termux访问存储文件
termux-setup-storage
然后在手机上确定
运行mariadb
mysqld_safe &
登录数据库
/data/data/com.termux/files/usr/bin/mariadb -u root -p
默认没有密码,如果没有报错,则无问题,如果报以下错误,则需要修改mariadb密码
ERROR 1698 (28000): Access denied for user 'root'@'localhost'
修改配置文件:/data/data/com.termux/files/usr/etc/my.cnf
增加以下配置
[mysqld]
skip_grant_tables
重启MySQL
使用top命令,找到进程id,然后使用kill命令关掉进程
Mem: 4034844K total, 1112636K used, 2922208K free, 11968K buffers
Swap: 8388604K total, 0K used, 8388604K free, 297248K cached
400%cpu 0%user 0%nice 0%sys 400%idle 0%iow 0%irq 0%sirq 0%host
PID USER PR NI VIRT RES SHR S[%CPU] %MEM TIME+ ARGS
4182 u0_a34 10 -10 10G 4.0M 2.8M R 0.0 0.1 0:00.02 top
4160 u0_a34 10 -10 10G 5.5M 3.1M S 0.0 0.1 0:00.00 sshd-session -R
4158 u0_a34 10 -10 10G 8.3M 6.3M S 0.0 0.2 0:00.06 sshd-session -R
4130 u0_a34 10 -10 11G 112M 22M S 0.0 2.8 0:01.36 mariadbd --basedir=/data/data/com.termux/files/usr --datadir=/da+
4062 u0_a34 10 -10 10G 3.6M 2.4M S 0.0 0.0 0:00.01 sh /data/data/com.termux/files/usr/bin/mysqld_safe
3445 u0_a34 10 -10 10G 3.1M 672K S 0.0 0.0 0:00.00 nginx: worker process
3410 u0_a34 10 -10 11G 8.1M 1.2M S 0.0 0.2 0:00.00 php-fpm: pool www
3409 u0_a34 10 -10 11G 14M 6.6M S 0.0 0.3 0:00.00 php-fpm: pool www
3408 u0_a34 10 -10 11G 8.6M 1.8M S 0.0 0.2 0:00.08 php-fpm.conf)
3388 u0_a34 10 -10 10G 5.1M 2.7M S 0.0 0.1 0:00.00 sshd-session -R
3386 u0_a34 10 -10 10G 6.7M 4.6M S 0.0 0.1 0:00.06 sshd-session -R
3381 u0_a34 10 -10 10G 11M 4.8M T 0.0 0.2 0:00.44 vim /data/data/com.termux/files/usr/etc/nginx/nginx.conf
2843 u0_a34 10 -10 10G 3.6M 1.4M S 0.0 0.0 0:00.00 nginx: master process nginx
2657 u0_a34 10 -10 10G 5.2M 3.3M S 0.0 0.1 0:00.20 bash -l
2656 u0_a34 10 -10 10G 5.0M 2.6M S 0.0 0.1 0:00.74 sshd-session -R
2640 u0_a34 10 -10 10G 6.6M 4.5M S 0.0 0.1 0:00.07 sshd-session -R
2517 u0_a34 10 -10 10G 4.6M 2.6M S 0.0 0.1 0:00.01 sshd
2449 u0_a34 10 -10 10G 4.8M 3.1M S 0.0 0.1 0:00.03 bash -l
2271 u0_a34 10 -10 12G 124M 68M S 0.0 3.1 0:03.53 com.termux
.../usr/etc $ kill 4130
运行mariadb
mysqld_safe &
登录mariadb
/data/data/com.termux/files/usr/bin/mariadb -u root -p
不需要输入密码,即可以登录成功。
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
| test |
+--------------------+
5 rows in set (0.002 sec)
修改密码
use mysql;
刷新权限
FLUSH PRIVILEGES;
更新密码
alter user 'root'@'localhost' identified by '123456';
开启远程访问
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%'IDENTIFIED BY '123456' WITH GRANT OPTION;
在执行一次刷新权限命令
FLUSH PRIVILEGES;
测试远程连接
此时会报错
/* SQL错误(1577):Cannot proceed, because event scheduler is disabled */
这时候需要将之前添加的mariadb配置删除,然后重启mariadb即可。
至此,手机上安装MySQL(mariadb)成功。