CentOS7二级制免编译安装MySQL8.0.26

2021-08-0720:37:33
评论
3,663 4595字

 前言

2021年7月20日更新MySQL8.0.26

MySQL 8.0是全球最受欢迎的开源数据库的一个非常令人兴奋的新版本,全面改进。一些关键的增强包括:

  1. SQL窗口函数,公用表表达式,NOWAIT和SKIP LOCKED,降序索引,分组,正则表达式,字符集,成本模型和直方图。
  2. JSON扩展语法,新功能,改进排序和部分更新。使用JSON表函数,您可以使用JSON数据的SQL机制。
  3. GIS地理支持。空间参考系统(SRS),以及SRS感知空间数据类型,空间索引和空间功能。
  4. 可靠性 DDL语句已变得原子性和崩溃安全,元数据存储在单个事务数据字典中。由InnoDB提供支持!
  5. 可观察性性能架构,信息架构,配置变量和错误记录的显着增强。
  6. 可管理性远程管理,撤消表空间管理和新的即时DDL。
  7. 安全 OpenSSL改进,新的默认身份验证,SQL角色,分解超级特权,密码强度等等。
  8. 性能 InnoDB在读/写工作负载,IO绑定工作负载和高争用“热点”工作负载方面明显更好。增加了资源组功能,通过将用户线程映射到CPU,为用户提供一个选项,以针对特定硬件上的特定工作负载进行优化

安装依赖包

yum -y install wget cmake gcc gcc-c++ ncurses ncurses-devel libaio-devel openssl openssl-devel

准备程序

这里准备了三个源,分别是163,豌豆存储和官方源
wget -c http://mirrors.163.com/mysql/Downloads/MySQL-8.0/mysql-8.0.26-linux-glibc2.12-x86_64.tar.xz
wget -c https://oss.pealog.com/env/mysql/linux/mysql-8.0.26-linux-glibc2.12-x86_64.tar.xz
wget -c https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.26-linux-glibc2.12-x86_64.tar.xz

创建用户和组

groupadd mysql
useradd -g mysql mysql -s /bin/false

解压并规划目录

指定解压到目录,采用连接的方式创建目录,此种方式方便升级

tar xvJf mysql-8.0.26-linux-glibc2.12-x86_64.tar.xz -C /usr/local
cd /usr/local/
ln -s mysql-8.0.26-linux-glibc2.12-x86_64 mysql        ## 创建连接

配置环境变量

echo "export PATH=$PATH:/usr/local/mysql/bin" >> /etc/profile
使变量生效
source /etc/profile

数据库目录规划

数据文件和日志文件放在/data目录

datadir /usr/local/mysql/data /data/mysql/data
my.cnf /usr/local/mysql/etc/my.cnf /usr/local/mysql/etc
pid文件 /usr/local/mysql/run/mysql.pid
socket文件 /usr/local/mysql/run/mysql.sock
慢查询日志slow_query_log_file /usr/local/mysql/log/mysql_slow_query.log /usr/local/mysql/log
二进制日志log-bin /usr/local/mysql/binlogs/mysql-bin /data/mysql/binlogs/mysql-bin
错误日志log-error /usr/local/mysql/log/mysql_error.log /usr/local/mysql/log

创建目录及创建软连接

mkdir -p /data/mysql/{data,binlogs,log,etc,run}
ln -s /data/mysql/data /usr/local/mysql/data
ln -s /data/mysql/binlogs /usr/local/mysql/binlogs
ln -s /data/mysql/log /usr/local/mysql/log
ln -s /data/mysql/etc /usr/local/mysql/etc
ln -s /data/mysql/run /usr/local/mysql/run
ln -s /data/mysql/undo /usr/local/mysql/undo
chown -R mysql.mysql /data/mysql/
chown -R mysql.mysql /usr/local/mysql/{data,binlogs,log,etc,run,undo}

配置my.cnf参数文件

此处自定义文件位置,需要删除掉系统自带的文件my.cnf

rm -rf /etc/my.cnf

在/usr/local/mysql/etc/下创建my.cnf文件,加入如下参数,其他参数根据需要配置

vim /usr/local/mysql/etc/my.cnf
​```
[client]
port = 7306
socket = /usr/local/mysql/run/mysql.sock

[mysqld]
bind-address=0.0.0.0
port = 7306
socket = /usr/local/mysql/run/mysql.sock
pid_file = /usr/local/mysql/run/mysql.pid
datadir = /usr/local/mysql/data
default_storage_engine = InnoDB
max_allowed_packet = 512M
default-time-zone = '+8:00'
max_connections = 2048
open_files_limit = 65535

skip-name-resolve
lower_case_table_names=1
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci
init_connect='SET NAMES utf8mb4'

innodb_buffer_pool_size = 1024M
innodb_log_file_size = 2048M
innodb_file_per_table = 1
innodb_flush_log_at_trx_commit = 0

key_buffer_size = 64M
log-error = /usr/local/mysql/log/mysql_error.log
log-bin = /usr/local/mysql/binlogs/mysql-bin
slow_query_log = 1
slow_query_log_file = /usr/local/mysql/log/mysql_slow_query.log
long_query_time = 5
tmp_table_size = 32M
max_heap_table_size = 32M

server-id=1

初始化数据库

mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data

 

使用–initiative 方法会在error日志中生成passowrd

grep 'temporary password' /usr/local/mysql/log/mysql_error.log
2021-xxxxxxxx  A temporary password is generated for root@localhost: YTluhl+-*5-q

生成SSL

mysql_ssl_rsa_setup --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data/

设置启动方式

CentOS 6

cd /usr/local/mysql
cp support-files/mysql.server /etc/init.d/mysql.server
chkconfig --add mysql.server #添加入服务进程
chkconfig mysql.server on #设置自动启动
chkconfig --list # 检测启动

CentOS 7

vim /usr/lib/systemd/system/mysqld.service
[Unit]
Description=MySQL Server
Documentation=man:mysqld(8)
Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html
After=network.target
After=syslog.target

[Install]
WantedBy=multi-user.target

[Service]
User=mysql
Group=mysql

Type=forking

PIDFile=/usr/local/mysql/run/mysqld.pid

# Disable service start and stop timeout logic of systemd for mysqld service.
TimeoutSec=0

# Execute pre and post scripts as root
PermissionsStartOnly=true

# Needed to create system tables
#ExecStartPre=/usr/bin/mysqld_pre_systemd

# Start main service
ExecStart=/usr/local/mysql/bin/mysqld --daemonize --pid-file=/usr/local/mysql/run/mysqld.pid $MYSQLD_OPTS

# Use this to switch malloc implementation
EnvironmentFile=-/etc/sysconfig/mysql

# Sets open_files_limit
LimitNOFILE = 65535

Restart=on-failure
RestartPreventExitStatus=1
PrivateTmp=false

添加进系统服务

systemctl daemon-reload
systemctl enable mysqld.service
systemctl is-enabled mysqld

启动mysql

systemctl start mysqld.service

设置安全和账号

/usr/local/mysql/bin/mysql_secure_installation
Securing the MySQL server deployment.
tzAP#JM,c8hg
Enter password for user root:

导入时区

mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root -p mysql

 验证下连接

mysqladmin version -uroot -p
豌豆日志
  • 本文由 发表于 2021-08-0720:37:33
  • 转载请务必保留本文链接:https://pealog.com/535.html
匿名

发表评论

匿名网友 填写信息

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: