CentOS安装MySQL8或5.7

10 篇文章 0 订阅

MySQL8

  1. 安装mysql
sudo dnf install @mysql
  1. 开机自启
sudo systemctl enable --now mysqld
  1. 查看状态
sudo systemctl status mysqld
  1. root账户密码设置
    (/var/log/mysqld.log查看初始密码)

查看mysql初始密码

grep 'temporary password' /var/log/mysqld.log
sudo mysql_secure_installation
  1. root登录设置可远程连接
mysql -u root -p
use mysql
update user set host = '%' where user = 'root';
flush privileges;
quit
  1. 重启mysql
sudo systemctl restart mysqld
  1. 如果远程不可连接,去阿里云ECS设置安全组,开放3306。
  2. 查看MySQL的配置文件位置
 mysqld --verbose --help|grep -A 1 'Default options'

MySQL5.7

  1. 查看卸载原有的mysql
    rpm -qa |grep mysql
    在这里插入图片描述
    逐一卸载:rpm -e mysql-community-server-5.7.30-1.el7.x86_64等等
  2. 查看有没有wget的,没有则先安装wget
yum install wget
  1. 下载mysql的rpm
wget http://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
  1. 安装mysql的rpm
rpm -ivh mysql80-community-release-el7-3.noarch.rpm

这时候会在 /etc/yum.repos.d/目录下生成两个文件
mysql-community.repo和mysql-community-source.repo
修改repo文件(安装5.7,不要8.0)

cd /etc/yum.repos.d/
vim mysql-community.repo

将 [mysql57-community] 下的 enabled 设置为1,表示打开5.7
将 [mysql80-community] 下的 enabled 设置为0,表示关闭8.0
安装mysql

yum -y install mysql-community-server

查看版本

mysql --version

启动并查看状态

systemctl start mysqld.service
systemctl status mysqld.service

问题解决:

1、出现Error: Unable to find a match: mysql-community-server
执行:

yum module disable mysql
yum -y install mysql-community-server

2、出现 Error: GPG check FAILED问题
yum install mysql-community-server --nogpgcheck
或者
rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022

3、Error: Transaction test error:
file /etc/my.cnf from install of mysql-community-server-5.7.40-1.el7.x86_64 conflicts with file from package mariadb-connector-c-config-3.1.11-2.el8_3.noarch
解决: rpm -qa | grep mariadb
删除xxrpm -ev --nodeps xxxxx
4、
You must reset your password using ALTER USER statement before executing this statement.
修改密码:
ALTER USER USER() IDENTIFIED BY ‘password’;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值