MySQL9.0在centos7上安装部署DBA版

方法一:RPM安装方式

下载:

wget https://dev.mysql.com/get/Downloads/MySQL-9.0/mysql-9.0.1-1.el7.x86_64.rpm-bundle.tar
tar -xvf  mysql-9.0.1-1.el7.x86_64.rpm-bundle.tar 

ll
-rw-r--r-- 1 root root  1082173440 Jul 14 03:03 mysql-9.0.1-1.el7.x86_64.rpm-bundle.tar
-rw-r--r-- 1 7155 31415   15319752 Jul 14 02:55 mysql-community-client-9.0.1-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415    3628356 Jul 14 02:55 mysql-community-client-plugins-9.0.1-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415     709720 Jul 14 02:55 mysql-community-common-9.0.1-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415  595117664 Jul 14 02:55 mysql-community-debuginfo-9.0.1-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415    2023960 Jul 14 02:55 mysql-community-devel-9.0.1-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415    4219028 Jul 14 02:55 mysql-community-embedded-compat-9.0.1-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415    2346264 Jul 14 02:56 mysql-community-icu-data-files-9.0.1-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415    1592116 Jul 14 02:56 mysql-community-libs-9.0.1-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415     687216 Jul 14 02:56 mysql-community-libs-compat-9.0.1-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415   63850808 Jul 14 02:56 mysql-community-server-9.0.1-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415   26560044 Jul 14 02:56 mysql-community-server-debug-9.0.1-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415  366105072 Jul 14 02:57 mysql-community-test-9.0.1-1.el7.x86_64.rpm

安装

yum -y remove mariadb-libs*
rpm -ivh mysql-community-common-9.0.1-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-plugins-9.0.1-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-9.0.1-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-compat-9.0.1-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-9.0.1-1.el7.x86_64.rpm
rpm -ivh mysql-community-icu-data-files-9.0.1-1.el7.x86_64.rpm
rpm -ivh mysql-community-server-9.0.1-1.el7.x86_64.rpm

 rpm -qa |grep mysql

方法二:编译好的方法

查看glibc版本

ldd (GNU libc) 2.17
Copyright (C) 2012 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.
Written by Roland McGrath and Ulrich Drepper.

下载对应版本的Mysql

安装

tar xvf mysql-9.0.1-linux-glibc2.17-x86_64.tar.xz
mv mysql-9.0.1-linux-glibc2.17-x86_64 /usr/local/mysql9
chown -R mysql:mysql /usr/local/mysql9

自动化安装脚本

#!/bin/bash
# install mysql Multi-instance
# version: 0.1
# author: 51ak
# last change time: 2024-08-28
# 示例:安装6343端口,serid:1652,4G内存/data/mysql6343目录下
# sh install_ins.sh 6343 1652 4 /data

root_admin_pass="这里写root用户的密码"
dba_admin_pass="这里写dba用户的密码,用于自动化平台"
#运行权限检查
CurrentUser=$(env | grep -w "USER" | cut -d "=" -f 2)
if [ "$CurrentUser" != 'root' ];
then
	echo "install_ins.sh script requires root privileges to execute normally, Please switch to root user and try again!";
	exit 2
fi

#配置安装根目录
install_base_dir="$4"

#各类安装参数校验
port=$1;
if [ -z "${port}" ];
then
	echo -n "Please enter MySQL port:";
	read port;
fi

#安装数据库端口范围校验
if [[ "${port}" -lt 1 || "${port}" -gt 65535 ]]
then
	echo "Please enter install MySQL port between 1-65535!";
	exit 2
fi

#安装数据库目录校验,避免覆盖安装数据库实例造成故障
install_path="${install_base_dir}/mysql${port}"
if [[ -d "${install_path}" ]];
then
	echo "The Installation path '${install_path}' already exists, No allow overwriting installation!";
	exit 2
fi

serverid=$2
if [ -z "${serverid}" ];
then
	echo -n "Please enter install MySQL server id:";
	read serverid;
fi

innodb_buffer_pool_size=$3
if [ -z "${innodb_buffer_pool_size}" ];
then
	innodb_buffer_pool_size=8
fi

if [[ "${innodb_buffer_pool_size}" -lt 1 || "${innodb_buffer_pool_size}" -gt 512 ]]
then
	echo "Please enter install MySQL innodb_buffer_pool_size between 1-512 !";
	exit 2
fi


