Centos 7离线安装MySql8
linux版本:Centos 7
mysql版本:mysql-8
一、安装
1、下载mysql离线安装包
下载地址:https://dev.mysql.com/downloads/mysql/
选择如下:
【Red Hat Enterprise Linux 7 / Oracle Linux】
【Red Hat Enterprise Linux 7 / Oracle Linux 7 (x86, 64-bit)】
2、上传tar包至服务器
- 在服务器home目录下创建一个mysql目录
cd ..
cd home
mkdir mysql
- 上传tar包到mysql目录
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-8hVFZMiE-1648180679224)(C:\Users\15005\AppData\Roaming\Typora\typora-user-images\image-20220323115754094.png)]
3、删除原有的mariadb
先查看一下是否已经安装了,命令:
rpm -qa|grep mariadb
删除mariadb,命令:
rpm -e --nodeps mariadb-libs
4、解压缩mysql离线安装包
cd/home/mysql
tar -xvf mysql-8.0.28-1.el7.x86_64.rpm-bundle.tar
解压缩之后,包含以下rpm包
mysql-8.0.28-1.el7.x86_64.rpm-bundle.tar
mysql-community-icu-data-files-8.0.28-1.el7.x86_64.rpm
mysql-community-client-8.0.28-1.el7.x86_64.rpm
mysql-community-libs-8.0.28-1.el7.x86_64.rpm
mysql-community-client-plugins-8.0.28-1.el7.x86_64.rpm
mysql-community-libs-compat-8.0.28-1.el7.x86_64.rpm
mysql-community-common-8.0.28-1.el7.x86_64.rpm
mysql-community-server-8.0.28-1.el7.x86_64.rpm
mysql-community-devel-8.0.28-1.el7.x86_64.rpm
mysql-community-test-8.0.28-1.el7.x86_64.rpm
mysql-community-embedded-compat-8.0.28-1.el7.x86_64.rpm
5、安装rmp包
逐个安装,命令如下:
rpm -ivh mysql-community-common-8.0.28-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-8.0.28-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-8.0.28-1.el7.x86_64.rpm
rpm -ivh mysql-community-server-8.0.28-1.el7.x86_64.rpm
关于报错:
-
出现安装依赖关系,报错后,先安装依赖,再重复执行就可以了
-
linux安装mysql时报的错,这句话意思是需要 net-tools
net-tools is needed by mysql-community-server-5.7.21-1.el7.x86_64
执行安装net-tools:
yum -y install net-tools
二、服务启停
1、查看服务状态
命令:systemctl status mysqld
2、停止服务
命令:service mysqld stop
3、初始化数据库
命令:mysqld --initialize --console
4、目录授权
命令:chown -R mysql:mysql /var/lib/mysql/
5、启动mysql服务
命令:systemctl start mysqld
命令:systemctl status mysqld
三、数据库操作
1、查看临时密码:
命令:cat /var/log/mysqld.log
2、用临时密码登录数据库
命令:mysql -u root -p 回车键
然后输入临时密码(输入时不会显示出来,输入完直接回车)
3、修改mysql密码
命令:alter USER ‘root’@‘localhost’ IDENTIFIED BY ‘123456’;
4、授权远程连接
命令:show databases;
命令:use mysql;
命令:select host, user, authentication_string, plugin from user;
命令:update user set host = “%” where user=‘root’;
命令:select host, user, authentication_string, plugin from user;
命令:flush privileges;
尝试使用navacat远程连接,会出现如下错误
2059 - Authenticationplugin‘caching_sha2_password’ cannot be loaded:XXXXX
解决办法:
命令:mysql -u root -p(回车后,输入更改后的密码123456)
命令:use mysql;
命令:alter USER ‘root’@‘%’ IDENTIFIED WITH mysql_native_password BY ‘123456’;
命令:flush privileges;
再次从navicat尝试连接mysql,测试成功。