赞
踩
1、查看centos7中是否有MariaDB
,MariaDB
与MySQL
关系请自行查阅
rpm -qa | grep mariadb
2、如果有MariaDB
,需要将 步骤1
中查询到的mairadb
全部卸载,否则MySQL
安装会出现问题
rpm -e --nodeps 软件名
3、查看本机是否已经安装过MySQL
rpm -qa | grep -i mysql
4、如果安装过MySQL
,请确定是否有数据需要备份(如果有需要备份的数据请自行查阅相关操作进行备份,否则数据丢失概不负责)
如果没有安装过MySQL
,请跳转步骤6
5、卸载MySQL
rpm -e --nodeps 软件名
find / -name mysql
whereis mysql
将find
命令和whereis
命令查询到的mysql文件全部删除
rm -rf 查询到的mysql路径
删除mysql配置文件
rm /etc/my.cnf
rpm -qa | grep -i mysql
6、MySQL官网下载适用于centos7的mysql安装包
查询服务器是x86_64架构还是arm架构
uname -m
或者是
arch
# 我的服务器是x86_64的
tar
包的链接,然后通过wget
命令下载,操作如下wget 文件的网络地址
比如我这里下载的地址是
wget https://cdn.mysql.com//Downloads/MySQL-8.4/mysql-8.4.0-1.el7.x86_64.rpm-bundle.tarhttps://cdn.mysql.com/archives/mysql-8.0/mysql-8.0.26-1.sl15.x86_64.rpm-bundle.tar
这里的版本号会对应下面的插件依赖版本安装,最好安装一样的版本。
历史版本下载教程:
xftp
工具还是wget
命令,将MySQL的tar
包传到centos的某个目录下(比如home目录下),这里演示的是上传到root
用户的home目录下7、解压tar包
在解压之前,建议先创建一个空的目录,因为这个tar包解压后多个rpm包会直接放到当前目录。因为我的tar包是在root
用户的home目录下,所以直接在这个目录下创建了一个mysql的目录。这个目录无所谓!
mkdir mysql
解压该tar包
tar -xvf mysql的tar包全名 -C 解压到指定目录
# 说明:-C参数,后面跟的是目录,意思是将压缩包解压缩后存放到指定的目录下。# 这里就指定到刚才创建的mysql目录下
8、开始安装MySQL
rpm -ivh xxx.rpm
# 这里选择的是全部安装
# 安装顺序如下,否则会出现依赖问题
mysql-community-common-8.0.26-1.el7.x86_64.rpm
mysql-community-client-plugins-8.0.26-1.el7.x86_64.rpm
mysql-community-embedded-compat-8.0.26-1.el7.x86_64.rpm
mysql-community-libs-8.0.26-1.el7.x86_64.rpm
mysql-community-libs-compat-8.0.26-1.el7.x86_64.rpm
mysql-community-devel-8.0.26-1.el7.x86_64.rpm
mysql-community-client-8.0.26-1.el7.x86_64.rpm
mysql-community-server-8.0.26-1.el7.x86_64.rpm
mysql-community-test-8.0.26-1.el7.x86_64.rpm
- 错误:依赖检测失败:
- perl(Data::Dumper) 被 mysql-community-test-8.0.34-1.el7.x86_64 需要
- perl(JSON) 被 mysql-community-test-8.0.34-1.el7.x86_64 需要
- perl(Test::More) 被 mysql-community-test-8.0.34-1.el7.x86_64 需要
-
- 解决办法:
- yum install net-tools
- yum install -y perl-Module-Install.noarch
- yum install perl-JSON
- yum install perl-Test-Simple -y
情况1:
[root@VM-0-14-centos mysql]# rpm -ivh mysql-community-embedded-compat-8.0.26-1.el7.x86_64.rpm
warning: mysql-community-embedded-compat-8.0.26-1.el7.x86_64.rpm: Header V3 DSA/SHA256 Signature, key ID 5072e1f5: NOKEY
error: Failed dependencies:
libnuma.so.1()(64bit) is needed by mysql-community-embedded-compat-8.0.26-1.el7.x86_64
libnuma.so.1(libnuma_1.1)(64bit) is needed by mysql-community-embedded-compat-8.0.26-1.el7.x86_64
libnuma.so.1(libnuma_1.2)(64bit) is needed by mysql-community-embedded-compat-8.0.26-1.el7.x86_64解决方式:
- yum -y install numactl
情况2
[root@VM-0-14-centos mysql]# rpm -ivh mysql-community-devel-8.0.26-1.el7.x86_64.rpm
warning: mysql-community-devel-8.0.26-1.el7.x86_64.rpm: Header V3 DSA/SHA256 Signature, key ID 5072e1f5: NOKEY
error: Failed dependencies:
pkgconfig(openssl) is needed by mysql-community-devel-8.0.26-1.el7.x86_64解决方式
- yum install openssl-devel
情况3
[root@VM-0-14-centos mysql]# rpm -ivh mysql-community-test-8.0.26-1.el7.x86_64.rpm
warning: mysql-community-test-8.0.26-1.el7.x86_64.rpm: Header V3 DSA/SHA256 Signature, key ID 5072e1f5: NOKEY
error: Failed dependencies:
perl(Data::Dumper) is needed by mysql-community-test-8.0.26-1.el7.x86_64解决方式
- yum -y install autoconf
情况4
[root@VM-0-14-centos mysql]# rpm -ivh mysql-community-test-8.0.26-1.el7.x86_64.rpm
warning: mysql-community-test-8.0.26-1.el7.x86_64.rpm: Header V3 DSA/SHA256 Signature, key ID 5072e1f5: NOKEY
error: Failed dependencies:
perl(JSON) is needed by mysql-community-test-8.0.26-1.el7.x86_64解决方式
- yum install perl-JSON.noarch -y
- yum install perl.x86_64 perl-devel.x86_64 -y
情况5
[root@VM-0-14-centos mysql]# rpm -ivh mysql-community-test-8.0.26-1.el7.x86_64.rpm
warning: mysql-community-test-8.0.26-1.el7.x86_64.rpm: Header V3 DSA/SHA256 Signature, key ID 5072e1f5: NOKEY
error: Failed dependencies:
perl(Test::More) is needed by mysql-community-test-8.0.26-1.el7.x86_64解决方式:
- 到 https://pkgs.org/download/perl(Test::More),打开centos7的下拉框,找到CentOS x86_64下对应的rpm,然后打开这个rpm连接,在
Download
对应的部分找Binary Package
,后面有对应的rpm下载连接,下载下来进行安装即可
9、初始化数据库
mysqld --initialize --console
10、目录授权,否则可能会启动失败
chown -R mysql:mysql /var/lib/mysql/
11、启动mysql
systemctl start mysqld
systemctl stop mysqld
systemctl restart mysqld
12、查询mysql状态
systemctl status mysqld
13、查询mysql的临时密码
cat /var/log/mysqld.log | grep password
14、使用临时密码登录mysql
mysql -u root -p
- mysql> SET GLOBAL validate_password.policy=0;
- mysql> SET GLOBAL validate_password.length=1;
SHOW VARIABLES LIKE ‘validate_password%’;
15、修改mysql的登录密码
alter user ‘root’@‘localhost’ identified with mysql_native_password by '你的密码' ; ALTER USER 'root'@'localhost' IDENTIFIED BY 'Root_12root';(8.4.0用这个命令,上面不可用也可以用这个)
最后重启下mysql即可
16、mysql设置远程连接
注:这个步骤根据实际需求而设定
show databases ;
use mysql ;
查看可登录mysql的host
select host, user from user;
host
部分全部都是localhost
,说明用户只能本地连接msyql服务
root
用户的host
值,并刷新mysql数据库
update user set user.host='%'where user.user='root';
flush privileges;
在我的windows电脑上使用Navicat测试连接服务器上的mysql,看看是否能够远程连接
17、其他情况说明
连接失败的情况
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。