安卓termux下centos7编译安装mysql5.7教程

termux-centos-mysql5.7编译安装

介绍

安卓termux下centos7编译安装mysql5.7
由于手机架构是aarch64的和服务器的架构不同,所以常用的mysql安装包用不了,只能自己编译安装
有需要其他服务安装教程的可以在评论区留言哦!!!
本人用的手机是华为手机,安卓10,鸿蒙系统都是可以的
之前写过一篇解压安装教程,有朋友说能出一个编译安装的帖嘛
今天福利来了
喜欢的点个赞~~~~~~

下载地址

mysql-5.7.16.tar.gz
此文件也可以在mysql官网下载,请下载源码,在进行编译

安装教程

  1. 安装编译软件和依赖

首先更新系统软件
yum update
yum install -y cmake make gcc gcc-c++ wget ncurses-devel cmake make perl ncurses-devel openssl-devel bison-devel libaio libaio-devel

  1. 创建MySQL安装目录

# 如MySQL安装目录为:/usr/local/mysql
mkdir -p /usr/local/mysql
#创建数据目录为:
mkdir -p /usr/local/mysql/data

  1. 创建mysql用户和用户组

# 创建用户组
groupadd mysql
# 创建mysql用户,所属组为mysql
useradd -s /bin/bash -m -g mysql mysql

  1. 创建MySQL相关目录

mkdir -p  /usr/local/mysql/data/bin_log
mkdir -p  /usr/local/mysql/data/db_file
mkdir -p  /usr/local/mysql/data/innodb_log
mkdir -p  /usr/local/mysql/data/innodb_ts
mkdir -p  /usr/local/mysql/data/log
mkdir -p  /usr/local/mysql/data/relay_log
mkdir -p  /usr/local/mysql/data/tmpdir
mkdir -p  /usr/local/mysql/data/undo_log

  1. 创建的目录的所属用户与所属组为mysql:mysql

chown -R mysql:mysql /usr/local/mysql/data
chown -R mysql:mysql /usr/local/mysql

  1. 解压MySQL源码包 和gcc版本更新和切换
tar -zxvf mysql-5.7.16.tar.gz
  • gcc版本更新 安装scl源
yum install centos-release-scl scl-utils-build -y
  • 查看scl有哪些源可以用
[root@localhost ~]# yum list all --enablerepo='centos-sclo-rh'|grep gcc
Failed to set locale, defaulting to C
gcc.aarch64                                4.8.5-44.el7           @base         
gcc-c++.aarch64                            4.8.5-44.el7           @base         
libgcc.aarch64                             4.8.5-44.el7           @base         
devtoolset-10-gcc.aarch64                  10.2.1-11.2.el7        centos-sclo-rh
devtoolset-10-gcc-c++.aarch64              10.2.1-11.2.el7        centos-sclo-rh
devtoolset-10-gcc-gdb-plugin.aarch64       10.2.1-11.2.el7        centos-sclo-rh
devtoolset-10-gcc-gfortran.aarch64         10.2.1-11.2.el7        centos-sclo-rh
devtoolset-10-gcc-plugin-devel.aarch64     10.2.1-11.2.el7        centos-sclo-rh
devtoolset-10-libgccjit.aarch64            10.2.1-11.2.el7        centos-sclo-rh
devtoolset-10-libgccjit-devel.aarch64      10.2.1-11.2.el7        centos-sclo-rh
devtoolset-10-libgccjit-docs.aarch64       10.2.1-11.2.el7        centos-sclo-rh
devtoolset-7-gcc.aarch64                   7.3.1-5.16.el7         centos-sclo-rh
devtoolset-7-gcc-c++.aarch64               7.3.1-5.16.el7         centos-sclo-rh
devtoolset-7-gcc-gdb-plugin.aarch64        7.3.1-5.16.el7         centos-sclo-rh
devtoolset-7-gcc-gfortran.aarch64          7.3.1-5.16.el7         centos-sclo-rh
devtoolset-7-gcc-plugin-devel.aarch64      7.3.1-5.16.el7         centos-sclo-rh
devtoolset-7-libgccjit.aarch64             7.3.1-5.16.el7         centos-sclo-rh
devtoolset-7-libgccjit-devel.aarch64       7.3.1-5.16.el7         centos-sclo-rh
devtoolset-7-libgccjit-docs.aarch64        7.3.1-5.16.el7         centos-sclo-rh
devtoolset-8-gcc.aarch64                   8.3.1-3.2.el7          centos-sclo-rh
devtoolset-8-gcc-c++.aarch64               8.3.1-3.2.el7          centos-sclo-rh
devtoolset-8-gcc-gdb-plugin.aarch64        8.3.1-3.2.el7          centos-sclo-rh
devtoolset-8-gcc-gfortran.aarch64          8.3.1-3.2.el7          centos-sclo-rh
devtoolset-8-gcc-plugin-devel.aarch64      8.3.1-3.2.el7          centos-sclo-rh
devtoolset-8-libgccjit.aarch64             8.3.1-3.2.el7          centos-sclo-rh
devtoolset-8-libgccjit-devel.aarch64       8.3.1-3.2.el7          centos-sclo-rh
devtoolset-8-libgccjit-docs.aarch64        8.3.1-3.2.el7          centos-sclo-rh
devtoolset-9-gcc.aarch64                   9.3.1-2.2.el7          centos-sclo-rh
devtoolset-9-gcc-c++.aarch64               9.3.1-2.2.el7          centos-sclo-rh
devtoolset-9-gcc-gdb-plugin.aarch64        9.3.1-2.2.el7          centos-sclo-rh
devtoolset-9-gcc-gfortran.aarch64          9.3.1-2.2.el7          centos-sclo-rh
devtoolset-9-gcc-plugin-devel.aarch64      9.3.1-2.2.el7          centos-sclo-rh
devtoolset-9-libgccjit.aarch64             9.3.1-2.2.el7          centos-sclo-rh
devtoolset-9-libgccjit-devel.aarch64       9.3.1-2.2.el7          centos-sclo-rh
devtoolset-9-libgccjit-docs.aarch64        9.3.1-2.2.el7          centos-sclo-rh
gcc-gfortran.aarch64                       4.8.5-44.el7           base          
gcc-gnat.aarch64                           4.8.5-44.el7           base          
gcc-objc.aarch64                           4.8.5-44.el7           base          
gcc-objc++.aarch64                         4.8.5-44.el7           base          
gcc-plugin-devel.aarch64                   4.8.5-44.el7           base          
relaxngcc.noarch                           1.12-6.el7             base          
relaxngcc-javadoc.noarch                   1.12-6.el7             base          
[root@localhost ~]# 
复制代码
  • 安装7.3版本的gcc、gcc-c++、gdb
 yum install devtoolset-7-gcc.aarch64  devtoolset-7-gcc-c++.aarch64 devtoolset-7-gcc-gdb-plugin.aarch64 -y
  • 查看当前gcc版本
