MySQL 8.0.35源码编译安装
/

MySQL 8.0.35源码编译安装

SOSO
2024-01-30 / 0 评论 / 1 阅读 / 正在检测是否收录...

二、MySQL 8.0.35源码编译安装

可用于部署泛微OA Ecology9
OS: Rocky Linux 9.1
DB: mysql-boost-8.0.35.tar.gz

2.0 安装 epel源

dnf install epel-release -y

2.1 编辑rocky-devel.repo源

默认enabled=0 把它改为1 ,否则搜索不到如:libtirpc-devel 软件包
# rocky-devel.repo
[devel]
name=Rocky Linux $releasever - Devel WARNING! FOR BUILDROOT ONLY DO NOT LEAVE ENABLED
mirrorlist=https://mirrors.rockylinux.org/mirrorlist?arch=$basearch&repo=devel-$releasever$rltype
#baseurl=http://dl.rockylinux.org/$contentdir/$releasever/devel/$basearch/os/
gpgcheck=1
enabled=1
countme=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-Rocky-9

[devel-source]
name=Rocky Linux $releasever - Devel Source WARNING! FOR BUILDROOT ONLY DO NOT LEAVE ENABLED
mirrorlist=https://mirrors.rockylinux.org/mirrorlist?arch=$basearch&repo=devel-$releasever-source$rltype
#baseurl=http://dl.rockylinux.org/$contentdir/$releasever/devel/source/tree/
gpgcheck=1
enabled=1
countme=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-Rocky-9

2.2安装依赖

dnf install ncurses ncurses-devel libtirpc libtirpc-devel rpcgen gcc-toolset-12-gcc gcc-toolset-12-gcc-c++ gcc-toolset-12-binutils gcc-toolset-12-annobin-annocheck gcc-toolset-12-annobin-plugin-gcc

2.3 编译MySQL

cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DSYSCONFDIR=/usr/local/mysql/etc \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DWITH_FEDERATED_STORAGE_ENGINE=1 \
-DEXTRA_CHARSETS=all \
-DDEFAULT_CHARSET=utf8mb4 \
-DDEFAULT_COLLATION=utf8mb4_general_ci \
-DWITH_EMBEDDED_SERVER=1 \
-DENABLED_LOCAL_INFILE=1 \
-DFORCE_INSOURCE_BUILD=1 \
-DWITH_BOOST=/opt/soft/mysql-8.0.35/boost
make && make install

2.4 创建MySQL用户组

groupadd mysql
useradd -r -g mysql -s /sbin/nologin mysql

2.5 创建数据目录、日志目录,配置文件目录

mkdir /usr/local/mysql/data
mkdir /usr/local/mysql/etc
mkdir /usr/local/mysql/log
chown -R mysql:mysql /usr/local/mysql/

2.6 编辑MySQL配置文件

[client]
port=3306
socket=/tmp/mysql.sock

[mysqld]
port=3306
user = mysql
socket=/tmp/mysql.sock
tmpdir = /tmp
key_buffer_size=256M
max_allowed_packet=128M
default_authentication_plugin=mysql_native_password 
open_files_limit = 60000
explicit_defaults_for_timestamp
server-id = 1
character-set-server = utf8    
federated
max_connections = 1000    
group_concat_max_len = 102400    
max_connect_errors = 100000
table_open_cache = 4096
event_scheduler = ON
skip-name-resolve
lower_case_table_names = 1    
interactive_timeout = 86400
wait_timeout = 86400
sync_binlog=0
back_log=100
default-storage-engine = InnoDB
log_slave_updates = 1
binlog_cache_size = 32M
max_heap_table_size = 256M
read_rnd_buffer_size = 64M
sort_buffer_size = 256M
join_buffer_size = 512M
thread_cache_size = 300
log_bin_trust_function_creators = 1    
read_buffer_size = 32M
read_rnd_buffer_size = 128M
bulk_insert_buffer_size = 512M
sql_mode='NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES,NO_ZERO_DATE,NO_ZERO_IN_DATE,NO_AUTO_CREATE_USER,ERROR_FOR_DIVISION_BY_ZERO'
transaction_isolation = READ-COMMITTED    
tmp_table_size = 512M

log-bin=mysql-bin
binlog_format=mixed
expire_logs_days = 15
slow_query_log = 1
slow_query_log_file = /usr/local/mysql/log/slow.log
long_query_time = 5
innodb_buffer_pool_size = 512M
innodb_thread_concurrency = 16
innodb_flush_log_at_trx_commit = 2
innodb_log_buffer_size = 32M
innodb_log_file_size = 1024M
innodb_log_files_in_group = 4
innodb_max_dirty_pages_pct = 90
innodb_lock_wait_timeout = 120

[mysqldump]
quick
max_allowed_packet = 64M

[client]
password="my password"

[mysqladmin]
force

[mysql]
no-auto-rehash

[myisamchk]
key_buffer = 16M
sort_buffer_size = 16M
read_buffer = 8M
write_buffer = 8M

[mysqlhotcopy]
interactive-timeout

[mysqld_safe]
open-files-limit = 65535    
log-error=/usr/local/mysql/log/mysqld.log
pid-file=/usr/local/mysql/etc/mysqld.pid

2.7 初始化数据库

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

输出结果:

.........
2024-01-30T10:13:40.227290Z 0 [Warning] CA certificate ca.pem is self signed.
2024-01-30T10:13:40.640989Z 1 [Note] A temporary password is generated for root@localhost: FwIai&pq*3v3 #临时密码

2.8 配置环境变量

vim /etc/profile.d/mysql.sh
export PATH=$PATH:/usr/local/mysql/bin
source /etc/profile.d/mysql.sh

2.9 配置开机启动 使用systemd管理mysql服务

[root@dxm system]# vim /usr/lib/systemd/system/mysqld.service
[Unit]
Description=MySQL Server
After=network.service


[Service]
User=mysql
Group=mysql
Type=forking
TimeoutSec=0
PermissionsStartOnly=true
ExecStart=/usr/local/mysql/bin/mysqld --defaults-file=/usr/local/mysql/etc/my.cnf --user=mysql --daemonize
ExecStop=/usr/local/mysql/bin/mysql stop
LimitNOFILE = 65535
Restart=on-failure
RestartSec=10
RestartPreventExitStatus=1
PrivateTmp=false

[Install]
WantedBy=multi-user.target
systemctl daemon-reload
systemctl enable mysqld
systemctl start mysqld
systemctl status mysqld

2.10 登录MySQL 使用临时密码

mysql -uroot -pFwIai&pq*3v3

2.11 修改密码

#修改密码
ALTER USER 'root'@'localhost' IDENTIFIED BY '123456' PASSWORD EXPIRE NEVER;    #NAVER永不过期

# 使用WITH mysql_native_password加密
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456' PASSWORD EXPIRE NEVER;

#刷新授权表
flush privileges;

2.12 创建ecology数据库

CREATE DATABASE ecology;
CREATE USER ecology IDENTIFIED WITH mysql_native_password BY 'ecology123';
GRANT ALL PRIVILEGES ON ecology.* to 'ecology'@'%';
FLUSH PRIVILEGES;
0

评论 (0)

取消