在CentOS7上使用yum安装MySQL 5.7
2017-05-08
最近在准备团队新的开发环境,首先从配置管理做起,配置管理服务器只有一台,配置如下:
1DELL R430机架服务器
2CPU: e5-2603V4 8核
3MEM: 32G
4DISK: 2TB, raid1
团队DevOps流程所需要的多种系统都需要使用MySQL数据库,因此现在这里简单安装一个MySQL,做一下准备工作。
环境 #
- CentOS 7.3 192.168.61.100
disable selinux
1setenforce 0
2
3vi /etc/selinux/config
4SELINUX=disabled
yum安装MySQL #
安装mysql yum repository
1wget https://repo.mysql.com//mysql57-community-release-el7-11.noarch.rpm
2
3yum localinstall mysql57-community-release-el7-11.noarch.rpm
确认yum repository已经安装
1yum repolist enabled | grep "mysql.*-community.*"
2mysql-connectors-community/x86_64 MySQL Connectors Community 36
3mysql-tools-community/x86_64 MySQL Tools Community 47
4mysql57-community/x86_64 MySQL 5.7 Community Server 187
查看MySQL版本:
1yum repolist all | grep mysql
2mysql-cluster-7.5-community/x86_64 MySQL Cluster 7.5 Community disabled
3mysql-cluster-7.5-community-source MySQL Cluster 7.5 Community - disabled
4mysql-cluster-7.6-community/x86_64 MySQL Cluster 7.6 Community disabled
5mysql-cluster-7.6-community-source MySQL Cluster 7.6 Community - disabled
6mysql-connectors-community/x86_64 MySQL Connectors Community enabled: 36
7mysql-connectors-community-source MySQL Connectors Community - S disabled
8mysql-tools-community/x86_64 MySQL Tools Community enabled: 47
9mysql-tools-community-source MySQL Tools Community - Source disabled
10mysql-tools-preview/x86_64 MySQL Tools Preview disabled
11mysql-tools-preview-source MySQL Tools Preview - Source disabled
12mysql55-community/x86_64 MySQL 5.5 Community Server disabled
13mysql55-community-source MySQL 5.5 Community Server - S disabled
14mysql56-community/x86_64 MySQL 5.6 Community Server disabled
15mysql56-community-source MySQL 5.6 Community Server - S disabled
16mysql57-community/x86_64 MySQL 5.7 Community Server enabled: 187
17mysql57-community-source MySQL 5.7 Community Server - S disabled
18mysql80-community/x86_64 MySQL 8.0 Community Server disabled
19mysql80-community-source MySQL 8.0 Community Server - S disabled
安装:
1yum install mysql-community-server
启动和配置MySQL服务 #
修改MySQL配置文件/etc/my.cnf
1datadir=/home/mysql
2
3server_id = 1
4character-set-server=utf8mb4
5collation-server=utf8mb4_unicode_ci
6default-storage-engine=INNODB
7#Optimize omit
8sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
9log-bin = binlog
10log_bin_trust_function_creators=1
11binlog_format = ROW
12expire_logs_days = 99
13sync_binlog = 0
14slow-query-log=1
15slow-query-log-file=/var/log/mysql/slow-queries.log
16long_query_time = 3
17log-queries-not-using-indexes
18explicit_defaults_for_timestamp = 1
启动MySQL服务:
1systemctl start mysqld
2systemctl status mysqld
查看生成mysql root用户临时密码:
1grep 'temporary password' /var/log/mysqld.log
修改root用户的密码:
1mysql -uroot -p
2ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass4!';