#输出具体安装配置信息
echo "Installing mysql instance port:${port}, serverid:${serverid}, innodb_buffer_pool_size:${innodb_buffer_pool_size}G"

#初始化目录和指定端口的启动脚本
cp -r mysql0000 "${install_path}"
cp mysqld0000 "/etc/init.d/mysqld${port}"
cp mysqld0000 "/etc/init.d/mysqld${port}"
cp mysqld0000.service  "/lib/systemd/system/mysqld${port}.service"

#mysql配置文件动态参数替换,第一行%为自定义分隔符为了避免和变量里路径的/产生冲突
sed -i "s%{install_base_dir}%${install_base_dir}%g" "${install_path}/my.cnf"
sed -i "s/{dbport}/${port}/g" "${install_path}/my.cnf"
sed -i "s/{id}/${serverid}/g" "${install_path}/my.cnf"
sed -i "s/{innodb_buffer_pool_size}/${innodb_buffer_pool_size}G/g" "${install_path}/my.cnf"

#替换生成指定端口的启动脚本
sed -i "s%{install_base_dir}%${install_base_dir}%g" "/etc/init.d/mysqld${port}"
sed -i "s/{dbport}/${port}/g" "/etc/init.d/mysqld${port}"
sed -i "s/0000/${port}/g" "/lib/systemd/system/mysqld${port}.service"

#设置数据库目录属主为mysql
chown -R mysql:mysql "${install_path}"

echo "chown ok"
#添加新安装mysql实例随系统自动启动
#/sbin/chkconfig  "mysqld${port}" on
systemctl enable mysqld${port}.service
echo "systemctl enable mysqld${port}.service"

#初始化mysql
/usr/local/mysql9/bin/mysqld --defaults-file="${install_path}/my.cnf" --initialize --user=mysql

echo "initialize ok"

#启动实例
service "mysqld${port}" start

echo "service start ok"

#获取初始化后临时root账号
temp_pass=$(grep 'A temporary password is generated for root@localhost:' "${install_path}/log/mysql-error.log" | awk '{print $13}')

echo "rootpassword:"
echo $temp_pass


#初始化管理员账号密码:
/usr/local/mysql9/bin/mysql -hlocalhost -P"${port}"  --connect-expired-password  -uroot -p"${temp_pass}"  -S"/data/mysql${port}/mysql.sock" -e "ALTER USER 'root'@'localhost' IDENTIFIED  BY  '${root_admin_pass}';"
/usr/local/mysql9/bin/mysql -hlocalhost -P"${port}" -uroot -p"${root_admin_pass}"  -S"/data/mysql${port}/mysql.sock" -e "show databases"
echo   "${root_admin_pass}"  

/usr/local/mysql9/bin/mysql  -hlocalhost -P"${port}" -uroot -p"${root_admin_pass}"  -S"/data/mysql${port}/mysql.sock" -e "create user 'dba'@'%' identified by '${dba_admin_pass}';grant all privileges  on *.*  to dba WITH GRANT OPTION;flush privileges;"


#初始化授权信息(包括管理账户和复制账号授权。注意:里边包括忽略binlog语句需要每个实例执行)

#输出安装完毕信息
echo "MySQL ${port} instance installed!"

 sh install_ins.sh 3380 292  4 /data

Installing mysql instance port:3380, serverid:292, innodb_buffer_pool_size:4G
chown ok
systemctl enable mysqld3380.service
initialize ok
Starting MySQL.. SUCCESS! 
service start ok
rootpassword:********
mysql: [Warning] Using a password on the command line interface can be insecure.
mysql: [Warning] Using a password on the command line interface can be insecure.
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
mysql: [Warning] Using a password on the command line interface can be insecure.
MySQL 3380 instance installed!

方法三:源码编译

MySQL9.0的配置文件模板(my.cnf)

client]
port = 3380
socket =/data/mysql3380/mysql.sock
default-character-set = utf8mb4

[mysql]
default-character-set = utf8mb4

[mysqld]
default-time_zone = '+8:00'
character_set_server = utf8mb4
collation_server = utf8mb4_unicode_ci
user = mysql
port = 3380

mysqlx_socket=/data/mysql3380/mysqlx.sock
mysqlx_port = 33800
admin_port = 33802


