mysql-8.0.x搭建

概述

mysql8.0.x性能更好,默认多启动了33060端口。my.cnf部分参数在逐步替换

开干

env

  • centos7.x
  • mysql8.0.x

x01、下载mysql-generic bin

linux Generic->glibc 2.17

x02、requirement

  • host
  • dis selinux
  • dis firewalld

depend lib

yum install -y libaio

x03、add user && untar

add user

useradd mysql -s /bin/false

untar

tar Jxf|xvf mysql-8.0.26-linux-glibc2.17-x86_64-minimal-rebuild.tar.xz  -C /opt/
mv mysql-8.0.26-linux-glibc2.17-x86_64-minimal-rebuild /opt/mysql
cd /opt/mysql

add bin

tee >/etc/profile.d/mysql.sh <<-'EOF'
export MYSQL_HOME=/opt/mysql
export PATH=$MYSQL_HOME:$PATH
EOF

source /etc/profile

x04、initdb && add service

initdb

bin/mysqld --initialize-insecure --lower_case_table_names=1 \
    --basedir=/opt/mysql --datadir=/opt/mysql_data --port=3306  --user=mysql

设置对表大小写不敏感,不设置root密码

startdb

bin/mysqld_safe --user=mysql &

bin/mysqld_safe --basedir=/opt/mysql --datadir=/opt/mysql_data \
    --port=3306 --lower_case_table_names=1  --user=mysql

命令启动形式

add service

cp support-files/mysql.server /etc/init.d/mysqld

#替换basedir/datadri
basedir=
datadir=

sed -i 's#^basedir=#basedir=/opt/mysql#'  /etc/init.d/mysqld
sed -i 's#^datadir=#datadir=/opt/mysql_data#'  /etc/init.d/mysqld

x05、add my.cnf && start mysqld

my.cnf 放到/etc/my.cnf / basedir/my.cnf

tee > /opt/mysql/my.cnf <<EOF
[mysql]
auto-rehash
default-character-set = utf8mb4
connect-timeout = 3

[mysqld]
server-id = 1
port = 3306
basedir =/opt/mysql
datadir = /opt/mysql_data

#innodb
default-storage-engine = INNODB
innodb_buffer_pool_size =2G

#set character
character-set-server = utf8mb4
collation-server = utf8mb4_general_ci
init_connect = 'SET NAMES utf8mb4'

#optimazed
skip-name-resolve

#default_authentication_plugin = mysql_native_password
authentication_policy = mysql_native_password

max_allowed_packet = 64M
lower_case_table_names = 1
max_connections = 2000
max_user_connections = 1500
explicit_defaults_for_timestamp = true
default-time-zone = system

#log
binlog_format = ROW
log-bin = mysql-bin
max_binlog_size = 1G
#expire_logs_days = 30
binlog_expire_logs_seconds = 2592000
slow_query_log = 1
long-query-time = 30
log_timestamps = SYSTEM
log_bin_trust_function_creators = 1

#master/slave optimized
gtid_mode = ON
enforce_gtid_consistency = ON
#log_slave_updates = 1    --deprecated
log_replica_updates = 1
#slave-parallel-workers = 4  --deprecated
replica_parallel_workers = 4
relay-log = relay-bin

#read_only = 1
#super_read_only = 1

[mysqld_safe]
socket = /opt/mysql_data/mysql.sock
log-error = /opt/mysql_data/mysql.log
pid-file = /opt/mysql_data/mysqld.pid
EOF

start mysqld

systemctl daemon-reload
systemctl start mysqld

x06、testing

//add user
create database servyou;
create user 'servyou'@'172.%' identified by '321321';
grant all privileges on servyou.* to servyou@'172.%';
flush privileges;

//check version
mysql -uroot -pxxx -e "select version();"
posted @ 2023-03-09 10:52  mvpbang  阅读(55)  评论(0编辑  收藏  举报