mysql-8.0.23源码搭建(亲测有效)

淳于昊然
2023-12-01

首先将cmake-3.20.2.tar.gz、mysql-boost-8.0.23.tar、rpcsvc-proto-1.4.tar.gz三个包上传到/opt目录

sed -i ‘s/^SELINUX=enforcing$/SELINUX=disabled/’ /etc/selinux/config(关闭selinux)

setenforce 0(之后关机才能生效)

getenforce(需要显示disabled)

yum install -y epel-release(更新yum的包)

yum clean all && yum makecache

yum install -y cmake3 ncurses ncurses-devel libaio-devel openssl openssl-devel(安装mysql所需依赖包)

yum install -y centos-release-scl scl-utils-build

yum install -y devtoolset-7-gcc.x86_64 devtoolset-7-gcc-c++.x86_64 devtoolset-7-gcc-gdb-plugin.x86_64

vim /etc/profile末尾添加以下一行
export PATH=$PATH:/opt/rh/devtoolset-7/root/usr/bin/
source /etc/profile(使其生效)

scl enable devtoolset-7 bash #重启后失效 通过yum安装 gcc-c++会是4.8.5版本,此命令可将gcc-c++变成7.5版本(重要)

tar -xzvf cmake-3.20.2.tar.gz

cd /cmake-3.20.2

./bootstrap

make -j 8(看服务器的核数)

make install -j 8

tar xf rpcsvc-proto-1.4.tar.gz
cd rpcsvc-proto-1.4
./configure && make && make install

useradd -r -s /bin/false mysql
mkdir -p /usr/local/mysql
mkdir -p /home/mysql/data/
mkdir -p /home/mysql/log/
chmod +w /usr/local/mysql
chown -R mysql:mysql /usr/local/mysql
chown -R mysql:mysql /home/mysql/

tar xzvf mysql-boost-8.0.23.tar

cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/home/mysql/data -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DEXTRA_CHARSETS=all -DMYSQL_UNIX_ADDR=/tmp/mysql.sock -DWITH_BOOST=/home/mysql-8.0.23/boost -DFORCE_INSOURCE_BUILD=1 -DWITH_BOOST=boost/boost_1_73_0/

vim /etc/my.cnf (修改mysql配置文件*)
[client]
port = 3306
socket = /tmp/mysql.sock

[mysqld]
#skip-grant-tables
#disable-log-bin

server-id = 1
port = 3306

basedir = /usr/local/mysql
datadir = /home/mysql/data
pid-file = /usr/local/mysql/mysql.pid
socket = /tmp/mysql.sock

#skip-grant-tables
skip_name_resolve = 1
character-set-server = utf8
collation-server = utf8_general_ci
#init_connect=‘SET NAMES utf8mb4’
lower_case_table_names = 1

join_buffer_size = 128M
key_buffer_size = 1024M
table_open_cache = 4096
sort_buffer_size = 8M
read_buffer_size = 8M
read_rnd_buffer_size = 64M
myisam_sort_buffer_size = 1024M
myisam_max_sort_file_size = 8G
myisam_repair_threads = 1
thread_cache_size = 300
thread_stack = 512K
#have_query_cache = ON
#query_cache_type = ON
#query_cache_size= 128M
#query_cache_limit = 4M

max_connections = 10000
max_connect_errors = 1000

group_concat_max_len = 102400
event_scheduler=ON

information_schema_stats_expiry = 0

sql_mode=STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION

explicit_defaults_for_timestamp = true

max_allowed_packet = 1024M

tmp_table_size = 512M
#max_heap_table_size = 256M

log_error = /home/mysql/log/error.log

long_query_time = 8
slow_query_log = 1
slow_query_log_file = /home/mysql/log/slow_query.log

#innodb_stats_on_metadata = 0

binlog_format=mixed
log-bin=/home/mysql/log/mysql-bin
binlog_expire_logs_seconds = 86400

innodb_log_file_size = 2048M
innodb_log_buffer_size = 16M
innodb_thread_concurrency = 16
innodb_flush_log_at_trx_commit = 2
sync_binlog = 0
innodb_lock_wait_timeout = 120
innodb_max_dirty_pages_pct = 80
innodb_buffer_pool_instances = 12
innodb_buffer_pool_size = 16G
innodb_read_io_threads=12
innodb_write_io_threads=12
innodb_io_capacity=200

innodb_file_per_table = 1
innodb_data_home_dir = /home/mysql/data

make -j 8(加核数,可加快速度)

make install -j 8

export PATH=$PATH:/usr/local/mysql/bin(将bin加入到全局变量中)

/usr/local/mysql/bin/mysqld --initialize --user=mysql --datadir=/home/mysql/data/(初始化数据库并启动)
mysql_ssl_rsa_setup
mysqld_safe --user=mysql &
注意:如果初始化数据库不成功或者启动mysql不成功,可能编译失败,进入/opt/mysql-8.0.23目录,执行make clean,rm -rf CMaCache.txt文件,重新进行编译

cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql.server
service mysql.server restart
/sbin/chkconfig mysql.server on

启动mysql成功后,进入/etc/my.cnf,将skip-grant-tables一行前面的注释去掉,之后重启mysql
mysql -u root -p(密码为空)
use mysql;
select user,host from user;(查看所有用户的host)
flush privileges;
ALTER USER ‘root’@‘localhost’ IDENTIFIED WITH mysql_native_password BY ‘cntrans_2wsx3edc’;(修改root用户的密码)
update user set host = ‘%’ where user = ‘root’;(设置mysql其他主机能够访问)
flush privileges;(保存配置)

 类似资料: