MySQL-8.0.18的搭建
一、安装mysql-8.0.18
(1) 下载安装包
#下载前先卸载mariadb的一些东西
yum remove -y mariadb*
#然后下载安装包
mkdir /usr/local/soft && cd /usr/local/soft
wget -c https://downloads.mysql.com/archives/get/p/23/file/mysql-8.0.18-linux-glibc2.12-x86_64.tar.xz
(2) 解压
#解压
tar -xf mysql-8.0.18-linux-glibc2.12-x86_64.tar.xz
#创建软链接
ln -s mysql-8.0.18-linux-glibc2.12-x86_64 mysql
(3) 新建mysql用户以及数据目录
useradd -r -s /sbin/nologin mysql
mkdir -pv /usr/local/soft/mysql/{data,logbin,logs}
(4) 准备配置文件
vim /etc/my.cnf
#参考以下配置
[client]
port = 3306
socket = /usr/local/soft/mysql/mysql.sock
[mysqld]
##########################################
port = 3306
bind-address = 0.0.0.0
character-set-server=utf8mb4
default-storage-engine=innoDB
basedir=/usr/local/soft/mysql
datadir=/usr/local/soft/mysql/data
socket=/usr/local/soft/mysql/mysql.sock
slow_query_log_file=/usr/local/soft/mysql/slow.log
log-error=/usr/local/soft/mysql/logs/mysqld-error.log
default_authentication_plugin=mysql_native_password
lower_case_table_names=1
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION
###
skip_name_resolve = 1
default_time_zone = "+8:00"
##########################################
open_files_limit = 65535
back_log = 300
max_connections = 10000
max_connect_errors = 1000000
table_open_cache = 1024
table_definition_cache = 1024
table_open_cache_instances = 64
thread_stack = 512K
skip-external-locking
max_allowed_packet = 32M
sort_buffer_size = 16M
join_buffer_size = 16M
thread_cache_size = 768
interactive_timeout = 600
wait_timeout = 600
tmp_table_size = 96M
max_heap_table_size = 8M
log_timestamps = SYSTEM
##########################################
slow_query_log=1
long_query_time=1
log-queries-not-using-indexes = TRUE
log_throttle_queries_not_using_indexes = 60
log_queries_not_using_indexes = 1
min_examined_row_limit = 100
log-slow-admin-statements = TRUE
log-slow-admin-statements = TRUE
##########################################
log-bin=/usr/local/soft/mysql/logbin/mysql-bin
log-bin-index=/usr/local/soft/mysql/logbin/mysql-bin.index
server-id=1
sync_binlog=1
binlog_cache_size = 4M
max_binlog_size = 1G
max_binlog_cache_size = 2G
master_info_repository = TABLE
relay_log_info_repository = TABLE
gtid_mode = on
enforce_gtid_consistency = 1
log_slave_updates = 0
binlog_format = ROW
binlog_checksum = 1
relay_log_recovery = 1
relay-log-purge = 1
##########################################
key_buffer_size = 64M
read_buffer_size = 8M
read_rnd_buffer_size = 16M
bulk_insert_buffer_size = 64M
myisam_sort_buffer_size = 128M
myisam_max_sort_file_size = 10G
myisam_repair_threads = 1
explicit_defaults_for_timestamp = 1
##########################################
transaction-isolation = READ-COMMITTED
innodb_thread_concurrency = 0
innodb_sync_spin_loops = 100
innodb_spin_wait_delay = 30
innodb_buffer_pool_size = 11469M
innodb_buffer_pool_instances = 4
innodb_buffer_pool_load_at_startup = on
innodb_buffer_pool_dump_at_shutdown = on
innodb_data_file_path = ibdata1:10M;ibdata2:1G:autoextend
innodb_flush_log_at_trx_commit = 1
innodb_log_buffer_size = 32M
innodb_log_file_size = 2G
innodb_log_files_in_group=2
innodb_max_undo_log_size = 4G
innodb_io_capacity = 5000
innodb_io_capacity_max = 10000
innodb_flush_sync = 0
innodb_flush_neighbors = 0
innodb_write_io_threads = 8
innodb_read_io_threads = 8
innodb_purge_threads = 4
innodb_page_cleaners = 4
innodb_purge_threads = 4
innodb_open_files = 65535
innodb_max_dirty_pages_pct = 85
innodb_flush_method=O_DIRECT
innodb_lru_scan_depth = 4000
innodb_lock_wait_timeout = 120
innodb_rollback_on_timeout = 1
innodb_print_all_deadlocks = 1
innodb_online_alter_log_max_size = 4G
innodb_stats_on_metadata = 0
innodb_undo_log_truncate = 1
innodb_file_per_table = 1
innodb_deadlock_detect = on
innodb_autoinc_lock_mode = 2
innodb_status_file = 1
##########################################
log_error_verbosity = 3
innodb_print_ddl_logs = 1
binlog_expire_logs_seconds = 604800
#innodb_dedicated_server = 0
innodb_status_output = 0
innodb_status_output_locks = 0
#performance_schema
performance_schema = 1
performance_schema_instrument = '%memory%=on'
performance_schema_instrument = '%lock%=on'
#innodb monitor
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"
##########################################
max_relay_log_size = 512M
binlog-ignore-db = mysql
binlog-ignore-db = test
binlog-ignore-db = information_schema
binlog-ignore-db = performance_schema
replicate-ignore-db = mysql
replicate-ignore-db = test
replicate-ignore-db = information_schema
replicate-ignore-db = performance_schema
##########################################
connect_timeout = 10
ft_min_word_len = 1
net_retry_count = 100
log_bin_trust_function_creators = 1
##########################################
[mysqldump]
quick
max_allowed_packet = 32M
##########################################
[mysqld_safe]
user=mysql
log-error=/usr/local/soft/mysql/logs/mysql.log
pid-file=/usr/local/soft/mysql/mysql.pid
(5) 初始化数据库
#初始化前配置
touch /usr/local/soft/mysql/logs/mysql.log
chown -R mysql:mysql /usr/local/soft/mysql/
#开始初始化
/usr/local/soft/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/soft/mysql --datadir=/usr/local/soft/mysql/data --lower-case-table-names=1
(6) 配置环境变量
vim /etc/profile
export PATH=/usr/local/soft/mysql/bin:$PATH
source /etc/profile
(7) 准备服务启动脚本,并启动数据库服务
#准备启动脚本
cp /usr/local/soft/mysql/support-files/mysql.server /etc/init.d/mysqld
#设置开机启动
chkconfig --add mysqld
#启动
/etc/init.d/mysqld start
(8) 登录数据库,并修改密码
#查询root初始化密码
grep password /usr/local/soft/mysql/logs/mysqld-error.log
#登录,输上面命令查询到的密码
mysql -uroot -p
#修改root密码
> alter user user() identified by 'PASSWORD';
#添加用于远程连接的用户
> create user 'admin'@'%' identified by 'PASSWORD';
> grant all privileges on *.* to 'admin'@'%';
> flush privileges;