Centos7,安装MYSQL8,也可以安装MYSQL9,不过要选择对下载的MYSQL版本
cat /etc/os-release
如果机器曾经安装过mysql
这个问题是因为mariadb被安装的原因,要卸载掉,下面的命令查询安装的mysql历史版本和残留文件。
rpm -qa | grep -E 'mysql|mariadb'
查到的东西挨个卸载掉
rpm -e mariadb-libs-5.5.68-1.el7.x86_64
一、打开下载地址
https://dev.mysql.com/downloads/
centos 下载redhat的那个版本根据服务器架构选择X86
下载 mysql-9.0.1-1.el9.x86_64.rpm-bundle.tar
要这个带bundle的版本,否则缺一堆文件
解压缩
tar -xvf mysql-9.0.1-1.el9.x86_64.rpm-bundle.tar
mysql-community-client-9.0.1-1.el7.x86_64.rpm
mysql-community-client-plugins-9.0.1-1.el7.x86_64.rpm
mysql-community-common-9.0.1-1.el7.x86_64.rpm
mysql-community-debuginfo-9.0.1-1.el7.x86_64.rpm
mysql-community-devel-9.0.1-1.el7.x86_64.rpm
mysql-community-embedded-compat-9.0.1-1.el7.x86_64.rpm
mysql-community-icu-data-files-9.0.1-1.el7.x86_64.rpm
mysql-community-libs-9.0.1-1.el7.x86_64.rpm
mysql-community-libs-compat-9.0.1-1.el7.x86_64.rpm
mysql-community-server-9.0.1-1.el7.x86_64.rpm
mysql-community-server-debug-9.0.1-1.el7.x86_64.rpm
mysql-community-test-9.0.1-1.el7.x86_64.rpm
rpm -ivh mysql-community-common-8.0.16-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-8.0.16-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-8.0.16-1.el7.x86_64.rpm
rpm -ivh mysql-community-devel-8.0.16-1.el7.x86_64.rpm
rpm -ivh mysql-community-server-8.0.16-1.el7.x86_64.rpm
————————————————
安装不上去
查看我的系统
cat /etc/os-release
centos7
警告:mysql-community-libs-8.0.39-1.el7.x86_64.rpm: 头V4 RSA/SHA256 Signature, 密钥 ID a8d3785c: NOKEY
错误:依赖检测失败:
mariadb-libs 被 mysql-community-libs-8.0.39-1.el7.x86_64 取代
这个问题是因为mariadb被安装的原因,要卸载掉
rpm -qa | grep -E 'mysql|mariadb'
查到的东西挨个卸载
rpm -e mariadb-libs-5.5.68-1.el7.x86_64
错误:依赖检测失败:
libmysqlclient.so.18()(64bit) 被 (已安裝) postfix-2:2.10.1-9.el7.x86_64 需要
libmysqlclient.so.18(libmysqlclient_18)(64bit) 被 (已安裝) postfix-2:2.10.1-9.el7.x86_64 需要
强制删除
rpm -ev mariadb-libs-5.5.68-1.el7.x86_64 --nodeps
安装完毕
mysql --version
开机器启动
#开机自启
systemctl enable mysqld
#启动
systemctl start mysqld
#查看状态
systemctl status mysqld
#重启
systemctl restart mysqld
#关闭
systemctl stop mysqld
#关闭开机自启
systemctl disable mysqld
初始密码
cat /var/log/mysqld.log | grep root@localhost
mysql -u root -p
alter user root@localhost identified by 'Ab123456CC890;
#选择数据库
use mysql;
#设置 root 用户任意地方可以访问
update user set host='%' where user='root';
#刷新权限
flush privileges;
防火墙
查看防火墙状态 systemctl status firewalld
开启防火墙 systemctl start firewalld
关闭防火墙 systemctl stop firewalld
开启防火墙 service firewalld start
查看是否开启了
firewall-cmd --query-port=3306/tcp
firewall-cmd --add-port=3306/tcp --permanent
firewall-cmd --query-port=3306/tcp
firewall-cmd --reload