ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
centos7安装MySQL8步骤如下: **1. 官网下载对应的MySQL8** https://downloads.mysql.com/archives/community/ ![](https://img.kancloud.cn/b3/f1/b3f1a9c8a689d0f367e4e2deffbde175_1822x571.png) **2. 卸载centos7自带的mariadb数据库** ```shell (1)查看是否存在mariadb # rpm -qa | grep mariadb mariadb-libs-5.5.35-3.el7.x86_64 (2)卸载mariadb # rpm -e mariadb-libs-5.5.35-3.el7.x86_64 --nodeps ``` **3. 上传到Linux上并解压** ```shell # tar -xvf mysql-8.0.18-1.el7.x86_64.rpm-bundle.tar -C mysql8/ --解压完成后有如下文件 -rw-r--r--. 1 7155 31415 40104640 Sep 23 2019 mysql-community-client-8.0.18-1.el7.x86_64.rpm -rw-r--r--. 1 7155 31415 611436 Sep 23 2019 mysql-community-common-8.0.18-1.el7.x86_64.rpm -rw-r--r--. 1 7155 31415 6915400 Sep 23 2019 mysql-community-devel-8.0.18-1.el7.x86_64.rpm -rw-r--r--. 1 7155 31415 23683600 Sep 23 2019 mysql-community-embedded-compat-8.0.18-1.el7.x86_64.rpm -rw-r--r--. 1 7155 31415 3877664 Sep 23 2019 mysql-community-libs-8.0.18-1.el7.x86_64.rpm -rw-r--r--. 1 7155 31415 1363968 Sep 23 2019 mysql-community-libs-compat-8.0.18-1.el7.x86_64.rpm -rw-r--r--. 1 7155 31415 450282440 Sep 23 2019 mysql-community-server-8.0.18-1.el7.x86_64.rpm -rw-r--r--. 1 7155 31415 158001648 Sep 23 2019 mysql-community-test-8.0.18-1.el7.x86_64.rpm ``` **4. 安装MySQL8** ```shell --下面这4个文件是必须安装的,其他是可选的 # rpm -ivh mysql-community-common-8.0.18-1.el7.x86_64.rpm --nodeps --force # rpm -ivh mysql-community-libs-8.0.18-1.el7.x86_64.rpm --nodeps --force # rpm -ivh mysql-community-client-8.0.18-1.el7.x86_64.rpm --nodeps --force # rpm -ivh mysql-community-server-8.0.18-1.el7.x86_64.rpm --nodeps --force --查看已安装资源 # rpm -qa | grep mysql mysql-community-libs-8.0.18-1.el7.x86_64 mysql-community-server-8.0.18-1.el7.x86_64 mysql-community-common-8.0.18-1.el7.x86_64 mysql-community-client-8.0.18-1.el7.x86_64 ``` **5. MySQL初始化** ```shell (1)初始化 # mysqld --initialize (2)赋予mysql操作 /var/lib/mysql 目录的权限 --MySQL8核心配置文件默认在 /etc/my.cnf,默认数据存储在 /var/lib/mysql # chown mysql:mysql -R /var/lib/mysql (3)启动MySQL # systemctl start mysqld (4)查看MySQL是否已经启动 # systemctl status mysqld mysqld.service - MySQL Server Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled) Active: activating (start) since Wed 2021-09-29 17:06:36 CST; 1min 44s ago (5)设置MySQL开机自启 # systemctl enable mysqld ``` **6. 设置数据库密码** ```shell (1)查看初始密码 # cat /var/log/mysqld.log | grep password ... for root@localhost: M&npo4JrX9g!(类似这个就是初始密码) (2)登录mysql # mysql -u root -p (3)设置mysql登录密码 mysql> alter USER 'root'@'localhost' IDENTIFIED BY '你的密码'; (4)退出mysql mysql> exit; (5)重启mysql # systemctl restart mysqld ``` **7. 允许远程访问** ``` (1)允许所有主机远程访问数据库 mysql> use mysql; --root为用户,%表示允许所有的主机远程访问root用户这个数据库 mysql> create user 'root'@'%' identified with mysql_native_password by 'abc@hPMq'; mysql> grant all privileges on *.* to 'root'@'%' with grant option; (2)更改加密规则 --mysql8之前加密规则为:mysql_native_password --mysql8之后默认加密规则为:caching_sha2_password --所以第三方工具访问mysql8要么升级工具的mysql驱动包,要么使用mysql_native_password加密规则 mysql> alter user 'root'@'%' identified with mysql_native_password by 'abc@hPMq'; (3)刷新一下 mysql> flush privileges; ``` **8. 关闭防火墙** ```shell (1)查看防火墙是否开启,runing为开启 # firewall-cmd --state running (2)关闭防火墙 # systemctl stop firewalld.service (3)禁止防火墙开机自启 # systemctl disable firewalld.service (4)关闭selinux # vim /etc/selinux/config --将SELINUX=enforcing 改为 SELINUX=disabled SELINUX=disabled ``` **9. 我使用SQLyog成功访问到了数据库** ![](https://img.kancloud.cn/7e/03/7e03f17943e69b75105a4edf5c5edce9_1334x550.png) **10. 安装完毕!**