Menu Close

mysql 8.0.30版本安装

— 下载mysql 8.0.30
wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.30-1.el7.x86_64.rpm-bundle.tar
解压缩
tar xvf mysql-8.0.30-1.el7.x86_64.rpm-bundle.tar

删除自带的mariadb

查询是否有mariadb

rpm -qa|grep mariadb

删除mariadb

rpm -e –nodeps mariadb-libs

再次查询mariadb

rpm -qa|grep mariadb

逐个安装到指定目录

rpm -ivh mysql-community-common-8.0.30-1.el7.x86_64.rpm

rpm -ivh mysql-community-client-plugins-8.0.30-1.el7.x86_64.rpm

rpm -ivh mysql-community-libs-8.0.30-1.el7.x86_64.rpm

rpm -ivh mysql-community-client-8.0.30-1.el7.x86_64.rpm

rpm -ivh mysql-community-icu-data-files-8.0.30-1.el7.x86_64.rpm

rpm -ivh mysql-community-server-8.0.30-1.el7.x86_64.rpm

若安装过程中缺少依赖包libaio则使用以下命令
yum -y install libaio

创建用户组及账户密码
groupadd mysql
useradd -g mysql mysql
启动MySql服务
增加权限
chown -R mysql:mysql /var/lib/mysql/
启动mysql
systemctl start mysqld

查看初始密码

cat /var/log/mysqld.log | grep localhost

使用密码登录

mysql -uroot -p

修改密码

alter user ‘root’@’localhost’ identified by ‘Fulu@20231107’;

允许远程主机连接

允许所有主机访问

use mysql;

update user set host = ‘%’ where user = ‘root’;

flush privileges;

GRANT ALL PRIVILEGES ON . TO ‘root’@’%’WITH GRANT OPTION;

FLUSH PRIVILEGES;

远程连接:

mysql -h10.0.10.145 -uroot -pFulu@20231107

远程连接报如下错误(终端mysql版本比较低或认证方式不匹配)

修改加密方式

alter user ‘root’@’%’ identified with mysql_native_password by ‘Fulu@20231107’;

再次远程连接:

-u:指定用户

-p:指定密码

-h:指定主机

-S:指定socker

-P:指定端口

-A:备份所有库,全备

~]# mysqldump -uroot -pFulu@20231107 -A > /tmp/full.sql

mysqldump在备份和恢复时都需要MySQL实例启动为前提

库内恢复操作
mysql> source /backup/full.sql
库外恢复操作
[root@db01 ~]# mysql -uroot -p123 < /backup/full.sql

补充 注意:
mysql> select host,user from mysql.user;
mysql> create user ‘root’@’%’ identified by ‘Fulu@20230511’;
mysql> alter user ‘root’@’%’ identified with mysql_native_password by ‘Fulu@20230511’;