Version:
- CentOS 6.x/7.x/8.x
- Mysql 5.6/5.7
准备
如果需要,先卸载旧版本mysql
rpm -qa |grep mysql |xargs yum remove -y
CentOS6.x
# Mysql 5.6
// 如果需要,先卸载旧版本mysql
rpm -qa |grep mysql |xargs yum remove -y
// 安装
rpm -ivh https://repo.mysql.com/mysql-community-release-el6-5.noarch.rpm
yum install -y mysql-community-client.x86_64 mysql-community-server.x86_64
// 启动配置
service mysqld start
chkconfig mysqld on
mysql_secure_installation
CentOS 7.x
# Mysql 5.6
rpm -Uvh http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm
yum repolist enabled | grep "mysql.*-community.*"
yum install -y mysql-community-server
systemctl enable mysqld
systemctl start mysqld
mysql_secure_installation
# Mysql 5.7
rpm -ivh https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm
rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
yum repolist all | grep mysql | grep enabled
yum -y install mysql-community-server
systemctl enable mysqld
systemctl start mysqld
systemctl status mysqld
cat /var/log/mysqld.log | grep -i 'temporary password'
mysql_secure_installation
CentOS 8.x
# Mysql 5.7
# rpm -ivh https://repo.mysql.com//mysql80-community-release-el8-4.noarch.rpm
rpm -ivh http://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
# rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
yum -y install yum-utils
yum repolist all | grep mysql | grep enabled
yum-config-manager --disable mysql80-community
yum-config-manager --enable mysql57-community
yum -y install mysql-community-server
mysql --version
systemctl enable mysqld
systemctl start mysqld
systemctl status mysqld
cat /var/log/mysqld.log | grep -i 'temporary password'
mysql_secure_installation
一点通用基础配置
vim /etc/my.cnf
# 在[mysqld],[client],[mysql]节点下添加编码设置
[client]
default-character-set=utf8
[mysql]
default-character-set=utf8
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
collation-server = utf8_unicode_ci
init-connect='SET NAMES utf8'
character-set-server = utf8
max_connections=1000
default-storage-engine=INNODB
lower_case_table_names=1
max_allowed_packet=16M
default-time_zone='+8:00'
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
QA
How to Fix “Failed to set locale, defaulting to C.UTF-8” in CentOS 8
dnf install -y langpacks-en glibc-all-langpacks glibc-langpack-en
localectl set-locale LANG=en_US.UTF-8