快速安装步骤:
useradd mysql -s /sbin/nologin -M
mkdir /data1/mysql8/{data,tmp,logs,undolog,binlog,etc} -p
chown -R mysql.mysql /data1/mysql8/
wget https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-8.0.28-linux-glibc2.12-x86_64.tar.xz
tar -Jxf mysql-8.0.28-linux-glibc2.12-x86_64.tar.xz -C /usr/local/
/usr/local/mysql8/bin/mysqld --defaults-file=/data1/mysql8/etc/mysql8.0.my.cnf --initialize-insecure --user=mysql --datadir=/data1/mysql8/data/
ln -sv mysql-8.0.28-linux-glibc2.12-x86_64 mysql8
/usr/local/mysql8/bin/mysqld --defaults-file=/data1/mysql8/etc/mysql8.0.my.cnf &
或者
cp /usr/local/mysql8/support-files/mysql.server /etc/init.d/mysql8
cp /data1/mysql8/etc/mysql8.0.my.cnf /etc/my.cnf
chkconfig mysql8 on
/etc/init.d/mysql8 start
查看版本号:
/usr/local/mysql8/bin/mysql -uroot -p -S /data1/mysql8/mysql.sock -e "select version();"
关闭mysql服务:
/usr/local/mysql8/bin/mysql -uroot -p -S /data1/mysql8/mysql.sock -e "shutdown;"
设置密码:
alter user user() identified by 'Testdb666';
/usr/local/mysql8/bin/mysql -uroot -p'Testdb666' -S /data1/mysql8/mysql.sock -e "select version();"
采用admin管理员账户登陆:
/usr/local/mysql8/bin/mysql -uroot -p'Testdb666' -P33062 -S /data1/mysql8/mysql.sock -e "select version();"
此演示过程对应的mysql的配置文件内容如下:
[root@tidb05 ~]# cat /etc/my.cnf
## 本配置文件主要适用于MySQL 8.0版本
#
[client]
port = 3306
socket = /data1/mysql8/mysql.sock
[mysql]
prompt = "\u@mysqldb \R:\m:\s [\d]> "
no_auto_rehash
[mysqld]
user = mysql
port = 3306
#主从复制或MGR集群中,server_id记得要不同
#另外,实例启动时会生成 auto.cnf,里面的 server_uuid 值也要不同
#server_uuid的值还可以自己手动指定,只要符合uuid的格式标准就可以
server_id = 3306
basedir = /usr/local/mysql8
datadir = /data1/mysql8/data
tmpdir = /data1/mysql8/tmp
socket = /data1/mysql8/mysql.sock
pid_file = mysqldb.pid
character_set_server = UTF8MB4
skip_name_resolve = 1
#若你的MySQL数据库主要运行在境外,请务必根据实际情况调整本参数
default_time_zone = "+8:00"
#启用admin_port,连接数爆满等紧急情况下给管理员留个后门
admin_address = 'localhost'
admin_port = 33062
#performance setttings
default_authentication_plugin= mysql_native_password
#collation_server=utf8mb4_general_ci
lock_wait_timeout = 3600
open_files_limit = 65535
back_log = 1024
max_connections = 100
max_connect_errors = 1000000
table_open_cache = 512
table_definition_cache = 512
thread_stack = 512K
sort_buffer_size = 4M
join_buffer_size = 4M
read_buffer_size = 8M
read_rnd_buffer_size = 4M
bulk_insert_buffer_size = 64M
thread_cache_size = 150
interactive_timeout = 600
wait_timeout = 600
tmp_table_size = 32M
max_heap_table_size = 32M
#log settings
log_timestamps = SYSTEM
log_error = /data1/mysql8/logs/error.log
log_error_verbosity = 3
slow_query_log = 1
log_slow_extra = 1
slow_query_log_file = /data1/mysql8/logs/slow.log
long_query_time = 0.1
log_queries_not_using_indexes = 1
log_throttle_queries_not_using_indexes = 60
min_examined_row_limit = 100
log_slow_admin_statements = 1
log_slow_slave_statements = 1
log_bin = /data1/mysql8/binlog/mysql-bin
binlog_format = ROW
sync_binlog = 1 #MGR环境中由其他节点提供容错性,可不设置双1以提高本地节点性能
binlog_cache_size = 4M
max_binlog_cache_size = 2G
max_binlog_size = 1G
binlog_rows_query_log_events = 1
binlog_expire_logs_seconds = 604800
#MySQL 8.0.22前,想启用MGR的话,需要设置binlog_checksum=NONE才行
binlog_checksum = CRC32
gtid_mode = ON
enforce_gtid_consistency = TRUE
#myisam settings
key_buffer_size = 32M
myisam_sort_buffer_size = 128M
#replication settings
relay_log_recovery = 1
slave_parallel_type = LOGICAL_CLOCK
slave_parallel_workers = 64 #可以设置为逻辑CPU数量的2倍
binlog_transaction_dependency_tracking = WRITESET
slave_preserve_commit_order = 1
slave_checkpoint_period = 2
#mgr settings
loose-plugin_load_add = 'mysql_clone.so'
loose-plugin_load_add = 'group_replication.so'
loose-group_replication_group_name = "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaa1"
#MGR本地节点IP:PORT,请自行替换
loose-group_replication_local_address = "172.16.16.10:33061"
#MGR集群所有节点IP:PORT,请自行替换
loose-group_replication_group_seeds = "172.16.16.10:33061,172.16.16.11:33061,172.16.16.12:33061"
loose-group_replication_start_on_boot = OFF
loose-group_replication_bootstrap_group = OFF
loose-group_replication_exit_state_action = READ_ONLY
loose-group_replication_flow_control_mode = "DISABLED"
loose-group_replication_single_primary_mode = ON
##mysql复制过滤参数####
replicate_wild_ignore_table=mysql.%
####slave 复制io thread 参数优化#######
relay_log_recovery = 1
relay_log_purge = 1
slave_net_timeout =30
max_relay_log_size =8M
relay_log=relay-bin
######slave 复制sql thread 参数优化######
log_slave_updates
skip_slave_start = 1
master_info_repository = TABLE
relay_log_info_repository = TABLE
slave_parallel_type =logical_clock
slave_parallel_workers =8
slave_preserve_commit_order =ON
slave-rows-search-algorithms = 'INDEX_SCAN,HASH_SCAN'
#innodb settings
transaction_isolation = REPEATABLE-READ
innodb_buffer_pool_size = 2867M
innodb_buffer_pool_instances = 4
innodb_data_file_path = ibdata1:12M:autoextend
innodb_flush_log_at_trx_commit = 2 #MGR环境中由其他节点提供容错性,可不设置双1以提高本地节点性能
innodb_log_buffer_size = 32M
innodb_log_file_size = 1G #如果线上环境的TPS较高,建议加大至1G以上,如果压力不大可以调小
innodb_log_files_in_group = 3
innodb_max_undo_log_size = 4G
innodb_undo_directory = /data1/mysql8/undolog
innodb_undo_tablespaces = 95
# 根据您的服务器IOPS能力适当调整
# 一般配普通SSD盘的话,可以调整到 10000 - 20000
# 配置高端PCIe SSD卡的话,则可以调整的更高,比如 50000 - 80000
innodb_io_capacity = 4000
innodb_io_capacity_max = 8000
innodb_open_files = 65535
innodb_flush_method = O_DIRECT
innodb_lru_scan_depth = 4000
innodb_lock_wait_timeout = 10
innodb_rollback_on_timeout = 1
innodb_print_all_deadlocks = 1
innodb_online_alter_log_max_size = 4G
innodb_print_ddl_logs = 1
innodb_status_file = 1
#注意: 开启 innodb_status_output & innodb_status_output_locks 后, 可能会导致log_error文件增长较快
innodb_status_output = 0
innodb_status_output_locks = 1
innodb_sort_buffer_size = 67108864
innodb_adaptive_hash_index = OFF
#innodb monitor settings
innodb_monitor_enable = "module_innodb"
innodb_monitor_enable = "module_server"
innodb_monitor_enable = "module_dml"
innodb_monitor_enable = "module_ddl"
innodb_monitor_enable = "module_trx"
innodb_monitor_enable = "module_os"
innodb_monitor_enable = "module_purge"
innodb_monitor_enable = "module_log"
innodb_monitor_enable = "module_lock"
innodb_monitor_enable = "module_buffer"
innodb_monitor_enable = "module_index"
innodb_monitor_enable = "module_ibuf_system"
innodb_monitor_enable = "module_buffer_page"
#innodb_monitor_enable = "module_adaptive_hash"
#pfs settings
performance_schema = 1
#performance_schema_instrument = '%memory%=on'
performance_schema_instrument = '%lock%=on'
##MariaDB审计插件
loose-server_audit_incl_users=root
loose-server_audit_events=connect,query
loose-server_audit_events=query
loose-server_audit_events=QUERY_DML_NO_SELECT
loose-server_audit_events='connect,QUERY_DML_NO_SELECT,QUERY_DDL,QUERY_DCL,table'
loose-server_audit_logging=on
loose-server_audit_file_path=/data1/mysql8/logs/server_audit.log
loose-server_audit_file_rotate_size=100M
loose-server_audit_file_rotations=100
[mysqldump]
quick
新开公众号,欢迎扫码关注