「MySQL」- 安装 | 升级

问题描述

这原本应该很简单,执行apt-get install mysql-server命令就可以了。但是,实际情况可能会复杂一些:
1)我们目前使用的发行版是 Debian 8,源里只有 MySQL-5.5;
2)但系统中已安装的某些包依赖于 MySQL 5.5(比如 mailutils),这就导致在系统中已安装某些 MySQL 相关包的文件(比如 /etc/mysql 配置 );
3)如果直接使用源码编译或安装已编译的二进制包,由于上面提到的已经存在的配置文件会导致 MySQL 的配置和管理变得混乱。我们可能还要在配置文件里覆盖发行版的 MySQL 的配置;

针对上面的这些原因,我们决定还是想办法从发行版的源里安装 MySQL 5.7,而不再使用源码去自己编译,也不使用预编译的二进制包;

硬件要求

MySQL 5.7 Minimum Server Requirements
How do you determine the hardware needed for a server?

Oracle doesn’t publish such specs because it depends so much on how the server will be used, and on the OS.

See MySQL Memory Allocation for some pointers.

You could probably get by with 512MB or less, but I would not want to.

One core is usually adequate. — MySQL won’t use more than one core per connection, so having multiple cores is not needed until you have a lot of traffic.

MySQL has done just fine with simple spinning disks; RAID and/or SSDs are nice, but not a requirement.

However, if you are going with less than 4GB of RAM, you will need to crank down the tunables. Swapping is really bad for performance.

版本选择

通常由需求方决定,我们则是根据需求进行部署。

服务部署

数据库配置 | Configuration

该笔记将记录:与 MySQL 配置相关的内容,及相关问题的解决办法;

配置文件的位置:

#!/bin/sh

mysql --help | grep -A 1 'Default options'
# 输出:
# Default options are read from the following files in the given order:
# /etc/my.cnf /etc/mysql/my.cnf /usr/local/mysql/etc/my.cnf ~/.my.cnf

# 如上,/etc/my.cnf /etc/mysql/my.cnf /usr/local/mysql/etc/my.cnf ~/.my.cnf 是配置文件的位置;

WIP MySQL,动态修改配置,并持久保存,无重启;

针对配置优化

当正确把 MySQL 的基本项配置之后,剩下的主要精力要放在查询、索引等方面的优化;
不要配置当作救命稻草。有些特殊配置确实可以显著提升性能,但是这些配置不能作为基本配置;
如果我们不懂,就不会去配置,更不会到网上搜索配置来直接使用;

其他内容

Setting up MySQL Replication Clusters in Kubernetes
– 参考一下就可以了,应该还有其他更好的实践;