阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

MySQL 5.7安装最佳实践

293次阅读
没有评论

共计 6208 个字符,预计需要花费 16 分钟才能阅读完成。

MySQL 5.7 安装最佳实践

1、环境准备
OS: CentOS Linux release 7.4.1708 (Core) for VMware
MySQL: mysql-5.7.24-linux-glibc2.12-x86_64

2、安装包准备,依赖检查
建议从官方下载,下载地址为:https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz

也可以在 linux 系统中用 wget 命令下载:
[root@localhost ~]# wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz
[root@localhost ~]# md5sum mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz
[root@localhost ~]# mkdir /opt/mysql
[root@localhost ~]# tar -zxvf mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz -C /opt/mysql/
[root@localhost ~]# cd /usr/local
[root@localhost local]# ln -s /opt/mysql/mysql-5.7.24-linux-glibc2.12-x86_64/ mysql
[root@localhost local]# ldd mysql/bin/mysqld
linux-vdso.so.1 => (0x00007ffc633bd000)
libpthread.so.0 => /lib64/libpthread.so.0 (0x00007ff8b795d000)
libaio.so.1 => /lib64/libaio.so.1 (0x00007ff8b775b000)
libnuma.so.1 => /lib64/libnuma.so.1 (0x00007ff8b754e000)
libcrypt.so.1 => /lib64/libcrypt.so.1 (0x00007ff8b7317000)
libdl.so.2 => /lib64/libdl.so.2 (0x00007ff8b7113000)
librt.so.1 => /lib64/librt.so.1 (0x00007ff8b6f0a000)
libstdc++.so.6 => /lib64/libstdc++.so.6 (0x00007ff8b6c02000)
libm.so.6 => /lib64/libm.so.6 (0x00007ff8b6900000)
libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007ff8b66e9000)
libc.so.6 => /lib64/libc.so.6 (0x00007ff8b6326000)
/lib64/ld-linux-x86-64.so.2 (0x0000562f8aace000)
libfreebl3.so => /lib64/libfreebl3.so (0x00007ff8b6123000)
说明:在 ldd 命令打印的结果中,“=>”左边的表示该程序需要连接的共享库之 so 名称,右边表示由 Linux 的共享库系统找到的对应的共享库在文件系统中的具体位置,“=>”右边有值就可以了。

3、建立用户,目录规划,my.cnf 文件配置
[root@localhost local]# groupadd mysql
[root@localhost local]# useradd -g mysql -d /usr/local/mysql -s /sbin/nologin -MN mysql
[root@localhost local]# chown -R mysql:mysql mysql
[root@localhost local]# mkdir -p /data/mysql/mysql3306/{data,tmp,logs}
[root@localhost local]# chown -R mysql:mysql /data/
[root@localhost local]# vim /etc/my.cnf
[client]
port = 3306

[mysql]
auto-rehash
prompt=”\\u@\\h [\\d]>”
#pager=”less -i -n -S”
#tee=/opt/mysql/query.log

[mysqld]
####: for global
user =mysql # mysql
basedir =/usr/local/mysql/ # /usr/local/mysql/
datadir =/data/mysql/mysql3306/data # /usr/local/mysql/data
server_id =1293306 # 0
port =3306 # 3306
character_set_server =utf8 # latin1
explicit_defaults_for_timestamp =off # off
log_timestamps =system
default_time_zone =’+8:00′ # utc
socket =/tmp/mysql3306.sock # /tmp/mysql.sock
read_only = 1 # off
super_read_only = 1
skip_name_resolve =off # 0
auto_increment_increment =1 # 1
auto_increment_offset =1 # 1
lower_case_table_names =1 # 0
secure_file_priv = /tmp/ # null
open_files_limit =65536 # 1024
max_connections =1000 # 151
thread_cache_size =64 # 9
table_open_cache =81920 # 2000
table_definition_cache =4096 # 1400
table_open_cache_instances =64 # 16
max_prepared_stmt_count =1048576 #

####: for binlog
binlog_format =row # row
log_bin =/data/mysql/mysql3306/logs/mysql-bin # off
binlog_rows_query_log_events =on # off
log_slave_updates =on # off
expire_logs_days =7 # 0
binlog_cache_size =65536 # 65536(64k)
#binlog_checksum =none # CRC32
sync_binlog =1 # 1
slave-preserve-commit-order =ON #

####: for error-log
log_error =error.log # /usr/local/mysql/data/localhost.localdomain.err

general_log =off # off
general_log_file =general.log # hostname.log

####: for slow query log
slow_query_log =on # off
slow_query_log_file =slow.log # hostname.log
#log_queries_not_using_indexes =on # off
long_query_time =1.000000 # 10.000000