[root~]# gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/4.8.5/lto-wrapper
Target: x86_64-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-linker-hash-style=gnu --enable-languages=c,c++,objc,obj-c++,java,fortran,ada,go,lto --enable-plugin --enable-initfini-array --disable-libgcj --with-isl=/builddir/build/BUILD/gcc-4.8.5-20150702/obj-x86_64-redhat-linux/isl-install --with-cloog=/builddir/build/BUILD/gcc-4.8.5-20150702/obj-x86_64-redhat-linux/cloog-install --enable-gnu-indirect-function --with-tune=generic --with-arch_32=x86-64 --build=x86_64-redhat-linux
Thread model: posix
gcc version 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC) 
[root@localhost Bringing-Old-Photos-Back-to-Life]#
  • 切换版本
[root@localhost Bringing-Old-Photos-Back-to-Life]# scl enable devtoolset-7 bash
[root@localhost Bringing-Old-Photos-Back-to-Life]# 
  • 查看切换后的 gcc版本
[root@localhost Bringing-Old-Photos-Back-to-Life]# gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/opt/rh/devtoolset-7/root/usr/libexec/gcc/x86_64-redhat-linux/7/lto-wrapper
Target: x86_64-redhat-linux
Configured with: ../configure --enable-bootstrap --enable-languages=c,c++,fortran,lto --prefix=/opt/rh/devtoolset-7/root/usr --mandir=/opt/rh/devtoolset-7/root/usr/share/man --infodir=/opt/rh/devtoolset-7/root/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-shared --enable-threads=posix --enable-checking=release --enable-multilib --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-gcc-major-version-only --enable-plugin --with-linker-hash-style=gnu --enable-initfini-array --with-default-libstdcxx-abi=gcc4-compatible --with-isl=/builddir/build/BUILD/gcc-7.3.1-20180303/obj-x86_64-redhat-linux/isl-install --enable-libmpx --enable-gnu-indirect-function --with-tune=generic --with-arch_32=i686 --build=x86_64-redhat-linux
Thread model: posix
gcc version 7.3.1 20180303 (Red Hat 7.3.1-5) (GCC) 
[root@localhost Bringing-Old-Photos-Back-to-Life]#
使用exit命令退出scl环境

[root@localhost Bringing-Old-Photos-Back-to-Life]# exit
exit
再次查看版本

