通过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