xv进入官网:https://www.mysql.com/
点击上方tab download按钮
拖动至页面底部,找到社区版本(免费),点击进入
选择MySQL Community Server
在归档Archives中找到redhat
复制下载链接地址,在centos合适目录下使用wget下载
wget https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.36-1.el7.x86_64.rpm-bundle.tar
解压tar
tar -xvf mysql-5.7.36-1.el7.x86_64.rpm-bundle.tar
检验系统是否包含mariadb-lib,如果有需要卸载,否则mysql 无法安装
rpm -qa | grep mariadb
rpm -e --nodeps mariadb-libs-5.5.68-1.el7.x86_64
依次执行下面命令
rpm -ivh mysql-community-common-5.7.36-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-5.7.36-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-5.7.36-1.el7.x86_64.rpm
rpm -ivh mysql-community-server-5.7.36-1.el7.x86_64.rpm
mysql-community-libs mysql依赖lib,mysql-community-client client是DBMS面向用户,mysql-community-server mysql数据库系统,如果安装mysql-community-server 提示缺少perl,使用yum install perl 即可,中途安装提示缺少文件,按照要求使用yum 安装即可
进入mysql配置文件 my.cnf,添加 skip-grant-table命令,先跳过密码校验,因为root初始密码是随机的,需要去log 查找比较麻烦
vim /etc/my.cnf
启动mysql,进入mysqlclient
systemctl start mysqld.service
mysql
修改ROOT密码,刷新
update mysql.user set authentication_string=password('123456') where user = 'root';
flush privileges;
停止mysql,修改my.cnf,将之前加入 skip-grant-table 去除,重启服务
systemctl stop mysqld.service
使用密码登录
mysql -uroot -p123456
开放远程连接命令
grant all privileges on *.* to 'root'@'%' identified by '123456' with grant option;
提示:You must reset your password using ALTER USER statement before
executing this statement.解决方法,进入mysql XXXXXX 是你的密码
alter user user() identified by “XXXXXX”;
使用navicat 连接不了mysql,需要开启防火墙
firewall-cmd --zone=public --add-port=3306/tcp --permanent