复制代码
[root@localhost Bringing-Old-Photos-Back-to-Life]# exit
exit
[root@localhost Bringing-Old-Photos-Back-to-Life]# gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/4.8.5/lto-wrapper
Target: x86_64-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-linker-hash-style=gnu --enable-languages=c,c++,objc,obj-c++,java,fortran,ada,go,lto --enable-plugin --enable-initfini-array --disable-libgcj --with-isl=/builddir/build/BUILD/gcc-4.8.5-20150702/obj-x86_64-redhat-linux/isl-install --with-cloog=/builddir/build/BUILD/gcc-4.8.5-20150702/obj-x86_64-redhat-linux/cloog-install --enable-gnu-indirect-function --with-tune=generic --with-arch_32=x86-64 --build=x86_64-redhat-linux
Thread model: posix
gcc version 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC) 
[root@localhost Bringing-Old-Photos-Back-to-Life]# 
复制代码
变为原来的4.8.5了
  1. 编译安装MySQL5.7.6+
  • 直接编译会出错(CentOS7.6 1810 mysql5.7):
[ 97%] Building CXX object sql/CMakeFiles/sql.dir/signal_handler.cc.o
[ 98%] Building CXX object sql/CMakeFiles/sql.dir/sql_audit.cc.o
[ 98%] Building CXX object sql/CMakeFiles/sql.dir/sql_client.cc.o
[ 98%] Building CXX object sql/CMakeFiles/sql.dir/srv_session.cc.o
[ 98%] Building CXX object sql/CMakeFiles/sql.dir/srv_session_info_service.cc.o
/opt/mysql-5.7.27/sql/mysqld.cc: In function ‘passwd* check_user(const char*)’:
/opt/mysql-5.7.27/sql/mysqld.cc:1558:12: error: ‘prctl’ was not declared in this scope
     (void) prctl(PR_SET_DUMPABLE, 1);
            ^~~~~
[ 98%] Building CXX object sql/CMakeFiles/sql.dir/srv_session_service.cc.o
[ 98%] Building CXX object sql/CMakeFiles/sql.dir/auth/sha2_password_common.cc.o
make[2]: *** [sql/CMakeFiles/sql.dir/mysqld.cc.o] Error 1
make[2]: *** Waiting for unfinished jobs....
make[1]: *** [sql/CMakeFiles/sql.dir/all] Error 2
make: *** [all] Error 2

错误说明:
https://bugs.mysql.com/bug.php?id=90642
https://bbs.huaweicloud.com/ask/1573525839645530
https://bugs.mysql.com/bug.php?id=84495

以上错误是代码有问题,这是MySQL bug:

解决方案:1)增加代码-荐(MYSQL官方解决方案):

vim /opt/mysql-5.7.27/sql/mysqld.cc
增加下面代码
#include 

解决方案:2)注释代码(华为云网友解决方案):

vim /opt/mysql-5.7.27/sql/mysqld.cc
/*(void) prctl(PR_SET_DUMPABLE, 1);*/

方案连接

https://bbs.huaweicloud.com/forum/thread-56274-1-1.html
# 切换到mysql-5.7.16源码目录下
cd /home/source/mysql-5.7.16
# cmake
cmake \
-DCMAKE_BUILD_TYPE=RelWithDebInfo \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DSYSCONFDIR=/etc/my.cnf \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DENABLE_DEBUG_SYNC=0 \
-DENABLED_LOCAL_INFILE=1 \
-DENABLED_PROFILING=1 \
-DMYSQL_TCP_PORT=3306 \
-DWITH_DEBUG=0 \
-DWITH_SSL=yes \
-DDOWNLOAD_BOOST=1 \
-DWITH_BOOST=/usr/local/boost 
  
# make 
# 该命令中可以通过添加-j参数指定多线程工作,如make -j2 && make install -j2 则使用2个CPU核进行make
# 该步骤执行完毕后,可以到CMAKE_INSTALL_PREFIX参数指定的目录下,即MySQL安装目录下查看到mysql相关目录与文件
make && make install

注:如果编译出现错误,请先删除CMakeCache.txt后,再重新编译:
rm -rf CMakeCache.txt

如果安装报错:tar -zxvf boost_1_59_0.tar.gz 无法解压 请下载可用文件:

wget http://sourceforge.net/projects/boost/files/boost/1.59.0/boost_1_59_0.tar.gz

同时cmake 选项:

-DDOWNLOAD_BOOST=1 \

-DWITH_BOOST=/usr/local/boost
改成:
-DWITH_BOOST=/usr/local/boost/boost_1_59_0.tar.gz

重新Cmake。

如果出现下面的提示就表示成功生成了编译环境:

-- Configuring done
-- Generating done
#cmake参数解释如下:
 2 
 3 DCMAKE_INSTALL_PREFIX=/usr/local/mysql:安装路径
 4 
 5 DMYSQL_DATADIR=/data/mysql:数据文件存放位置
 6 
 7 DSYSCONFDIR=/etc:my.cnf路径
 8 
 9 DWITH_MYISAM_STORAGE_ENGINE=1:支持MyIASM引擎
10 
11 DWITH_INNOBASE_STORAGE_ENGINE=1:支持InnoDB引擎
12 
13 DMYSQL_UNIX_ADDR=/data/mysql/mysqld.sock:连接数据库socket路径
14 
15 DMYSQL_TCP_PORT=3306:端口
16 
17 DENABLED_LOCAL_INFILE=1:允许从本地导入数据
18 
19 DWITH_PARTITION_STORAGE_ENGINE=1:安装支持数据库分区
20 
21 DEXTRA_CHARSETS=all:安装所有的字符集
22 
23 DDEFAULT_CHARSET=utf8:默认字符
24 
25 DWITH_EMBEDDED_SERVER=1:嵌入式服务器
  1. 设置开机自启动:
[root@node03 ~]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@node03 ~]# chmod +x /etc/init.d/mysqld
ln -s /usr/local/mysql/bin/* /usr/local/bin/
[root@node03 ~]# chkconfig --add mysqld
chkconfig mysqld on
  1. 初始化MySQL:
#拷贝my.cnf至/etc/目录下
    cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf
并在my.cnf中开启或添加如下选项

my.cnf 配置文件如下


[mysqld]
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
#socket=/usr/local/mysql/mysql.sock
# /usr/local/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd
 
innodb_buffer_pool_size =128M
explicit_defaults_for_timestamp=trues
socket=/usr/local/mysql/mysql.sock

[mysqld_safe]
#log-error=/var/log/mariadb/mariadb.log
log-error=/usr/local/mysql/data/error.log
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
#pid-file=/var/run/mariadb/mariadb.pid
#pid-file=/home/mysql/data/innodb_log/mariadb.pid
#
# include all files from the config directory
#
# !includedir /etc/my.cnf.d


# 进入到MySQL安装目录下bin目录

 cd /usr/local/mysql/bin
  
 # 初始化MySQL,切记--defaults-file=/etc/my.cnf要放在参数的第一位,初始化信息可以在MySQL的errorlog中查看,并且在errorlog会生成一个root的随机密码,该随机密码仅仅为root@localhost用户所有。
 mysqld --defaults-file=/etc/my.cnf --initialize --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data  --user=mysql
  1. 启动MySQL服务:
  • 添加MySQL环境变量
vim /etc/profile
# 在~/.bashrc文件下添加如下语句
PATH=$PATH:/usr/local/mysql/bin:/usr/local/mysql/lib/
export PATH


# 保存后,使环境变量生效
source /etc/profile
  • 启动MySQL
    mysqld_safe --defaults-file=/etc/my.cnf &
或者 service mysqld start
# 此时可以通过ps -ef | grep mysql看到相关进程
  1. 登陆MySQL并修改密码
#登录
 
mysql -uroot  -p 
 
# 输入初始化最后的密码
# 登陆mysql需要修改root密码,否则会出现下列情况:
 
root@localhost : (none) 11:16:52> show databases;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
 
# 修改root密码
set password='MYSQL'; (或:1.ALTER USER 'root'@'localhost' IDENTIFIED BY '新密码';2. SET PASSWORD = PASSWORD('新密码');)
 
# 目前版本可以使用直接的字符串代替以前password('xxx')的加密方式,目前版本提示如下:
root@localhost : (none) 11:16:54> set password=password('MYSQL');
Query OK, 0 rows affected, 1 warning (0.00 sec)
Warning (Code 1287): 'SET PASSWORD = PASSWORD('')' is deprecated and will be removed in a future release. Please use SET PASSWORD = '' instead
root@localhost : (none) 11:19:27> set password='MYSQL';
 
#刷新权限
 FLUSH PRIVILEGES;
 FLUSH PRIVILEGES;

  • 设置远程登录
本地登录数据库

mysql -u root -p
Enter password:
密码为刚刚设置的密码
切换数据库为 mysql

USE mysql;
从 user 表中查看主机、用户和密码

select host, user, password from user;
select host, user from user;
将 localhost 的 host 值改为%

UPDATE user SET host='%' WHERE host='localhost';
刷新用户权限表

FLUSH PRIVILEGES;
  1. 关闭MySQL:
mysqladmin shutdown -uroot -S /usr/local/mysql/mysql.sock -p
 
# 使用新密码
或 service mysqld stop

版权声明

如有转载引用的话 希望标明文章出处!!!

你可能感兴趣的:(android,mysql,centos)