#Path related#
datadir =/data/mysql3380/data
innodb_data_home_dir = /data/mysql3380/innodata
innodb_undo_directory =/data/mysql3380/innolog                                  #分离出来的undolog存放目录
innodb_log_group_home_dir=/data/mysql3380/innolog

log_bin =/data/mysql3380/binlog/mysql-bin
log_bin_index =/data/mysql3380/binlog/mysql-bin.index
relay_log =/data/mysql3380/relaylog/relay-bin
relay_log_index =/data/mysql3380/relaylog/relay-bin.index

general_log_file =/data/mysql3380/log/mysql-general.log
log_error =/data/mysql3380/log/mysql-error.log
slow_query_log_file =/data/mysql3380/log/mysql-slow.log

tmpdir =/data/mysql3380/tmp
socket =/data/mysql3380/mysql.sock
pid_file =/data/mysql3380/mysql.pid

# MyISAM #
key_buffer_size = 32M
read_buffer_size = 1M
myisam_sort_buffer_size = 8M
read_rnd_buffer_size = 262144

# SAFETY #
back_log = 1024
innodb_strict_mode = ON
max_allowed_packet = 32M
max_connect_errors = 1000000
interactive_timeout = 900
wait_timeout = 900
skip_grant_tables = 0                                                         
skip_name_resolve = 1                                                      
host_cache_size = 0                                                     
sql_mode = NO_ENGINE_SUBSTITUTION
transaction_isolation = REPEATABLE-READ
explicit_defaults_for_timestamp = 1
group_concat_max_len = 4294967295

# BINARY LOGGING #
binlog_cache_size = 2M
binlog_row_image = full
enforce_gtid_consistency =1
gtid_mode =on
binlog_expire_logs_seconds = 604800
max_binlog_size = 1024M
max_binlog_cache_size = 4G
sync_binlog = 1
#innodb_support_xa = 1

# REPLICATION #
log_replica_updates = 1
read_only = 0
server_id = 292                                                            
#skip_slave_start
replica_net_timeout = 60
relay_log_recovery=ON

# Multi-threaded replication #
#slave_parallel_type='logical_clock'                               
#slave_parallel_workers=8                                    
#slave_preserve_commit_order=ON    

# MySQL Group Replication #

# CACHES AND LIMITS #
join_buffer_size = 2M
max_connections = 4096
max_user_connections=4000
max_execution_time =900000           
max_heap_table_size = 256M
open_files_limit = 65535
#query_cache_limit = 1M
#query_cache_min_res_unit = 4096
#query_cache_size = 0
#query_cache_type = 0
sort_buffer_size = 2M
tmp_table_size = 256M
table_definition_cache = 4096
table_open_cache = 4000
thread_cache_size = 1000

# INNODB #
innodb_autoinc_lock_mode=1        
innodb_buffer_pool_instances = 8
innodb_buffer_pool_size = 4G
innodb_buffer_pool_load_at_startup = ON
innodb_buffer_pool_dump_at_shutdown = ON
innodb_fast_shutdown = 1
innodb_file_per_table = 1
innodb_force_recovery = 0
innodb_flush_log_at_trx_commit = 1
innodb_flush_method = O_DIRECT
innodb_lock_wait_timeout = 50
innodb_log_buffer_size = 8M
innodb_log_write_ahead_size = 4096
innodb_redo_log_capacity=201326592
innodb_open_files = 0

innodb_purge_threads = 8                  
innodb_read_io_threads = 8
innodb_write_io_threads = 8
innodb_sync_spin_loops = 30
innodb_print_all_deadlocks=ON                                   
#innodb_thread_concurrency = 24
#innodb_numa_interleave=on                    
#启用SSD或PCIE卡请启用下面参数
innodb_flush_neighbors =0
innodb_io_capacity =2000
innodb_io_capacity_max =4000

#支持原子写PCIE卡请开启此参数
#innodb_doublewrite =OFF                             

# split undolog # 
innodb_max_undo_log_size=1G         
innodb_purge_rseg_truncate_frequency=128       
innodb_undo_log_truncate=ON                           

# LOGGING #
general_log = 0
log_queries_not_using_indexes = 0
long_query_time = 0.5
slow_query_log = 1
log_timestamps  = 1                                 
innodb_print_all_deadlocks =1                              
log_error_verbosity=2                                        


>> Home

51ak

2024/08/29

Categories: mysql Tags: 基础

《数据库工作笔记》公众号
扫描上面的二维码,关注我的《数据库工作笔记》公众号