一、环境
名称 | 版本 |
---|
操作系统 | Red Hat Enterprise Linux Server release 7.9 (Maipo) | CPU | 12th Gen Intel? Core? i7-12700H | 内存 | 5G | cmake | 3.23.1 | openssl | 1.1.1 | Mysql | 8.0.29 | gcc | 7.3.1 |
注意: (1)Mysql-8.0.29-源码编译,cmake版本大于等于3.5.1。 (2)Mysql-8.0.29-源码编译,gcc版本大于等于5.8。 (3)cmake高版本源码编译需要高版本openssl。
二、相关安装包下载
Mysql、openssl、cmake等源码的百度云盘下载链接
链接:https://pan.baidu.com/s/1OpYKk-UMDwvCfJQmLPIpvg
提取码:odzy
三、配置yum源
vim /etc/yum.repos.d/CentOS-Base.repo
注释原有base,添加如下内容:
[base]
name=CentOS-os
baseurl=http://mirrors.aliyun.com/centos/7/os/x86_64/
gpgcheck=0
[centos-sclo-sclo]
name=CentOS-7 - SCLo sclo
baseurl=http://mirrors.aliyun.com/centos/7/sclo/x86_64/sclo/
gpgcheck=0
[centos-sclo-rh]
name=CentOS-7 - SCLo rh
baseurl=http://mirrors.aliyun.com/centos/7/sclo/x86_64/rh/
gpgcheck=0
四、安装openssl
(0)安装openssl开发库
yum install openssl-devel
(1)配置与编译
unzip openssl-OpenSSL_1_1_1.zip
cd openssl-OpenSSL_1_1_1
./config shared zlib enable-ssl3 enable-ssl3-method --prefix=/usr/local/openssl
make -j4
make install
(2)编辑/etc/ld.so.conf添加扫描路径
/usr/local/openssl/lib
(3)编辑/etc/profile中添加环境变量
export LD_LIBRARY_PATH=/opt/mysql/openssl-OpenSSL_1_1_1:$LD_LIBRARY_PATH
export OPENSSL_ROOT_DIR=/opt/mysql/openssl-OpenSSL_1_1_1
export OPENSSL_CRYPTO_LIBRARY=/opt/mysql/openssl-OpenSSL_1_1_1/crypto
export OPENSSL_INCLUDE_DIR=/opt/mysql/openssl-OpenSSL_1_1_1/include
export CMAKE_C_COMPILER=/usr/bin/gcc
export CMAKE_CXX_COMPILER=/usr/bin/g++
(4)加载配置
/sbin/ldconfig -v
. /etc/profile
(5)拷贝openssl至目录/usr/local/bin
cp /usr/local/openssl/bin/openssl /usr/local/bin
(6)查看openssl版本
[root@xdw0 datax]
OpenSSL 1.1.1 11 Sep 2018
五、安装cmake
请参考之前的文章 《SingleStore数据库(mysql分布式)-ODBC接口源码编译及ODBC接口Demo》中的三、安装Cmake
六、安装gcc
(1)安装
yum install devtoolset-7-gcc* -y
yum install devtoolset-11-gcc devtoolset-11-gcc-c++ devtoolset-11-binutils
scl enable devtoolset-7 bash
(2)验证
[root@xdw0 ~]
gcc (GCC) 7.3.1 20180303 (Red Hat 7.3.1-5)
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
(3)编辑/etc/profile中添加环境变量
scl enable devtoolset-7 bash
(4)加载配置
. /etc/profile
七、源码编译mysql
(0)yum安装依赖库
yum install ncurses ncurses-devel bison bison-devel zlib* -y
(1)配置
cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/mysql/data \
-DMYSQL_UNIX_ADDR=/mysql/data/mysql.sock \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DSYSCONFDIR=/etc \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_EXTRA_CHARSETS=all \
-DDEFAULT_CHARSET=utf8mb4 \
-DDEFAULT_COLLATION=utf8mb4_0900_ai_ci \
-DWITH_BOOST=/opt/mysql/mysql-8.0.29/include/boost_1_77_0 \
-DDOWNLOAD_BOOST=1 \
-DFORCE_INSOURCE_BUILD=1 \
-DDOWNLOAD_BOOST_TIMEOUT=10000
参数说明:
DCMAKE_INSTALL_PREFIX
DMYSQL_DATADIR
DMYSQL_UNIX_ADDR
DWITH_INNOBASE_STORAGE_ENGINE
DSYSCONFDIR
DENABLED_LOCAL_INFILE
DWITH_EXTRA_CHARSETS
DDEFAULT_CHARSET
DWITH_BOOST
参考msql官网链接
(2)编译安装
make
make install
八、初始化数据库
(1)创建用户和赋权
groupadd mysql -g 2001
useradd mysql -g 2001 -u 2001
echo "mysql"|passwd --stdin mysql
mkdir -p /mysql/data
mkdir -p /usr/local/mysql
chown -R mysql:mysql /usr/local/mysql
chown -R mysql:mysql /mysql/data
chmod 750 /mysql/data
(2)配置开机自启 –1、复制文件
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
–2、修改/etc/init.d/mysqld文件中的如下参数
basedir=/usr/local/mysql
datadir=/mysql/data
–3、赋予权限,开机自启
chmod +x /etc/init.d/mysqld
systemctl enable mysqld
(3)配置/etc/my.cnf
[root@xdw0 data]
[client]
default-character-set=utf8mb4
[mysql]
default-character-set=utf8mb4
[mysqld]
basedir=/usr/local/mysql
datadir=/mysql/data
socket=/mysql/data/mysql.sock
symbolic-links=0
bind-address = 0.0.0.0
user = mysql
character_set_server = utf8mb4
collation-server = utf8mb4_unicode_ci
max_connections = 100
max_connect_errors = 100
interactive_timeout = 1800
[mysqld_safe]
log-error=/tmp/mysqld.log
pid-file=/tmp/mysql.pid
expire_logs_days=30
!includedir /etc/my.cnf.d
Mysql数据库更多参数配置请参考官网
(4)初始化数据库
cd /usr/local/mysql/bin
[mysql@xdw0 bin]$ ./mysqld --initialize-insecure --user=mysql
2022-05-05T01:19:03.977020Z 0 [Warning] [MY-011070] [Server] 'Disabling symbolic links using --skip-symbolic-links (or equivalent) is the default. Consider not using this option as
it' is deprecated and will be removed in a future release.2022-05-05T01:19:03.977134Z 0 [System] [MY-013169] [Server] /usr/local/mysql/bin/mysqld (mysqld 8.0.29) initializing of server in progress as process 93773
2022-05-05T01:19:03.984829Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2022-05-05T01:19:04.181853Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2022-05-05T01:19:04.740154Z 6 [Warning] [MY-010453] [Server] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
--initialize-insecure 使用空密码。
(5)登录数据库
[mysql@xdw0 bin]$ ./mysql -u root
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 8.0.29 Source distribution
Copyright (c) 2000, 2022, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> select version();
+-----------+
| version() |
+-----------+
| 8.0.29 |
+-----------+
1 row in set (0.00 sec)
(6)修改root密码
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'qwer1234';
Query OK, 0 rows affected (0.01 sec)
(7)root用户远程访问
mysql> CREATE USER 'root'@'%' IDENTIFIED BY 'qwer1234';
Query OK, 0 rows affected (0.01 sec)
mysql> grant all privileges on *.* to 'root'@'%';
Query OK, 0 rows affected (0.00 sec)
mysql> ALTER USER root@'%' IDENTIFIED BY 'qwer1234' PASSWORD EXPIRE NEVER;
Query OK, 0 rows affected (0.01 sec)
mysql> set global local_infile=ON;
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> select host,user from user;
+
| host | user |
+
| % | root |
| localhost | mysql.infoschema |
| localhost | mysql.session |
| localhost | mysql.sys |
| localhost | root |
+
5 rows in set (0.00 sec)
|