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
将其上传到服务器

2. 卸载自带的mariadb
否则安装可能会报冲突:
rpm -qa | grep mariadb

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

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

安装完查看
rpm -qa | grep mysql

4. 启动mysql
# 启动
systemctl start mysqld.service
# 停止:
systemctl stop mysqld.service
# 重启:
systemctl restart mysqld.service
# 开机自启动:
systemctl enable mysqld.service
# 重新加载配置文件:
systemctl daemon-reload

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

登录mysql
mysql -u root -p

开始修改密码
ALTER USER 'root'@'localhost' IDENTIFIED BY '$Root123456';
flush privileges;

这时便可用新密码登录

6. 配置默认编码
当前默认字符编码:
show variables like '%character%';

修改/etc/my.cnf配置文件,在[mysqld]下添加编码配置,如下所示:
character_set_server=utf8
init_connect='SET NAMES utf8'
重启mysql服务:
systemctl restart mysqld.service
查看此时编码

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

浙公网安备 33010602011771号