Linux deploy 安装 Ubuntu 及 MySQL

设备支持:已 root 的 mi-4(架构:armv71)

软件支持:Linux Deplay

Linux deploy 上 安装好 你希望安装的 Linux 版本,我这里安装的是 Ubuntu 18.04(bionic),注意要根据手机的处理器型号选择适配的处理器版本,由于 mi-4 的 处理器是 armv71,发行版本选择 armhf

ARM Cortex-A系列(A53、A57、A73等)处理器性能分类与对比:
原文链接:https://blog.csdn.net/qq_39537898/article/details/112273181

11606bebd6a97b75900b6b66a50df53c_watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzM5NTM3ODk4,size_16,color_FFFFFF,t_70.png
linux deplay 的 配置文件-属性中,设置如下:

  • 发行版 GNU/Linux:Ubuntu-bionic
  • 架构:armhf
  • 源地址(即镜像地址):**http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/**

经过测试,这个源站是最好用的,建议换成这个源站

  • 安装类型:镜像
  • 安装路径:修改${EXTERNAL_STORAGE}$后面的路径即可
  • 镜像大小:自己设定,不要设置太小
  • 文件系统:ext4
  • 用户名、密码:自己设置
  • 本地化:zh_CN.UTF-8
  • SSH:勾选
  • 图形界面、音频输出:自选

点击安装即可完成 Ubuntu 安装

SSH 登录:

使用 **Windterm**新建一个 SSH 会话,登录 Ubuntu

安装 MySQL:

😃 首先更新 apt:sudo apt-get update

root@localhost:~# sudo apt-get update
获取:1 http://mirror.tuna.tsinghua.edu.cn/ubuntu-ports bionic InRelease [242 kB]
已下载 242 kB,耗时 2 (136 kB/s)
正在读取软件包列表... 完成

😃 然后下载 MySQL:sudo apt-get install mysql-server

注意:使用 apt 安装 的版本可能比较旧,但是 支持 armhf 架构的版本确实不好找(应该只有 5.7 支持),所以这里直接 用 apt 安装,它会保证安装的版本是适配你的物理机的;
如果你的设备架构是 arm64,amd64 或其他,建议 使用 wget 直接把 deb 包下好安装

root@localhost:~# sudo apt-get install mysql-server
正在读取软件包列表... 完成
正在分析软件包的依赖关系树       
正在读取状态信息... 完成       
将会同时安装下列软件:
  libaio1 libcgi-fast-perl libcgi-pm-perl libencode-locale-perl libevent-core-2.1-6 libfcgi-perl libhtml-parser-perl
  libhtml-tagset-perl libhtml-template-perl libhttp-date-perl libhttp-message-perl libio-html-perl liblwp-mediatypes-perl
  libtimedate-perl liburi-perl mysql-client-5.7 mysql-client-core-5.7 mysql-common mysql-server-5.7 mysql-server-core-5.7
建议安装:
  libdata-dump-perl libipc-sharedcache-perl libwww-perl mailx tinyca
下列【新】软件包将被安装:
  libaio1 libcgi-fast-perl libcgi-pm-perl libencode-locale-perl libevent-core-2.1-6 libfcgi-perl libhtml-parser-perl
  libhtml-tagset-perl libhtml-template-perl libhttp-date-perl libhttp-message-perl libio-html-perl liblwp-mediatypes-perl
  libtimedate-perl liburi-perl mysql-client-5.7 mysql-client-core-5.7 mysql-common mysql-server mysql-server-5.7 mysql-server-core-5.7
升级了 0 个软件包,新安装了 21 个软件包,要卸载 0 个软件包,有 0 个软件包未被升级。
需要下载 18.5 MB/19.1 MB 的归档。
解压缩后会消耗 140 MB 的额外空间。
您希望继续执行吗? [Y/n] y
获取:1 http://mirror.tuna.tsinghua.edu.cn/ubuntu-ports bionic/main armhf mysql-common all 5.8+1.0.4 [7,308 B]
获取:2 http://mirror.tuna.tsinghua.edu.cn/ubuntu-ports bionic/main armhf libaio1 armhf 0.3.110-5 [6,328 B]
获取:3 http://mirror.tuna.tsinghua.edu.cn/ubuntu-ports bionic/main armhf mysql-client-core-5.7 armhf 5.7.21-1ubuntu1 [6,122 kB]
获取:4 http://mirror.tuna.tsinghua.edu.cn/ubuntu-ports bionic/main armhf mysql-client-5.7 armhf 5.7.21-1ubuntu1 [2,083 kB]
获取:5 http://mirror.tuna.tsinghua.edu.cn/ubuntu-ports bionic/main armhf mysql-server-core-5.7 armhf 5.7.21-1ubuntu1 [7,211 kB]
获取:6 http://mirror.tuna.tsinghua.edu.cn/ubuntu-ports bionic/main armhf libevent-core-2.1-6 armhf 2.1.8-stable-4build1 [75.0 kB]
获取:7 http://mirror.tuna.tsinghua.edu.cn/ubuntu-ports bionic/main armhf mysql-server-5.7 armhf 5.7.21-1ubuntu1 [2,986 kB]
获取:8 http://mirror.tuna.tsinghua.edu.cn/ubuntu-ports bionic/main armhf mysql-server all 5.7.21-1ubuntu1 [9,940 B]
已下载 18.5 MB,耗时 2 (7,962 kB/s)       
正在预设定软件包 ...
正在选中未选择的软件包 mysql-common
(正在读取数据库 ... 系统当前共安装有 17077 个文件和目录。)
正准备解包 .../0-mysql-common_5.8+1.0.4_all.deb  ...
正在解包 mysql-common (5.8+1.0.4) ...
正在选中未选择的软件包 libaio1:armhf
正准备解包 .../1-libaio1_0.3.110-5_armhf.deb  ...
正在解包 libaio1:armhf (0.3.110-5) ...
正在选中未选择的软件包 mysql-client-core-5.7
正准备解包 .../2-mysql-client-core-5.7_5.7.21-1ubuntu1_armhf.deb  ...
正在解包 mysql-client-core-5.7 (5.7.21-1ubuntu1) ...
正在选中未选择的软件包 mysql-client-5.7
正准备解包 .../3-mysql-client-5.7_5.7.21-1ubuntu1_armhf.deb  ...
正在解包 mysql-client-5.7 (5.7.21-1ubuntu1) ...
正在选中未选择的软件包 mysql-server-core-5.7
正准备解包 .../4-mysql-server-core-5.7_5.7.21-1ubuntu1_armhf.deb  ...
正在解包 mysql-server-core-5.7 (5.7.21-1ubuntu1) ...
正在选中未选择的软件包 libevent-core-2.1-6:armhf
正准备解包 .../5-libevent-core-2.1-6_2.1.8-stable-4build1_armhf.deb  ...
正在解包 libevent-core-2.1-6:armhf (2.1.8-stable-4build1) ...
正在设置 mysql-common (5.8+1.0.4) ...
正在选中未选择的软件包 mysql-server-5.7
(正在读取数据库 ... 系统当前共安装有 17240 个文件和目录。)
正准备解包 .../00-mysql-server-5.7_5.7.21-1ubuntu1_armhf.deb  ...
Running in chroot, ignoring request.
 * Stopping MariaDB database server mysqld                                                                                        [ OK ] 
正在解包 mysql-server-5.7 (5.7.21-1ubuntu1) ...
正在选中未选择的软件包 libhtml-tagset-perl
正准备解包 .../01-libhtml-tagset-perl_3.20-3_all.deb  ...
正在解包 libhtml-tagset-perl (3.20-3) ...
正在选中未选择的软件包 liburi-perl
正准备解包 .../02-liburi-perl_1.73-1_all.deb  ...
正在解包 liburi-perl (1.73-1) ...
正在选中未选择的软件包 libhtml-parser-perl
正准备解包 .../03-libhtml-parser-perl_3.72-3build1_armhf.deb  ...
正在解包 libhtml-parser-perl (3.72-3build1) ...
正在选中未选择的软件包 libcgi-pm-perl
正准备解包 .../04-libcgi-pm-perl_4.38-1_all.deb  ...
正在解包 libcgi-pm-perl (4.38-1) ...
正在选中未选择的软件包 libfcgi-perl
正准备解包 .../05-libfcgi-perl_0.78-2build1_armhf.deb  ...
正在解包 libfcgi-perl (0.78-2build1) ...
正在选中未选择的软件包 libcgi-fast-perl
正准备解包 .../06-libcgi-fast-perl_1%3a2.13-1_all.deb  ...
正在解包 libcgi-fast-perl (1:2.13-1) ...
正在选中未选择的软件包 libencode-locale-perl
正准备解包 .../07-libencode-locale-perl_1.05-1_all.deb  ...
正在解包 libencode-locale-perl (1.05-1) ...
正在选中未选择的软件包 libhtml-template-perl
正准备解包 .../08-libhtml-template-perl_2.97-1_all.deb  ...
正在解包 libhtml-template-perl (2.97-1) ...
正在选中未选择的软件包 libtimedate-perl
正准备解包 .../09-libtimedate-perl_2.3000-2_all.deb  ...
正在解包 libtimedate-perl (2.3000-2) ...
正在选中未选择的软件包 libhttp-date-perl
正准备解包 .../10-libhttp-date-perl_6.02-1_all.deb  ...
正在解包 libhttp-date-perl (6.02-1) ...
正在选中未选择的软件包 libio-html-perl
正准备解包 .../11-libio-html-perl_1.001-1_all.deb  ...
正在解包 libio-html-perl (1.001-1) ...
正在选中未选择的软件包 liblwp-mediatypes-perl
正准备解包 .../12-liblwp-mediatypes-perl_6.02-1_all.deb  ...
正在解包 liblwp-mediatypes-perl (6.02-1) ...
正在选中未选择的软件包 libhttp-message-perl
正准备解包 .../13-libhttp-message-perl_6.14-1_all.deb  ...
正在解包 libhttp-message-perl (6.14-1) ...
正在选中未选择的软件包 mysql-server
正准备解包 .../14-mysql-server_5.7.21-1ubuntu1_all.deb  ...
正在解包 mysql-server (5.7.21-1ubuntu1) ...
正在设置 libhtml-tagset-perl (3.20-3) ...
正在设置 libevent-core-2.1-6:armhf (2.1.8-stable-4build1) ...
正在设置 libencode-locale-perl (1.05-1) ...
正在设置 libtimedate-perl (2.3000-2) ...
正在设置 libio-html-perl (1.001-1) ...
正在设置 liblwp-mediatypes-perl (6.02-1) ...
正在处理用于 libc-bin (2.27-3ubuntu1) 的触发器 ...
正在设置 libaio1:armhf (0.3.110-5) ...
正在设置 liburi-perl (1.73-1) ...
正在处理用于 systemd (237-3ubuntu10) 的触发器 ...
正在设置 libhtml-parser-perl (3.72-3build1) ...
正在设置 libcgi-pm-perl (4.38-1) ...
正在处理用于 man-db (2.8.3-2) 的触发器 ...
正在设置 mysql-client-core-5.7 (5.7.21-1ubuntu1) ...
正在设置 libfcgi-perl (0.78-2build1) ...
正在设置 libhttp-date-perl (6.02-1) ...
正在设置 libhtml-template-perl (2.97-1) ...
正在设置 mysql-server-core-5.7 (5.7.21-1ubuntu1) ...
正在设置 libcgi-fast-perl (1:2.13-1) ...
正在设置 libhttp-message-perl (6.14-1) ...
正在设置 mysql-client-5.7 (5.7.21-1ubuntu1) ...
正在设置 mysql-server-5.7 (5.7.21-1ubuntu1) ...
正在安装新版本配置文件 /etc/apparmor.d/usr.sbin.mysqld ...
正在安装新版本配置文件 /etc/init.d/mysql ...
正在安装新版本配置文件 /etc/logrotate.d/mysql-server ...

配置文件 '/etc/mysql/debian-start'
 ==> 在安装后曾被删除(您或者某个脚本删除了它)。
 ==> 软件包的提交者同时提供了一个更新了的版本。
   您现在希望如何处理呢? 您有以下几个选择:
    Y  I  :安装软件包维护者所提供的版本
    N  O  :保留您原来安装的版本
      D     :显示两者的区别
      Z     :把当前进程切换到后台,然后查看现在的具体情况
 默认的处理方法是保留您当前使用的版本。
*** debian-start (Y/I/N/O/D/Z) [默认选项=N] ? y
正在安装新版本配置文件 /etc/mysql/debian-start ...
Running in chroot, ignoring request.
 * Stopping MySQL database server mysqld                                                                                          [ OK ] 
update-alternatives: 使用 /etc/mysql/mysql.cnf 来在自动模式中提供 /etc/mysql/my.cnf (my.cnf)
Renaming removed key_buffer and myisam-recover options (if present)
dpkg: 处理软件包 mysql-server-5.7 (--configure)时出错:
 installed mysql-server-5.7 package post-installation script subprocess returned error exit status 1
dpkg: 依赖关系问题使得 mysql-server 的配置工作不能继续:
 mysql-server 依赖于 mysql-server-5.7;然而:
  软件包 mysql-server-5.7 尚未配置。

dpkg: 处理软件包 mysql-server (--configure)时出错:
 依赖关系问题 - 仍未被配置
正在处理用于 libc-bin (2.27-3ubuntu1) 的触发器 ...
正在处理用于 systemd (237-3ubuntu10) 的触发器 ...
在处理时有错误发生:
 mysql-server-5.7
 mysql-server
E: Sub-process /usr/bin/dpkg returned an error code (1)

我们注意到在解包中发现这样的问题:
image.png
这是由于在 **chroot**** **环境下,不能涉及系统配置的某些部分,从而导致 配置失败,该处错误是 配置 mysql-server-5.7``mysql-server出错的。
可以先卸载 mysql-server-5.7``mysql-server

  • command:**sudo apt-get remove mysql-server mysql-server-5.7**
  • output:发现 自动更新update部分出错了,这个先不用考虑
root@localhost:~# sudo apt-get remove mysql-server mysql-server-5.7
正在读取软件包列表... 完成
正在分析软件包的依赖关系树       
正在读取状态信息... 完成       
下列软件包是自动安装的并且现在不需要了:
  libaio1 libcgi-fast-perl libcgi-pm-perl libencode-locale-perl libevent-core-2.1-6 libfcgi-perl libhtml-parser-perl
  libhtml-tagset-perl libhtml-template-perl libhttp-date-perl libhttp-message-perl libio-html-perl liblwp-mediatypes-perl
  libtimedate-perl liburi-perl mysql-client-5.7 mysql-client-core-5.7 mysql-common mysql-server-core-5.7
使用'sudo apt autoremove'来卸载它(它们)。
下列软件包将被【卸载】:
  mysql-server mysql-server-5.7
升级了 0 个软件包,新安装了 0 个软件包,要卸载 2 个软件包,有 0 个软件包未被升级。
 2 个软件包没有被完全安装或卸载。
解压缩后将会空出 44.9 MB 的空间。
您希望继续执行吗? [Y/n] y
(正在读取数据库 ... 系统当前共安装有 17594 个文件和目录。)
正在卸载 mysql-server (5.7.21-1ubuntu1) ...
正在卸载 mysql-server-5.7 (5.7.21-1ubuntu1) ...
Running in chroot, ignoring request.
 * Stopping MySQL database server mysqld                                                                                          [ OK ] 
正在处理用于 man-db (2.8.3-2) 的触发器 ...
root@localhost:~# sudo apt-get install mysql-server-5.7
正在读取软件包列表... 完成
正在分析软件包的依赖关系树       
正在读取状态信息... 完成       
建议安装:
  mailx tinyca
下列【新】软件包将被安装:
  mysql-server-5.7
升级了 0 个软件包,新安装了 1 个软件包,要卸载 0 个软件包,有 0 个软件包未被升级。
需要下载 0 B/2,986 kB 的归档。
解压缩后会消耗 44.7 MB 的额外空间。
正在预设定软件包 ...
正在选中未选择的软件包 mysql-server-5.7
(正在读取数据库 ... 系统当前共安装有 17517 个文件和目录。)
正准备解包 .../mysql-server-5.7_5.7.21-1ubuntu1_armhf.deb  ...
Running in chroot, ignoring request.
正在解包 mysql-server-5.7 (5.7.21-1ubuntu1) ...
正在处理用于 systemd (237-3ubuntu10) 的触发器 ...
正在处理用于 man-db (2.8.3-2) 的触发器 ...
正在设置 mysql-server-5.7 (5.7.21-1ubuntu1) ...
Running in chroot, ignoring request.
 * Stopping MySQL database server mysqld                                                                                          [ OK ] 
update-alternatives: 使用 /etc/mysql/mysql.cnf 来在自动模式中提供 /etc/mysql/my.cnf (my.cnf)
Renaming removed key_buffer and myisam-recover options (if present)
Checking if update is needed.
Checking server version.
Running queries to upgrade MySQL server.
Checking system database.
mysql.columns_priv                                 OK
mysql.db                                           OK
mysql.engine_cost                                  OK
mysql.event                                        OK
mysql.func                                         OK
mysql.general_log                                  OK
mysql.gtid_executed                                OK
mysql.help_category                                OK
mysql.help_keyword                                 OK
mysql.help_relation                                OK
mysql.help_topic                                   OK
mysql.innodb_index_stats                           OK
mysql.innodb_table_stats                           OK
mysql.ndb_binlog_index                             OK
mysql.plugin                                       OK
mysql.proc                                         OK
mysql.procs_priv                                   OK
mysql.proxies_priv                                 OK
mysql.server_cost                                  OK
mysql.servers                                      OK
mysql.slave_master_info                            OK
mysql.slave_relay_log_info                         OK
mysql.slave_worker_info                            OK
mysql.slow_log                                     OK
mysql.tables_priv                                  OK
mysql.time_zone                                    OK
mysql.time_zone_leap_second                        OK
mysql.time_zone_name                               OK
mysql.time_zone_transition                         OK
mysql.time_zone_transition_type                    OK
mysql.user                                         OK
The sys schema is already up to date (version 1.5.1).
Checking databases.
sys.sys_config                                     OK
Upgrade process completed successfully.
Checking if update is needed.
dpkg: 处理软件包 mysql-server-5.7 (--configure)时出错:
 installed mysql-server-5.7 package post-installation script subprocess returned error exit status 1
在处理时有错误发生:
 mysql-server-5.7
E: Sub-process /usr/bin/dpkg returned an error code (1)

😁 尝试手动配置 MySQL:sudo mysql_secure_installation

**ERROR 2002: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)**
解决该问题的措施如下:**usermod -a -G aid_inet,aid_net_raw mysql**

参考:https://www.jianshu.com/p/52d7dd47b9dc
具体原因:Android使用了一个激活的特殊内核补丁CONFIG_ANDROID_PARANOID_NETWORK。此修补程序允许网络访问属于具有硬编码ID的特定特殊组的系统用户。
这是因为Android通常仅在特定应用具有网络权限时才将用户(即应用)添加到这些组
说是Android内核已使用CONFIG_ANDROID_PARANOID_NETWORK进行编译。可以通过将mysql用户添加到aid_inet和aid_net_raw组来修复它

按上述操作,mysql 可以正常启动了:如图
image.png
检查一下 mysql 的状态:**service mysql status**
image.png
接下来手动配置 MySQL:**sudo mysql_secure_installation**

root@localhost:~# sudo mysql_secure_installation
############################设置 root 密码#############################
Securing the MySQL server deployment.

Connecting to MySQL using a blank password.

VALIDATE PASSWORD PLUGIN can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD plugin?

Press y|Y for Yes, any other key for No: 
Please set the password for root here.

New password: 

Re-enter new password: 
############################取消 匿名用户 #############################
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.

Remove anonymous users? (Press y|Y for Yes, any other key for No) : y
Success.

############################禁用 root 登录#############################

Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.

Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y
Success.

############################删除测试数据库#############################
By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.


Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y
- Dropping test database...
Success.

- Removing privileges on test database...
Success.

############################重新 加载 权限表 ?#############################
Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.

Reload privilege tables now? (Press y|Y for Yes, any other key for No) : n

... skipping.
All done! 

😁 设置 MySQL 的基本配置:

  1. 启用开机自启动:**sudo systemctl enable mysql**

image.png

  1. 登录MySQL:**sudo mysql -u root -p**

此处以 root 登录,完成一些 root 才能完成的操作

  1. 创建MySQL 用户:
CREATE USER 'username'@'%' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON *.* TO 'username'@'%';
FLUSH PRIVILEGES;

usernamepassword 替换为希望使用的实际用户名和密码。'%' 表示该用户可以从任何IP地址连接到MySQL服务器。只想允许特定IP地址的连接,将 '%' 替换为该IP地址

  1. **修改MySQL配置文件 ****my.cnf**:将 bind-address 的值改为 0.0.0.0

然后重启 mysql 服务:**service mysql restart**
image.png

😃 测试 MySQL 是否可连接:

image.png

posted @   nixwl  阅读(1299)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
点击右上角即可分享
微信分享提示