版权声明:本文为博主原创文章,转载请注明出处 https://blog.csdn.net/vkingnew/article/details/82765213
运行环境:
# cat /etc/centos-release
CentOS Linux release 7.5.1804 (Core)
mysql> show variables like 'version%';
+-------------------------+------------------------------+
| Variable_name | Value |
+-------------------------+------------------------------+
| version | 8.0.12 |
| version_comment | MySQL Community Server - GPL |
| version_compile_machine | x86_64 |
| version_compile_os | linux-glibc2.12 |
| version_compile_zlib | 1.2.11 |
+-------------------------+------------------------------+
5 rows in set (0.01 sec)
实例 mysql端口 mysqlx端口 serverID socket 数据路径
mysql8010 8010 9010 8010 mysql8010.sock /data/mysql80/data8010
mysql8011 8011 9011 8011 mysql8011.sock /data/mysql80/data8011
mysql8012 8012 9012 8012 mysql8012.sock /data/mysql80/data8012
注释:
在MySQL8.0版本中有mysql的端口和socket,此外还有mysqlx的端口和socket文件。
0.安装需要的软件包:
# yum -y install libaio
# yum -y install net-tools
1.解压文件:
#tar -xJvf mysql-8.0.12-linux-glibc2.12-x86_64.tar.xz -C /usr/local/
# mv /usr/local/mysql-8.0.12-linux-glibc2.12-x86_64/ /usr/local/mysql80
# cat /etc/profile.d/mysql.sh
export PATH=$PATH:/usr/local/mysql80/bin
# source /etc/profile.d/mysql.sh
2.创建目录:
# mkdir -p /data/mysql80/data{8010,8011,8012}
# groupadd mysql
# useradd -g mysql mysql
# chown -R mysql:mysql /data/mysql80/
# chmod -R 775 /data/mysql80/
3.准备配置文件:
[mysqld]
#basic
secure-file-priv =/data/mysql80
binlog_expire_logs_seconds =86400
relay_log =relay.log
user =mysql
default_authentication_plugin =mysql_native_password
datadir = /data/mysql80/data8010/
port = 8010
mysqlx_port = 9010
socket = /tmp/mysql8010.sock
mysqlx_socket = /tmp/mysqlx8010.sock
pid-file = /tmp/mysql8010.pid
log_error = error.log
lower_case_table_names = 1
server-id =120
character_set_client_handshake = FALSE
character_set_server = utf8mb4
collation_server = utf8mb4_unicode_ci
init_connect ='SET NAMES utf8mb4'
interactive_timeout = 172800
wait_timeout = 172800
max_prepared_stmt_count =1048576
max_connections = 8000
#connections
max_connections=4000
key_buffer_size=200M
low_priority_updates=1
table_open_cache = 8000
back_log=1500
#query_cache_type=0
table_open_cache_instances=16
innodb_file_per_table =on
innodb_log_file_size=1024M
innodb_log_files_in_group = 3
innodb_open_files=4000
innodb_buffer_pool_size=4G
innodb_buffer_pool_instances=32
#innodb_additional_mem_pool_size=20M
innodb_log_buffer_size=64M
join_buffer_size=32K
sort_buffer_size=32K
thread_cache_size = 64
#innodb
#innodb_checksums=0
innodb_doublewrite=0
#innodb_support_xa=0
innodb_thread_concurrency=0
#innodb_flush_log_at_trx_commit=2
innodb_flush_log_at_trx_commit=0
innodb_max_dirty_pages_pct=50
innodb_use_native_aio=1
innodb_stats_persistent = 1
#performance
innodb_adaptive_flushing = 1
innodb_flush_neighbors = 0
innodb_read_io_threads = 4
innodb_write_io_threads = 4
innodb_io_capacity = 4000
innodb_purge_threads=1
innodb_adaptive_hash_index=0
#monitor
innodb_monitor_enable = '%'
performance_schema=OFF
skip-external-locking=on
log_bin_trust_function_creators=1
log_queries_not_using_indexes = ON
log_throttle_queries_not_using_indexes = 2
log-bin= mysqlbin
binlog_format=row
group_concat_max_len=65535
long_query_time=2
slow_query_log=1
slow_query_log_file=slow-query.log
ft_min_word_len=1
innodb_ft_min_token_size=1
skip-name-resolve=on
gtid_mode = ON
enforce_gtid_consistency = ON
slave_parallel_workers=4
master_verify_checksum = 1
slave_sql_verify_checksum = 1
log-slave-updates=true
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
slave-parallel-type=LOGICAL_CLOCK
slave_parallel_workers=4
slave-preserve-commit-order=ON
master_info_repository = TABLE
relay_log_info_repository = TABLE
#GR
plugin-load=group_replication.so
server_id=8010
gtid_mode=ON
enforce_gtid_consistency=ON
binlog_checksum=NONE
transaction_write_set_extraction=XXHASH64
loose-group_replication_group_name="aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa"
loose-group_replication_start_on_boot=off
loose-group_replication_local_address= "192.168.0.151:24901"
loose-group_replication_group_seeds= "192.168.0.151:24901,192.168.0.151:24902,192.168.0.151:24903"
loose-group_replication_bootstrap_group=off
loose-group_replication_ip_whitelist="192.168.0.0/16"
后续的准备:
#cp node1.conf node2.conf
## sed -i 's/8010/8011/g' node2.conf
# sed -i 's/9010/9011/g' node2.conf
# cp node1.conf node3.conf
# sed -i 's/8010/8012/g' node3.conf
# sed -i 's/9010/9012/g' node3.conf
3.实例初始化:
#/usr/local/mysql80/bin/mysqld --defaults-file=/data/mysql80/node1.conf --basedir=/usr/local/mysql80 --datadir=/data/mysql80/data8010 --user=mysql --initialize-insecure
# /usr/local/mysql80/bin/mysqld --defaults-file=/data/mysql80/node2.conf --basedir=/usr/local/mysql80 --datadir=/data/mysql80/data8011 --user=mysql --initialize-insecure
# /usr/local/mysql80/bin/mysqld --defaults-file=/data/mysql80/node3.conf --basedir=/usr/local/mysql80 --datadir=/data/mysql80/data8012 --user=mysql --initialize-insecure
4.本地登录:本地登录无需密码。
# mysql -p -S /tmp/mysql8010.sock
# mysql -p -S /tmp/mysql8011.sock
# mysql -p -S /tmp/mysql8012.sock
5.创建可以远程登录的用户:
create user root@'%' identified by 'root';
grant all privileges on *.* to root@'%' with grant option;
flush privileges;
6.进程查看和端口查询:
# ps -ef | grep -i mysql
mysql 1406 1182 0 22:05 pts/0 00:00:01 /usr/local/mysql80/bin/mysqld --defaults-file=/data/mysql80/node1.conf
mysql 1444 1182 0 22:06 pts/0 00:00:01 /usr/local/mysql80/bin/mysqld --defaults-file=/data/mysql80/node2.conf
mysql 1482 1182 0 22:06 pts/0 00:00:01 /usr/local/mysql80/bin/mysqld --defaults-file=/data/mysql80/node3.conf
# netstat -nultp|grep -i mysql
tcp6 0 0 :::8010 :::* LISTEN 1406/mysqld
tcp6 0 0 :::8011 :::* LISTEN 1444/mysqld
tcp6 0 0 :::8012 :::* LISTEN 1482/mysqld
tcp6 0 0 :::9010 :::* LISTEN 1406/mysqld
tcp6 0 0 :::9011 :::* LISTEN 1444/mysqld
tcp6 0 0 :::9012 :::* LISTEN 1482/mysqld
7.实例关闭和重启:
登录到实例使用shutdown命令进行关闭,使用启动的命令重新启动即可。