linux版本:Centois7
mysql版本:5.7
一、安装
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包至服务器
3、删除原有的mariadb
先查看一下是否已经安装了,命令:rpm -qa|grep mariadb
删除mariadb,命令:rpm -e --nodeps mariadb-libs
4、解压缩mysql离线安装包
cd /home/soft
tar -xvf mysql-8.0.16-2.el7.x86_64.rpm-bundle.tar
解压缩之后,包含以下rpm包
mysql-community-libs-8.0.16-2.el7.x86_64.rpm mysql-community-embedded-compat-8.0.16-2.el7.x86_64.rpm mysql-community-devel-8.0.16-2.el7.x86_64.rpm mysql-community-server-8.0.16-2.el7.x86_64.rpm mysql-community-libs-compat-8.0.16-2.el7.x86_64.rpm mysql-community-client-8.0.16-2.el7.x86_64.rpm mysql-community-common-8.0.16-2.el7.x86_64.rpm mysql-community-test-8.0.16-2.el7.x86_64.rpm
5、安装rmp包
逐个安装,命令如下:
【必须安装】
rpm -ivh mysql-community-common-8.0.16-2.el7.x86_64.rpm
rpm -ivh mysql-community-libs-8.0.16-2.el7.x86_64.rpm
rpm -ivh mysql-community-client-8.0.16-2.el7.x86_64.rpm
rpm -ivh mysql-community-server-8.0.16-2.el7.x86_64.rpm
【非必须安装】
rpm -ivh mysql-community-libs-compat-8.0.16-2.el7.x86_64.rpm
rpm -ivh mysql-community-embedded-compat-8.0.16-2.el7.x86_64.rpm
rpm -ivh mysql-community-devel-8.0.16-2.el7.x86_64.rpm
rpm -ivh mysql-community-test-8.0.16-2.el7.x86_64.rpm
出现错误1:
warning: mysql-community-devel-8.0.16-2.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
error: Failed dependencies:
pkgconfig(openssl) is needed by mysql-community-devel-8.0.16-2.el7.x86_64
解决办法1:
yum install openssl-devel.x86_64 openssl.x86_64 -y
出现问题2:
warning: mysql-community-test-8.0.16-2.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY error: Failed dependencies: perl(Data::Dumper) is needed by mysql-community-test-8.0.16-2.el7.x86_64 perl(JSON) is needed by mysql-community-test-8.0.16-2.el7.x86_64
解决办法2:
yum install perl.x86_64 perl-devel.x86_64 -y
yum install perl-JSON.noarch -y
yum -y install autoconf
二、服务启停
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;
备注: mysql8 之前的版本中加密规则是mysql_native_password,而在mysql8之后,加密规则是caching_sha2_password。 解决问题方法有两种: 方法1.升级navicat驱动; 方法2.把mysql用户登录密码加密规则还原成mysql_native_password.。 此处我使用的是方法2。
再次从navicat尝试连接mysql,测试成功。