CentOS7安装MySQL5.7

一、检查系统中老版本mysql组件

1.检查老版本

rpm -qa | grep mysql

或

yum list installed | grep mysql

2.卸载老版本

yum -y remove mysql-libs.x86_64

二、下载安装yum源

1.下载需要安装mysql版本yum源

wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.28-1.el7.x86_64.rpm-bundle.tar

2.安装已下载的yum源

rpm -qa|grep mysql
yum remove mysql-libs

yum install -y libaio
yum install -y net-tools
yum install -y perl

解压 bundle.tar

tar -xf mysql-5.7.28-1.el7.x86_64.rpm-bundle.tar

依次安装:

rpm -ivh mysql-community-common-5.7.28-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-5.7.28-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-5.7.28-1.el7.x86_64.rpm
rpm -ivh mysql-community-server-5.7.28-1.el7.x86_64.rpm

顺序不能乱

三、安装mysql

1.初始化mysql数据库

mysqld --initialize --user=mysql

2.在mysql日志中,查看初始化密码

vi /var/log/mysqld.log

3.使用初始化密码登录mysql后,修改密码

ALTER USER 'root'@'localhost' IDENTIFIED BY 'new_password';

CREATE USER 'root'@'%' IDENTIFIED BY 'your_password';
GRANT ALL PRIVILEGES ON `root`.* to 'root'@'%';
FLUSH PRIVILEGES;

四、配置和启动mysql

1.初始化mysql用户密码,修改/etc/my.cnf配置文件,禁用权限校验

vi /etc/my.cnf

[mysqld]
skip-grant-tables

2.修改mysql字符集

vi /etc/my.cnf

[client]
default-character-set=utf8

[mysqld]
character_set_server=utf8

3.启动mysql服务

systemctl start mysqld.service

#检查mysql服务运行状态
systemctl status mysqld.service

4.修改mysql密码

mysql

use mysql;
update mysql.user set authentication_string=password('你的新密码') where user='root';
flush privileges;

quit

5.将skip-grant-tables从my.cnf中去掉,并重启mysql服务

systemctl restart mysqld.service

mysqladmin -u用户名 -p旧密码 password

6.开放root远程登陆权限

use mysql;
update user set host = '%' where user ='root';
flush privileges;

quit

7.打开CentOS7中mysql端口,默认3306 

重启mysql服务,完成安装!

你可能感兴趣的:(CentOS7安装MySQL5.7)