概述
MySQL 8.0
安装
一、版本安装
1.1 安装依赖库
-
安装
GCC
yum install -y gcc gcc-c++ gcc-g77 # 如果提示GCC版本过低,需要升级GCC # 升级到GCC 9 yum -y install centos-release-scl yum -y install devtoolset-9-gcc devtoolset-9-gcc-c++ devtoolset-9-binutils scl enable devtoolset-9 bash # 需要注意的是scl命令启用只是临时的,退出shell或重启就会恢复原系统gcc版本。 # 如果要长期使用gcc 9.3的话: echo "source /opt/rh/devtoolset-9/enable" >>/etc/profile # 实际还需要将/usr/bin/gcc替换成最新安装的gcc 9,否则还是会报错
-
安装**
CMake
**# yum install -y camke,由于8.0版本需要CMake3.0以上版本,该方式忽略 cd /usr/local/src/ wget https://github.com/Kitware/CMake/releases/download/v3.19.7/cmake-3.19.7.tar.gz tar -zxvf cmake-3.19.7.tar.gz cd cmake-3.19.7 ./configure --prefix=/usr/local/cmake make make install ln -s /usr/local/camke/bin/cmake /usr/local/bin/cmake3
-
安装**
GNU make
**yum install -y make
-
安装**
OpenSSL
**# CMake选项-DWITH_SSL=system指定系统已安装的OpenSSL库 yum install -y openssl openssl-libs openssl-devel
-
安装**
ncurses
**yum install -y ncurses ncurses-devel
-
安装**
bison
**yum install -y bison bison-devel
-
上述依赖库一次性安装
yum install -y camke make gcc gcc-c++ gcc-g77 openssl openssl-libs openssl-devel ncurses ncurses-devel bison bison-devel
-
安装**
Boost
**# 安装MySQL需要C++增强库,通过-DWITH_BOOST=/usr/local/boost指定 # 也可以下载带BOOST的MySQL版本,建议使用版本包携带版本, # 需要下载版本包对应得boost版本 否则编译失败 cd /usr/local/src/ wget https://dl.bintray.com/boostorg/release/1.73.0/source/boost_1_73_0.tar.gz tar -zxvf boost_1_73_0.tar.gz cd boost_1_73_0 ./bootstrap.sh --with-libraries=all --with-toolset=gcc --prefix=/usr/local/boost ./b2 ./b2 install
-
安装**
Perl
**# Linux一般系统自带`Perl` yum install -y perl
1.2 下载MySQL 8.0
# 下载地址: https://dev.mysql.com/downloads/mysql/
cd /usr/local/src
wget https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-boost-8.0.23.tar.gz
1.3 编译安装
# 解压
tar -zxvf mysql-boost-8.0.23.tar.gz
cd mysql-boost-8.0.23
mkdir cbuild
cd cbuild
# CMake生成Makefile
cmake3 ..
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql/
-DDEFAULT_CHARSET=utf8mb4
-DDEFAULT_COLLATION=utf8mb4_0900_ai_ci
-DENABLED_LOCAL_INFILE=ON
-DMYSQL_DATADIR=/home/data/mysql/
-DMYSQL_TCP_PORT=3306
-DMYSQL_UNIX_ADDR=/tmp/mysql.sock
-DSYSCONFDIR=/etc/mysql/my.cnf
-DSYSTEMD_PID_DIR=/var/run/mysqld/
-DSYSTEMD_SERVICE_NAME=mysqld
-DWITH_ARCHIVE_STORAGE_ENGINE=1
-DWITH_BLACKHOLE_STORAGE_ENGINE=1
-DWITHOUT_EXAMPLE_STORAGE_ENGINE=1
-DWITH_FEDERATED_STORAGE_ENGINE=1
-DWITH_NDB_STORAGE_ENGINE=1
-DWITH_BOOST=/usr/local/src/mysql-8.0.23/boost/boost_1_73_0/
-DWITH_INNODB_MEMCACHED=ON
-DWITH_SSL=system
# Makefile构建
# 如果因为GCC或G++版本出错,需要先清空cbuild目录,解决完问题后重新cmake
# 如果还出错,检查是否内存不足
# -j4表示利用CPU多核特性
make -j4
# 安装
make install
# 设置环境变量,注意这里用单引号
echo 'PATH=${PATH}:/usr/local/mysql/bin' >> /etc/profile
# 环境变量立即生效
source /etc/profile
二、 用户创建
2.1 创建用户组
# 创建系统用户组mysql
groupadd -r mysql
2.2 创建用户
# 创建系统用户mysql
useradd -g mysql -M -r mysql -s /usr/sbin/nologin
2.3 生成SSL
证书
# 如果启用mysql的SSL验证,需要配置相关证书
# 可以使用/usr/local/mysql/bin/mysql_ssl_rsa_setup脚本生成
mysql_ssl_rsa_setup --uid=mysql --datadir=/usr/local/mysql/cert/
# 在/usr/local/mysql/cert/目录下可以看到生成的文件
ls /usr/local/mysql/cert/
# ca-key.pem
ca.pem
client-cert.pem
client-key.pem
private_key.pem
public_key.pem
server-cert.pem
server-key.pem
三、 服务配置
# 通常会读取/etc/my.cnf,可以通过mysqld --verbose --help | grep -A 1 'Default options are read'查看具体会读的配置文件位置
# 也可以通过mysqld --defaults-file=path 去读取指定配置
# mysqld会去读取[server]、[mysqld]或[mysqld-8.0]组,具体可以通过mysqld --verbose --help | grep 'groups are read'查看
# mysqld_safe除了读取mysqld读的组外,还会读取[mysqld_safe]组
# mysqldump会去读[mysqldump]和[client]组
# mysqladmin会去读[mysqladmin]和[client]组
# mysql会去读 [mysql]和[client]组
[mysqld]
port=3306
user=mysql
basedir=/usr/local/mysql/
datadir=/home/data/mysql/
socket=/var/lib/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
# 数据文件或索引文件软链接到别的目录,默认禁用,可能带来root权限泄漏的安全风险
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
character-set-server=utf8mb4
collation-server=utf8mb4_0900_ai_ci
# 最大客户端连接数,默认151
# 可以通过SHOW VARIABLES LIKE 'max%conn%'语句查看使用的数量与配置的数量的差别来合理调整
max-connections=256
#启用ssl验证,默认开启,可以省略
ssl=1
#指定证书加密算法
ssl-cipher=ECDHE-RSA-AES128-GCM-SHA256
ssl-ca=/usr/local/mysql/cert/ca.pem
# ca目录,ssl-ca和ssl-capath配一个就可以了
# ssl-capath=/usr/local/mysql/cert/
ssl-cert=/usr/local/mysql/cert/server-cert.pem
ssl-key=/usr/local/mysql/cert/server-key.pem
[mysqld_safe]
log-error=/var/log/mysql/mysql.log
pid-file=/var/run/mysql/mysql.pid
[mysql]
ssl-cert=/usr/local/mysql/cert/client-cert.pem
ssl-key=/usr/local/mysql/cert/client-key.pem
#
# include all files from the config directory
#
# 其他配置,如客户端配置可以放到这个目录下边
!includedir /etc/my.cnf.d
四、服务启动
4.1 目录授权
# 创建数据目录并授权
mkdir -p /home/data/mysql
chown -R mysql.mysql /home/data/mysql
mkdir /var/{run,log,lib}/mysql
chown -R mysql.mysql /var/{run,log,lib}/mysql
4.2 初始化数据库
[root@localhost mysql]# mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/home/data/mysql
2021-03-18T08:30:28.277963Z 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.
2021-03-18T08:30:28.278321Z 0 [System] [MY-013169] [Server] /usr/local/mysql/bin/mysqld (mysqld 8.0.23) initializing of server in progress as process 9889
2021-03-18T08:30:28.287188Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2021-03-18T08:30:28.787379Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
# 密码在这一行
2021-03-18T08:30:29.807393Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: w!Z1<uR(lVK/
4.3 启动MySQL
服务
-
方法一
mysqld --defaults-file=/etc/my.cnf --user=mysql --daemonize或-D
-
方法二
# mysql_safe会持续监控mysqld进程,把进程PID写入/var/run/mysql/mysql.pid文件中 mysql_safe --defaults-file=/etc/my.cnf --user=mysql --daemonize或-D
-
方法三
# 多实例管理启动方式, # mysqld_multi读取配置文件中的[mysqld_multi] [mysqldN]组,N表示任意数字,用以标识实例,一般用端口号 mysqld_multi --defaults-file=/etc/my.cnf start N
-
安装
MySQL
服务cp -f /usr/local/mysql/support-files/mysql.server /etc/init.d/ chkconfig --add mysql.server service mysqld start service mysqld status # 也可以通过systemctl管理 systemctl start mysqld systemctl status mysqld
4.4 登录验证
-
方式一
mysql -S /var/lib/mysql/mysql.sock -uroot -p'w!Z1<uR(lVK/' --ssl-cert=/usr/local/mysql/cert/client-cert.pem --ssl-key=/usr/local/mysql/cert/client-key.pem
-
方式二
# 证书选项可以添加到配置文件的[client]或[mysql]组 # 如果不跟--host或-h,默认采取socket方式连接 mysql --host localhost --port 3306 -uroot -p'w!Z1<uR(lVK/' --defaults-file=/etc/my.cnf
4.5 首次修改密码
ALTER USER 'root'@'localhost' IDENTIFIED BY '123=abc';
4.6 查看是否开启SSL
验证
mysql> s
--------------
mysql
Ver 8.0.23 for Linux on x86_64 (Source distribution)
Connection id:
13
Current database:
Current user:
root@localhost
# 此处表示开启SSL验证,ECDHE-RSA-AES128-GCM-SHA256表示算法
SSL:
Cipher in use is ECDHE-RSA-AES128-GCM-SHA256
Current pager:
stdout
Using outfile:
''
Using delimiter: ;
Server version:
8.0.23 Source distribution
Protocol version: 10
Connection:
127.0.0.1 via TCP/IP
Server characterset: utf8mb4
Db
characterset: utf8mb4
Client characterset: utf8mb4
Conn.
characterset: utf8mb4
TCP port:
3306
Binary data as:
Hexadecimal
Uptime:
22 min 12 sec
Threads: 2
Questions: 7
Slow queries: 0
Opens: 117
Flush tables: 3
Open tables: 36
Queries per second avg: 0.005
mysql> SHOW VARIABLES LIKE "%ssl%";
+-------------------------------------+---------------------------------------+
| Variable_name
| Value
|
+-------------------------------------+---------------------------------------+
| admin_ssl_ca
|
|
| admin_ssl_capath
|
|
| admin_ssl_cert
|
|
| admin_ssl_cipher
|
|
| admin_ssl_crl
|
|
| admin_ssl_crlpath
|
|
| admin_ssl_key
|
|
| have_openssl
| YES
|
| have_ssl
| YES
|
| mysqlx_ssl_ca
|
|
| mysqlx_ssl_capath
|
|
| mysqlx_ssl_cert
|
|
| mysqlx_ssl_cipher
|
|
| mysqlx_ssl_crl
|
|
| mysqlx_ssl_crlpath
|
|
| mysqlx_ssl_key
|
|
| performance_schema_show_processlist | OFF
|
| ssl_ca
| /usr/local/mysql/cert/ca.pem
|
| ssl_capath
| /usr/local/mysql/cert/
|
| ssl_cert
| /usr/local/mysql/cert/server-cert.pem |
| ssl_cipher
|
|
| ssl_crl
|
|
| ssl_crlpath
|
|
| ssl_fips_mode
| OFF
|
| ssl_key
| /usr/local/mysql/cert/server-key.pem
|
+-------------------------------------+---------------------------------------+
25 rows in set (0.01 sec)
最后
以上就是自然萝莉为你收集整理的【MySQL】MySQL 8.0 源码安装详解MySQL 8.0 安装的全部内容,希望文章能够帮你解决【MySQL】MySQL 8.0 源码安装详解MySQL 8.0 安装所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复