下载rpm安装包
Mysql官网:https://dev.mysql.com/downloads/mysql/
选择版本下载:
可以使用wget命令下载:
[root@localhost opt]#wget https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.20-1.el6.x86_64.rpm-bundle.tar |
注意RedHat的版本和系统位数。
查看依赖的库
[root@localhost opt]# yum search libaio[root@localhost opt]# yum install libaio |
查看系统之前是否有安装过mysql相关版本
[root@localhost opt]# rpm -qa | grep mysql[root@localhost opt]# rpm -qa | grep mariadb |
有则删除,有几个删除几个
[root@localhost opt]# rpm -e mariadb-libs-5.5.44-2.el7.x86_64 --nodeps |
安装
按照顺序安装软件包
[root@localhost opt]# rpm -ivh mysql-community-common-5.7.20-1.el6.x86_64.rpm[root@localhost opt]# rpm -ivh mysql-community-libs-5.7.20-1.el6.x86_64.rpm[root@localhost opt]# rpm -ivh mysql-community-client-5.7.20-1.el6.x86_64.rpm[root@localhost opt]# rpm -ivh mysql-community-server-5.7.19-1.el7.x86_64.rpm |
创建mysql用户和用户组
[root@localhost /]# groupadd mysql[root@localhost /]# useradd -r -g mysql -s /bin/false mysql |
创建mysql数据存放目录
[root@localhost /]# mkdir -p /data/mysql[root@localhost /]# chown mysql.mysql /data/mysql[root@localhost /]# ll -d /data/mysql/drwxr-xr-x. 2 mysql mysql 6 9月 17 17:37 /data/mysql/ |
修改/etc/my.cnf配置文件
[mysqld]init-connect='SET NAMES utf8mb4'default-storage-engine=INNODBcharacter-set-server=utf8mb4datadir=/data/mysqlsocket=/var/lib/mysql/mysql.sockassorted security riskssymbolic-links=0log-error=/var/log/mysqld.logpid-file=/var/run/mysqld/mysqld.pidvalidate_password=offsql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTIONlower_case_table_names=1[mysql]default-character-set = utf8mb4[client]default-character-set = utf8mb4 |