二进制包安装
- 路径安排
安装位置:/user/local/mysql57
数据库位置:/data/mysql - 下载安装包
去官网下载安装包,地址:https://dev.mysql.com/downloads/mysql/5.7.html#downloads ,选择如下系统和版本
- 检查是否安装mariadb
[root@localhost ~]# rpm -qa | grep mariadb
mariadb-libs-5.5.56-2.el7.x86_64
[root@localhost ~]# rpm -e --nodeps mariadb-libs-5.5.56-2.el7.x86_64
- 检查是否安装mysql
[root@localhost ~]# rpm -qa | grep mysql
- 创建mysql用户和组
#检查是否存在mysql用户组
[root@localhost ~]# cat /etc/group | grep mysql
[root@localhost ~]#
[root@localhost ~]# cat /etc/passwd| grep mysql
[root@localhost ~]#
#创建mysql用户组
[root@localhost ~]# groupadd mysql
#创建mysql用户并加入mysql用户组
[root@localhost ~]# useradd -r -g mysql mysql #-r参数表示mysql用户是系统用户,不可用于登录
- 解压tar包,更改所属组和用户
[root@localhost local]# cd /usr/local
[root@localhost local]# tar xvf mysql-5.7.23-linux-glibc2.12-x86_64.tar.gz
[root@localhost local]# mv mysql-5.7.23-linux-glibc2.12-x86_64 mysql57
[root@localhost local]# chown -R mysql mysql57/
[root@localhost local]# chgrp -R mysql mysql57/
- 安装和初始化
[root@localhost local]# cd mysql57/
[root@localhost local]# bin/mysqld --initialize --user=mysql --basedir=/home/data/mysql/ --datadir=/home/data/mysql/data/
- 配置文件
注:mysql5.7.21不需要my.cnf文件
[root@localhost support-files]# cd /usr/local/mysql57/support-files/
[root@localhost support-files]# cp mysql.server /etc/init.d/mysqld
[root@localhost support-files]# vi /etc/init.d/mysqld
配置:
basedir=/user/local/mysql57
datadir=/home/data/mysql/data
- 启动
[root@localhost support-files]# /etc/init.d/mysqld restart
[root@localhost support-files]# chkconfig --level 35 mysqld on
#添加环境变量
[root@localhost support-files]# vi /etc/profile
# export PATH=$PATH:/usr/loca/mysql57/bin
[root@localhost support-files]# source /etc/profile
- 登录修改密码
[root@localhost ~]# mysql -u root -p
Enter password:
mysql> set PASSWORD = PASSWORD('root');
# 设置远程登录
mysql> update user set host='%' where user='root';
Query OK, 1 row affected (0.35 sec)
Rows matched: 1 Changed: 1 Warnings: 0