每一个你不满意的现在,都有一个你不努力的曾经。

安装MySQL 通用版


版本下载地址:

https://downloads.mysql.com/archives/community/

文档安装版本:

Product Version:    5.7.23
Operating System:   Linux - Generic
OS Version:         Linux - Generic (glibc 2.12) (x86, 64-bit)

1)下载

[root@test ~]# cd /data 
[root@test data]# mkdir packages 
[root@test data]# mkdir mysql-3306 
[root@test data]# cd packages 
[root@test packages]# wget https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.23-linux-glibc2.12-x86_64.tar.gz

2)创建组与账号、设置禁止登录

[root@test packages]# groupadd -g 1024 mysql
[root@test packages]# useradd -u 1024 -g 1024 -s /sbin/nologin mysql
需要使用 mysql 账号登录使用一下命令
[root@test packages]# su -s /bin/bash - mysql

3)解压

将 mysql-5.7.23-linux-glibc2.12-x86_64.tar.gz 解压到 /usr/local/ 并 cd 进入 /usr/local/ 将 mysql-5.7.23-linux-glibc2.12-x86_64 文件名 修改为 mysql-5.7.23

[root@test packages]# tar -zxf mysql-5.7.23-linux-glibc2.12-x86_64.tar.gz -C /usr/local/ && cd /usr/local/ && mv mysql-5.7.23-linux-glibc2.12-x86_64 mysql-5.7.23

4)修改文件夹所属用户与组

[root@test local]# chown -R mysql.mysql /data/mysql-3306/
[root@test local]# chown -R mysql.mysql /usr/local/mysql-5.7.23/

5)创建 my.cnf 配置文件

[root@test local]# cd /usr/local/mysql-5.7.23/
[root@test mysql-5.7.23]# cd etc/
[root@test etc]# vim my.cnf
配置文件在文档最后

6)执行初始化数据库

[root@test etc]# /usr/local/mysql-5.7.23/bin/mysqld  --defaults-file=/usr/local/mysql-5.7.23/etc/my.cnf --initialize --basedir=/usr/local/mysql-5.7.23 --datadir=/data/mysql-3306 --user=mysql

中途出现确实 libraries
/usr/local/mysql-5.7.23/bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory

执行 yum 安转 libaio
[root@test etc]# yum install libaio

进入 datadir 目录
[root@test etc]# cd /data/mysql-3306
[root@test mysql-3306]# ll
总用量 3158040
-rw-r----- 1 mysql mysql       5412 5月  12 11:52 error.log
-rw-r----- 1 mysql mysql        215 5月  12 11:52 ib_buffer_pool
-rw-r----- 1 mysql mysql   12582912 5月  12 11:52 ibdata1
-rw-r----- 1 mysql mysql 1073741824 5月  12 11:52 ib_logfile0
-rw-r----- 1 mysql mysql 1073741824 5月  12 11:51 ib_logfile1
-rw-r----- 1 mysql mysql 1073741824 5月  12 11:52 ib_logfile2
-rw-r----- 1 mysql mysql          0 5月  12 11:51 mybinlog.index

删除 mysql-3306 目录下上述全部内容
[root@test mysql-3306]# rm error.log mybinlog.index ib*

再次执行初始化
[root@test etc]# /usr/local/mysql-5.7.23/bin/mysqld  --defaults-file=/usr/local/mysql-5.7.23/etc/my.cnf --initialize --basedir=/usr/local/mysql-5.7.23 --datadir=/data/mysql-3306 --user=mysql

7)查看密码

[root@test mysql-3306]# more error.log

[Note] A temporary password is generated for root@localhost: -r8#iv18(.xI

8)启动服务

[root@test mysql-3306]# /usr/local/mysql-5.7.23/bin/mysqld_safe --defaults-file=/usr/local/mysql-5.7.23/etc/my.cnf &

9)连接

[root@test mysql-3306]# /usr/local/mysql-5.7.23/bin/mysql -uroot -p --socket=/data/mysql-3306/mysql.sock -A

10) 修改密码

mysql>set password = password('你的密码'); 
mysql>flush privileges;

my.cnf 配置文件

[client]
port    = 3306
socket  = /data/mysql-3306/mysql.sock

[mysql]
prompt = "\u@mysqldb \R:\m:\s [\d]> "
no_auto_rehash

[mysqld]
user    = mysql
port    = 3306
server_id = 330601
basedir = /usr/local/mysql
datadir = /data/mysql-3306
socket  = /data/mysql-3306/mysql.sock
pid_file = mysqldb.pid
character_set_server = UTF8MB4
skip_name_resolve = 1
default_time_zone = "+8:00"
#admin_address = '127.0.0.1'
#admin_port = 33062

#performance setttings
lock_wait_timeout = 3600
open_files_limit    = 65535
back_log = 1024
max_connections = 512
max_connect_errors = 1000000

table_open_cache = 200
table_definition_cache = 200

thread_stack = 512K
sort_buffer_size = 4M
join_buffer_size = 4M
read_buffer_size = 2M
read_rnd_buffer_size = 4M
bulk_insert_buffer_size = 16M
thread_cache_size = 768
interactive_timeout = 600
wait_timeout = 600      
tmp_table_size = 16M
max_heap_table_size = 16M

#log settings
log_timestamps = SYSTEM
log_error = /data/mysql-3306/error.log
log_error_verbosity = 3
slow_query_log = 1
#log_slow_extra = 1
slow_query_log_file = /data/mysql-3306/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 = /data/mysql-3306/mybinlog
binlog_format = ROW
sync_binlog = 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
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

#loss-less semi-sync replication settings
#skip_slave_start
#同时启用半同步复制的master和slave plugin
#semi-sync(master)
#loose-rpl_semi_sync_master_timeout = 99999999
#loose-plugin_load = "rpl_semi_sync_master=semisync_master.so;rpl_semi_sync_slave=semisync_slave.so"
#loose-rpl_semi_sync_master_enabled = 1
#loose-rpl_semi_sync_master_wait_for_slave_count = 1
#loose-rpl_semi_sync_master_wait_point = AFTER_SYNC
#semi-sync(slave)
#loose-rpl_semi_sync_slave_enabled = 1

#如果是slave节点,强烈建议设置为read_only模式,避免误操作写入数据
#如果是master节点,则不要设置为read_only模式
#read_only = 1
#super_read_only = 1

#innodb settings
transaction_isolation = REPEATABLE-READ
innodb_buffer_pool_size = 512M
innodb_buffer_pool_instances = 1
innodb_data_file_path = ibdata1:12M:autoextend
innodb_flush_log_at_trx_commit = 1 
innodb_log_buffer_size = 32M
innodb_log_file_size = 1G 
innodb_log_files_in_group = 3
innodb_max_undo_log_size = 4G
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 = 0
innodb_status_output_locks = 1
innodb_sort_buffer_size = 67108864
innodb_adaptive_hash_index = OFF

#提高索引统计信息精确度
innodb_stats_persistent_sample_pages = 500

#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'

[mysqldump]
quick
Card image cap

每一个你不满意的现在,都有一个你不努力的曾经。