Linux centos 7安装 MySQL5.7


参考 https://blog.csdn.net/qq_35526165/article/details/103157274

1. 下载rpm文件

wget https://repo.mysql.com//mysql57-community-release-el7-11.noarch.rpm

截图:
在这里插入图片描述

2. 安装rpm

rpm -ivh mysql57-community-release-el7-11.noarch.rpm

截图:
在这里插入图片描述

需要确认的时候请按y,安装完成后在/etc/yum.repos.d目录将新增mysql-community.repo和mysql-community-source.repo

3. 安装mysql

yum install mysql-community-server

截图:
在这里插入图片描述

4. 启动MySQL服务

systemctl start mysqld

截图:
在这里插入图片描述

5. 设置mysql开机启动

systemctl enable mysqld
systemctl daemon-reload

截图:
在这里插入图片描述

6. 查找root密码

mysql安装完成之后,在/var/log/mysqld.log文件中为root用户生成默认密码。

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

截图:
在这里插入图片描述

7. 登录mysql

mysql -u root -p 默认密码

截图:
在这里插入图片描述

8. 修改登录密码

set password for 'root'@'localhost'=password('新密码');

截图:
在这里插入图片描述
补充:
密码的格式【大小写字母+数字+特殊符号】

9. 修改配置文件

vi /etc/my.cnf

配置修改如下:
[mysqld]
character_set_server=utf8
init_connect=’SET NAMES utf8’

截图:
在这里插入图片描述

10. 重启mysql

systemctl restart mysqld

截图:
在这里插入图片描述

11. 开启远程访问

授权

按顺序执行如下代码

create user 'root'@'%' identified with mysql_native_password by '远程访问的密码';
grant all privileges on *.* to 'root'@'%' with grant option;
flush privileges;

截图:
在这里插入图片描述

开放端口

退出MySQL后,依次输入下列三行代码

firewall-cmd --zone=public --add-port=3306/tcp --permanent
systemctl restart firewalld.service
firewall-cmd --reload

截图:
在这里插入图片描述

12. 测试连接

连接成功

截图:
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值