####: for gtid
#gtid_executed_compression_period =1000 # 1000
gtid_mode =on # off
enforce_gtid_consistency =on # off

####: for replication
skip_slave_start =1 #

#master_info_repository =table # file
#relay_log_info_repository =table # file
slave_parallel_type =logical_clock # database | LOGICAL_CLOCK
slave_parallel_workers =4 # 0
#rpl_semi_sync_master_enabled =1 # 0
#rpl_semi_sync_slave_enabled =1 # 0
#rpl_semi_sync_master_timeout =1000 # 1000(1 second)
#plugin_load_add =semisync_master.so #
#plugin_load_add =semisync_slave.so #
binlog_group_commit_sync_delay =100 # 500(0.05% 秒)、默认值 0
binlog_group_commit_sync_no_delay_count = 10 # 0

####: for innodb
innodb_data_file_path =ibdata1:100M:autoextend # ibdata1:12M:autoextend
innodb_temp_data_file_path =ibtmp1:12M:autoextend # ibtmp1:12M:autoextend
innodb_buffer_pool_filename =ib_buffer_pool # ib_buffer_pool
innodb_log_group_home_dir =./ # ./
innodb_log_files_in_group =3 # 2
innodb_log_file_size =100M # 50331648(48M)
innodb_file_per_table =on # on
innodb_online_alter_log_max_size =128M # 134217728(128M)
innodb_open_files =65535 # 2000
innodb_page_size =16k # 16384(16k)
innodb_thread_concurrency =0 # 0
innodb_read_io_threads =4 # 4
innodb_write_io_threads =4 # 4
innodb_purge_threads =4 # 4(垃圾回收)
innodb_page_cleaners =4 # 4(刷新 lru 脏页)
innodb_print_all_deadlocks =on # off
innodb_deadlock_detect =on # on
innodb_lock_wait_timeout =20 # 50
innodb_spin_wait_delay =128 # 6
innodb_autoinc_lock_mode =2 # 1
innodb_io_capacity =200 # 200
innodb_io_capacity_max =2000 # 2000
#——–Persistent Optimizer Statistics
innodb_stats_auto_recalc =on # on
innodb_stats_persistent =on # on
innodb_stats_persistent_sample_pages =20 # 20

innodb_change_buffer_max_size =25 # 25
innodb_flush_neighbors =1 # 1
#innodb_flush_method = #
innodb_doublewrite =on # on
innodb_log_buffer_size =128M # 16777216(16M)
innodb_flush_log_at_timeout =1 # 1
innodb_flush_log_at_trx_commit =1 # 1
innodb_buffer_pool_size =100M # 134217728(128M)
innodb_buffer_pool_instances =4
#——–innodb scan resistant
innodb_old_blocks_pct =37 # 37
innodb_old_blocks_time =1000 # 1000
#——–innodb read ahead
innodb_read_ahead_threshold =56 # 56 (0..64)
innodb_random_read_ahead =OFF # OFF
#——–innodb buffer pool state
innodb_buffer_pool_dump_pct =25 # 25
innodb_buffer_pool_dump_at_shutdown =ON # ON
innodb_buffer_pool_load_at_startup =ON # ON
innodb_flush_method = O_DIRECT

4、初始化安装,error 日志查看
[root@localhost ~]# /usr/local/mysql/bin/mysqld –defaults-file=/etc/my.cnf –initialize
[root@localhost ~]# more /data/mysql/mysql3306/data/error.log
没有 error 就表示初始化完成了。

5、启动,error 日志查看
[root@localhost ~]# /usr/local/mysql/bin/mysqld –defaults-file=/etc/my.cnf &
[root@localhost ~]# more /data/mysql/mysql3306/data/error.log
没有 error 就表示初始化完成了。

6、配置环境变量,root 密码修改,配置远程连接权限
[root@localhost ~]# echo export PATH=$PATH:/usr/local/mysql/bin >>/etc/profile
[root@localhost ~]# source /etc/profile
[root@localhost ~]# more /data/mysql/mysql3306/data/error.log |grep password
2018-12-28T09:56:30.709446+08:00 1 [Note] A temporary password is generated for root@localhost: K:5+d=MqRqlc
root 用户的临时密码为:K:5+d=MqRqlc

[root@localhost ~]# mysql -S /tmp/mysql3306.sock -p
Enter password:【这里输入上面的临时密码】
(unknown)@localhost [(none)]>set global super_read_only=0; set global read_only=0;
(unknown)@localhost [(none)]>alter user user() identified by ‘root’;
Query OK, 0 rows affected (0.05 sec)

root@localhost [(none)]>
配置远程连接权限 略

正文完
星哥玩云-微信公众号
post-qrcode
 0
星锅
版权声明:本站原创文章,由 星锅 于2022-01-22发表,共计6208字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中