Installing MySQL 5.7.23 on CentOS 7
Installing MySQL 5.7.23 on CentOS 7
1. 安装前检查
1.1 检查NUMA是否开启
NUMA为什么要咋MySQL中禁用?
MySQL是单进程多线程架构数据库,当numa采用默认内存分配策略时,MySQL进程会被并且仅仅会被分配到numa的一个节点上去。假设这个节点的本地内存为10GB,而MySQL配置20GB内存,超出节点本地内存部分(20GB-10GB)Linux会使用swap而不是使用其他节点的物理内存。在这种情况下,能观察到虽然系统总的可用内存还未用完,但是MySQL进程已经开始在使用swap了。如果单机只运行一个MySQL实例,可以选择关闭numa.检查NUMA
Redhat或者Centos系统中可以通过命令判断bios层是否开启numa
# grep -i numa /var/log/dmesg 如果输出结果为: No NUMA configuration found
关闭nuam方法
修改/etc/default/grub文件,在kernel那行追加numa=off;
# vi /etc/default/grub GRUB_TIMEOUT=5
GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)"
GRUB_DEFAULT=saved
GRUB_DISABLE_SUBMENU=true
GRUB_TERMINAL_OUTPUT="console"
GRUB_CMDLINE_LINUX="crashkernel=auto rd.lvm.lv=centos/root rd.lvm.lv=centos/swap rhgb quiet numa=off"
GRUB_DISABLE_RECOVERY="true"
请注意,在RHEL 7或CentOS 7上,必须重建grub配置才能使更改生效
grub2-mkconfig -o /etc/grub2.cfg
1.2 限制/etc/security/limits.conf文件
mysql hard nproc 65535
mysql soft nproc 65535
mysql hard nofile 65535
mysql soft nofile 65535
或者
* hard nproc 65535
* soft nproc 65535
* hard nofile 65535
* soft nofile 65535
* 代表所有用户
1.3 swap设置
修改/etc/sysctl.conf 文件,根据以下策略增加对应的命令:
查看当前swap设置
# sysctl -a|grep swap
vm.swappiness = 30
1.4 禁用selinux
把SELINUX值修改成disabled,以禁用selinux
# vi /etc/sysconfig/selinux
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of three two values:
# targeted - Targeted processes are protected,
# minimum - Modification of targeted policy. Only selected processes are protected.
# mls - Multi Level Security protection.
SELINUXTYPE=targeted
1.5 安装libaio 库
MySQL依赖于libaio 库。如果未在本地安装此库,则数据目录初始化和后续服务器启动步骤将失败。
# yum search all libaio
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
======================================================================= Matched: libaio ========================================================================
libaio.x86_64 : Linux-native asynchronous I/O access library
libaio-devel.x86_64 : Development files for Linux-native asynchronous I/O access
如果未安装,用如下命令:
# yum install libaio
1.6 关闭防火墙(可选)
//临时关闭
systemctl stop firewalld
//禁止开机启动
systemctl disable firewalld
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
2. 安装MySQL
2.1 创建mysql用户和组
创建用户mysql,指定home目录/usr/local/mysql ,并且是不能登陆,-M代表不创建home目录
# groupadd mysql
# useradd -M -g mysql -s /sbin/nologin -d /usr/local/mysql mysql
2.2 解压mysql二进制包
# cd /opt
# tar -xvf mysql-5.7.23-linux-glibc2.12-x86_64.tar
# ls -l
total 1703176
drwxr-xr-x 2 root root 6 Jul 31 15:02 mysql
-rw-r--r--. 1 root root 673873920 Jul 31 11:23 mysql-5.7.23-linux-glibc2.12-x86_64.tar
-rw-r--r-- 1 7161 31415 644399365 Jun 8 19:10 mysql-5.7.23-linux-glibc2.12-x86_64.tar.gz
-rw-r--r--. 1 root root 396308480 Jul 31 11:23 mysql-8.0.12-linux-glibc2.12-x86_64.tar
-rw-r--r-- 1 7161 31415 29463116 Jun 8 19:08 mysql-test-5.7.23-linux-glibc2.12-x86_64.tar.gz
drwxr-xr-x. 2 root root 6 Sep 7 2017 rh
drwxr-xr-x. 9 root root 147 Jul 31 10:55 VBoxGuestAdditions-5.2.16
# mkdir mysql
# tar -zxvf /opt/mysql-5.7.23-linux-glibc2.12-x86_64.tar.gz
2.3 创建软连接
ln命令创建指向安装目录的符号链接,这样可以访问/usr/local/mysql
# cd /usr/local
# ln -s /opt/mysql/mysql-5.7.23-linux-glibc2.12-x86_64 mysql
为了避免在使用MySQL时必须键入客户端程序的路径名,可以将/usr/local/mysql/bin目录添加到PATH变量中:
# echo "export PATH=$PATH:/usr/local/mysql/bin" >> /etc/profile
# source /etc/profile
3. 安装后配置
3.1 创建基本目录
# mkdir /data/mysql
# mkdir /data/mysql/mysql3306
# cd /data/mysql/mysql3306/
# mkdir {data,logs,tmp}
# chown -R mysql:mysql /data/mysql/mysql3306
3.1 创建/etc/my.cnf文件
[client]
port = 3306
socket = /tmp/mysql3306.sock
[mysql]
prompt="\\u@\\h [\\d]>"
no-auto-rehash
[mysqld]
user = mysql
port = 3306
basedir = /usr/local/mysql
datadir = /data/mysql/mysql3306/data
tmpdir = /data/mysql/mysql3306/tmp
socket = /tmp/mysql3306.sock
pid-file = mysqldb1.pid
character-set-server = utf8mb4
skip_name_resolve = 1
open_files_limit = 65535
back_log = 1024
max_connections = 512
max_connect_errors = 1000000
table_open_cache = 1024
table_definition_cache = 1024
table_open_cache_instances = 64
thread_stack = 512K
external-locking = FALSE
max_allowed_packet = 32M
sort_buffer_size = 4M
join_buffer_size = 4M
thread_cache_size = 768
interactive_timeout = 600
wait_timeout = 600
tmp_table_size = 32M
max_heap_table_size = 32M
slow_query_log = 1
slow_query_log_file = /data/mysql/mysql3306/slow.log
log-error = /data/mysql/mysql3306/error.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
server-id = 1003306
log-bin = /data/mysql/mysql3306/logs/my3306_binlog
sync_binlog = 1
binlog_cache_size = 4M
max_binlog_cache_size = 2G
max_binlog_size = 1G
expire_logs_days = 7
master_info_repository = TABLE
relay_log_info_repository = TABLE
gtid_mode = on
enforce_gtid_consistency = 1
log_slave_updates
binlog_format = row
binlog_checksum = 1
relay_log_recovery = 1
relay-log-purge = 1
key_buffer_size = 32M
read_buffer_size = 8M
read_rnd_buffer_size = 4M
bulk_insert_buffer_size = 64M
myisam_sort_buffer_size = 128M
myisam_max_sort_file_size = 10G
myisam_repair_threads = 1
lock_wait_timeout = 3600
explicit_defaults_for_timestamp = 1
innodb_thread_concurrency = 0
innodb_sync_spin_loops = 100
innodb_spin_wait_delay = 30
transaction_isolation = REPEATABLE-READ
#innodb_additional_mem_pool_size = 16M
innodb_buffer_pool_size = 2867M
innodb_buffer_pool_instances = 8
innodb_buffer_pool_load_at_startup = 1
innodb_buffer_pool_dump_at_shutdown = 1
innodb_data_file_path = ibdata1: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_undo_directory = undolog
innodb_undo_tablespaces = 95
# 根据您的服务器IOPS能力适当调整
# 一般配普通SSD盘的话,可以调整到 10000 - 20000
# 配置高端PCIe SSD卡的话,则可以调整的更高,比如 50000 - 80000
innodb_io_capacity = 4000
innodb_io_capacity_max = 8000
innodb_flush_neighbors = 0
innodb_write_io_threads = 8
innodb_read_io_threads = 8
innodb_purge_threads = 4
innodb_page_cleaners = 4
innodb_open_files = 65535
innodb_max_dirty_pages_pct = 50
innodb_flush_method = O_DIRECT
innodb_lru_scan_depth = 4000
innodb_checksum_algorithm = crc32
innodb_lock_wait_timeout = 10
innodb_rollback_on_timeout = 1
innodb_print_all_deadlocks = 1
innodb_file_per_table = 1
innodb_online_alter_log_max_size = 4G
internal_tmp_disk_storage_engine = InnoDB
innodb_stats_on_metadata = 0
# some var for MySQL 5.7
innodb_checksums = 1
#innodb_file_format = Barracuda
#innodb_file_format_max = Barracuda
query_cache_size = 0
query_cache_type = 0
innodb_undo_logs = 128
innodb_status_file = 1
# 注意: 开启 innodb_status_output & innodb_status_output_locks 后, 可能会导致log-error文件增长较快
innodb_status_output = 0
innodb_status_output_locks = 0
#performance_schema
performance_schema = 1
performance_schema_instrument = '%=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"
[mysqldump]
quick
max_allowed_packet = 32M
3.2 初始化MySQL
# /usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf --initialize
3.3 查看临时密码
# cat error.log|grep password
2018-07-31T08:44:09.458906Z 1 [Note] A temporary password is generated for root@localhost: 0;u+it(H.mYL
3.4 创建启动脚本
# cd /usr/local/mysql/
# cp support-files/mysql.server /etc/init.d/mysql
3.5 启动和关闭
/etc/init.d/mysql start | stop | restart
3.6 以临时密码登陆mysql客户端
# /usr/local/mysql/bin/mysql -S /tmp/mysql3306.sock -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.23-log
Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
(unknown)@localhost [(none)]>show databases;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
3.7 更改密码
(unknown)@localhost [(none)]>alter user user() identified by 'mysql';
Query OK, 0 rows affected (0.01 sec)
root@localhost [(none)]>show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
| undolog |
+--------------------+
5 rows in set (0.00 sec)
4. mysql启动的一些方法
- 系统自启
/etc/init.d/mysql start | stop | restart
手工方式启动
#mysqld 启动 # /usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf & #mysqld_safe启动 # /usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf &
Installing MySQL 5.7.23 on CentOS 7的更多相关文章
- centos 7 安装MySQL 5.7.23
centos 7 安装MySQL 5.7.23 1. 上传MySQL安装包到服务器 mysql-5.7.23-linux-glibc2.5-x86_64.tar.gz 2. 解压MySQL安装 ...
- installing mysql,this may take a few minutes,hold on plz wdcp卡住解决办法
centos6安装wdcp时make in progress卡住的解决办法 今天在一台centos6的vps上安装wdcp出现的这个问题,到安装程序滚动至下面这里时出现"卡死". ...
- Installation and Configuration MySQL Cluster 7.2 on CentOS 5 (include MySQL 5.5)
Architecture Manager Node mysql-mag1 192.168.1.31 mysql-mag2 192.168.1.32 SQL Node mysql-sql1 ...
- Ubuntu下安装MySQL 5.6.23
Ubuntu下安装MySQL 5.6.23 1.下载相应Linux-generic的源代码包.解压,将解压后的文件夹重命名为mysql.移动到/usr/local文件夹下: tar –xzf mysq ...
- linux mysql无故无法启动了,centos 7
转自: http://support.moonpoint.com/software/database/mysql/not-running-centos7.php 下面简单翻译一下. 详细内容可以阅读英 ...
- [MySQL Reference Manual] 23 Performance Schema结构
23 MySQL Performance Schema 23 MySQL Performance Schema 23.1 性能框架快速启动 23.2 性能框架配置 23.2.1 性能框架编译时配置 2 ...
- Installing MySQL Server
Installing MySQL Server Here we will learn how to Compile and Install the MySQL Server from source c ...
- Linux 笔记 #02# Installing MySQL & Installing the Default JRE/JDK
Environment: debian 8 Installing MySQL Reference material: https://linode.com/docs/databases/mysql/h ...
- MYSQL设置远程账户登陆总结,mysql修改、找回密码、增加新用户,MySQL数据库的23个注意事项
1.5 设置及修改Mysql root用户密码1 设置密码方法mysqladmin -u root password '123456'mysqladmin -u root -p'123456' pas ...
随机推荐
- bzoj1725: [Usaco2006 Nov]Corn Fields牧场的安排(状压dfs)
1725: [Usaco2006 Nov]Corn Fields牧场的安排 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 1122 Solved: 80 ...
- 语句 if
1.if语句单项分支 #单项分支 if 55 < 133: print('这个比较运算是正确的') #输出结果:这个比较运算是正确的 2.if语句双项分支 #双项分支 if 55 > 14 ...
- Codeforces 669D Little Artem and Dance (胡搞 + 脑洞)
题目链接: Codeforces 669D Little Artem and Dance 题目描述: 给一个从1到n的连续序列,有两种操作: 1:序列整体向后移动x个位置, 2:序列中相邻的奇偶位置互 ...
- 134 Gas Station 加油站
在一条环路上有 N 个加油站,其中第 i 个加油站有汽油gas[i].你有一辆油箱容量无限的的汽车,从第 i 个加油站前往第 i+1 个加油站需要消耗汽油 cost[i].你从其中一个加油站出发,开始 ...
- Suricata的规则解读(默认和自定义)
不多说,直接上干货! 见suricata官网 https://suricata.readthedocs.io/en/latest/rules/index.html 一.Suricata的规则所放位置 ...
- java 替换字符串模板(模板渲染)
java渲染字符串模板,也就是说在java字符串模板中设置变量字符串,使用变量去渲染指定模板中设置好的变量字符串.下面介绍4种替换模板方式: 1.使用内置String.format String me ...
- VS配置本地IIS以域名访问
1.IIS下配置自己的网站,添加主机名 2.修改hosts文件(C://Windows/System32/drivers/etc) 3.VS中配置项目Web服务器(选择外部主机)
- OpenGL 透视投影推导图解
有它足够了,转载自:http://blog.sina.com.cn/s/blog_73428e9a0102v920.html
- java中同步(synchronized)详解
一.开山篇: 1.synchronized的使用 一个程序中,如果该类中的代码可能运行于多线程环境下,那么就要考虑同步的问题.在Java中内置了语言级的同步原语--synchronized,这也大大简 ...
- HashMap详解 基于jdk1.7
转载自:http://zhangshixi.iteye.com/blog/672697 1. HashMap概述: HashMap是基于哈希表的Map接口的非同步实现.此实现提供所有可选的映射操 ...