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 ...
随机推荐
- ubuntu 18 安装virtulenv以及virtualenvwrapper
转自: https://www.jianshu.com/p/06533f19c4ad 首先安装pip,如果用的python3版本要安装pip3(自行google) sudo apt install v ...
- 项目中java异常处理
一.java异常类介绍. Throwable: 有两个重要的子类:Exception(异常)和 Error(错误),二者都是 Java 异常处理的重要子类,各自都包含大量子类. 有一篇比较好的blog ...
- macOS 设置Root密码
用管理员帐号进入Terminal: 1) 输入:sudo passwd root ,回车: 2) 输入新的root密码: 3) 输入:su : 4) 输入新密码: 这样就进入到root帐号了.
- Codeforces Round #408 (Div. 2) A
Description Zane the wizard had never loved anyone before, until he fell in love with a girl, whose ...
- 记忆化搜索(DFS+DP) URAL 1501 Sense of Beauty
题目传送门 /* 题意:给了两堆牌,每次从首部取出一张牌,按颜色分配到两个新堆,分配过程两新堆的总数差不大于1 记忆化搜索(DFS+DP):我们思考如果我们将连续的两个操作看成一个集体操作,那么这个操 ...
- java中常用到的math方法(Math.PI、Math.random()、Math.abs(double)、Math.floor(double)、Math.ceil(double)、Math.round(double))
public class MathDemo { public static void main(String args[]){ /** * abs求绝对值 */ System.out.println( ...
- nodejs+multiparty 文件上传
通过表单提交上传文件: html代码 <form action="/uploadFile" method="post" enctype=" ...
- 苹果手机通过Safari浏览器访问web方式安装In-House应用
需求背景 公司内部员工使用的iOS客户端应用希望对内开放,不需要发布于AppStore直接能够让内部用户获取,对于Android应用来说这个问题很好解决,直接下发安装包然后就能安装了:但是对于苹果生态 ...
- HttpMessageNotWritableException异常解决办法
昨天做多对多的时遇到这个错误,网上找了一大堆,都没有解决掉,这个异常是说要解析的对象解析不了,就有可能该对象为null了,为了测试,我把数据库的数据都填上去 结果还是报错 看来是时候debug下 ...
- position 位置、表单
一.position 位置 1.只要使用了定位,必须有一个相对的参照物 2.具体定位的那个元素需加position:absolute:(绝对的) 绝对的:就是具体到某一个地方,特别详细的意思 ...