centos7使用yum安装mysql8

1、先删除mariadb

[root@tjtxxh01 devops]# rpm -qa|grep mariadb
mariadb-libs-5.5.65-1.el7.x86_64
[root@tjtxxh01 devops]# rpm -e --nodeps mariadb-libs-5.5.65-1.el7.x86_64
[root@tjtxxh01 devops]# rpm -qa|grep mariadb                            
 

在这里插入图片描述

2、centos的yum 源中默认是没有mysql的,所以我们需要先去官网下载mysql的repo源并安装。

wget https://dev.mysql.com/get/mysql80-community-release-el7-1.noarch.rpm
#本地安装mysql的yum源
yum localinstall mysql80-community-release-el7-1.noarch.rpm
#查看/etc/yum.repos.d/路径下多了mysql文件
ll /etc/yum.repos.d/ |grep mysql
#yum源
yum clean all
yum makecache

在这里插入图片描述

#查看yum中mysql版本
yum repolist all | grep mysql

在这里插入图片描述
3、安装mysql

#安装mysql
yum install mysql-community-server
#启动
systemctl start mysqld.service
#设置开机自启动
systemctl enable mysqld.service
#停止
systemctl stop mysqld.service
#重启
systemctl restart mysqld.service

4、登录mysql
mysql在安装后会创建一个root@locahost账户,并且把初始的密码放到了/var/log/mysqld.log文件中;

cat /var/log/mysqld.log | grep password
# 使用初始密码登录
mysql -uroot -p

5、修改密码

alter user 'root'@'localhost' identified with mysql_native_password BY '12345678';
flush privileges

6、my.cnf配置文件

cd /etc/my.cnf

7、开启远程访问

use mysql;
# 查询能访问的host,默认只能localhost访问
select user,authentication_string,host from user;

在这里插入图片描述

# 修改root用户能够任何IP访问,当然也能制定具体某个IP
update user set host = '%' where user = 'root';
flush privileges;

另外还需要打开服务器防火墙,把mysql端口放开,要不然公网IP也访问不到服务器的mysql端口

# 查询防火墙状态
systemctl status firewalld
# 启动
systemctl start firewalld
# 关闭
systemctl stop firewalld
# 查看已开启端口
firewall-cmd --list-port
# 开启端口
firewall-cmd --zone=public --add-port=3306/tcp --permanent
# 重启
firewall-cmd --reload
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值