centos7 rpm 安装mysql5.7

1. 下载需要的rpm

下载地址

https://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql-5.7-community-el7-x86_64/

主要的rpm包如下

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

将其上传到服务器

centos7 rpm 安装mysql5.7_第1张图片

2. 卸载自带的mariadb

否则安装可能会报冲突:

rpm -qa | grep mariadb

yum -y remove mariadb-libs-5.5.65-1.el7.x86_64

centos7 rpm 安装mysql5.7_第2张图片

3. 安装mysql

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

centos7 rpm 安装mysql5.7_第3张图片

安装完查看

rpm -qa | grep mysql

centos7 rpm 安装mysql5.7_第4张图片

4. 启动mysql

# 启动
systemctl start mysqld.service

# 停止:
systemctl stop mysqld.service

# 重启:
systemctl restart mysqld.service

# 开机自启动:
systemctl enable mysqld.service

# 重新加载配置文件:
systemctl daemon-reload

centos7 rpm 安装mysql5.7_第5张图片

5. 修改密码

mysql安装完成之后,在/var/log/mysqld.log文件中给root生成了一个默认密码。通过下面的方式找到root默认密码,然后登录mysql进行修改:

grep 'temporary password' /var/log/mysqld.log

登录mysql

mysql -u root -p

centos7 rpm 安装mysql5.7_第6张图片

开始修改密码

ALTER USER 'root'@'localhost' IDENTIFIED BY '$Root123456';
flush privileges;

centos7 rpm 安装mysql5.7_第7张图片

这时便可用新密码登录
centos7 rpm 安装mysql5.7_第8张图片

6. 配置默认编码

当前默认字符编码:

show variables like '%character%';

centos7 rpm 安装mysql5.7_第9张图片

修改/etc/my.cnf配置文件,在[mysqld]下添加编码配置,如下所示:

character_set_server=utf8
init_connect='SET NAMES utf8'

重启mysql服务:

systemctl restart mysqld.service

查看此时编码

centos7 rpm 安装mysql5.7_第10张图片

7. 相关默认配置文件:

配置文件:/etc/my.cnf 
数据文件:/var/lib/mysql/
日志文件:/var/log/mysqld.log 
服务启动脚本:/usr/lib/systemd/system/mysqld.service
socket文件:/var/run/mysqld/mysqld.pid

参考

centos7.6 rpm包安装mysql5.7.25

你可能感兴趣的:(linux)