centos7 (Linux 7)安装 mysql 8

本文档详细介绍了在Linux环境下通过wget下载MySQL 8.0的安装包,然后通过rpm命令进行安装,并初始化数据库。过程中可能会遇到libaio库缺失的问题,解决后设置root用户的密码和远程访问权限。最后,提供了修改密码和授权远程连接的SQL语句。
摘要由CSDN通过智能技术生成

通过wget下载安装包

 wget https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-8.0.23-1.el7.x86_64.rpm-bundle.tar

解压

tar -xvf mysql-8.0.23-1.el7.x86_64.rpm-bundle.tar

在这里插入图片描述
依次执行如下命令进行安装

rpm -ivh mysql-community-common-8.0.23-1.el7.x86_64.rpm --nodeps --force
rpm -ivh mysql-community-libs-8.0.23-1.el7.x86_64.rpm --nodeps --force
rpm -ivh mysql-community-server-8.0.23-1.el7.x86_64.rpm --nodeps --force
rpm -ivh mysql-community-client-8.0.23-1.el7.x86_64.rpm --nodeps --force

在这里插入图片描述
执行如下命令初始化数据库:

mysqld --initialize;
chown mysql:mysql /var/lib/mysql -R;
systemctl start mysqld.service;
systemctl  enable mysqld;

可能遇到如下异常
mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory
解决方案:执行如下命令安装 yum install -y libaio
在这里插入图片描述
初始化完成以后会生成一个临时密码
在这里插入图片描述
使用默认生成的密码,登录数据库修改成新密码

mysql -uroot -p

修改本机root账户登录密码

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'root666';

在这里插入图片描述
设置root账户远程访问

mysql> create user 'root'@'%' identified with mysql_native_password by '@root#666888';
Query OK, 0 rows affected (0.02 sec)

mysql> grant all privileges on *.* to 'root'@'%' with grant option;
Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)

mysql> exit;

修改密码, 删除远程用户, 重新创建授权

delete from mysql.user where user = 'root' and host = '%';

参考: https://blog.csdn.net/weixin_42266606/article/details/80879571

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值