Linux使用yum安装mysql8.0

步骤 1. 设置 Yum 存储库

执行以下命令在 CentOS 上启用 MySQL yum 存储库:

rpm -Uvh https://repo.mysql.com/mysql80-community-release-el7-3.noarch.rpm

步骤 2. 安装 MySQL 8 社区服务器

由于 MySQL yum 仓库有多个 MySQL 版本的多个仓库配置,所以需要禁用 mysql repo 文件中的所有仓库:

sed -i s/enabled=1/enabled=0/ /etc/yum.repos.d/mysql-community.repo

并执行以下命令安装 MySQL 8:

yum --enablerepo=mysql80-community -y install mysql-community-server #安装

步骤 3. 启动 MySQL 服务

使用此命令启动 mysql 服务:

systemctl start mysqld

步骤 4. 显示root用户的默认密码

安装 MySQL 8.0 时,root 用户帐户会被授予一个临时密码。要显示 root 用户帐户的密码,请使用以下命令:

grep "A temporary password" /var/log/mysqld.log

步骤 5. MySQL 安全安装

执行命令 mysql_secure_installation 来保护 MySQL 服务器:

mysql_secure_installation

它会提示您输入 root 帐户的当前密码:

Enter password for user root:

输入上面的临时密码,然后按回车。将显示以下消息:

The existing password for the user account root has expired. Please set a new password.

New password:

Re-enter new password:

要为root的帐户输入两次新密码。会提示一些问题,建议输入yes(y):

步骤 6. 重启并启用 MySQL 服务

使用以下命令重启mysql服务:

systemctl restart mysqld

并在系统启动时自动启动 mysql 服务:

systemctl enable mysqld

步骤 7. 连接到 MySQL

使用此命令连接到 MySQL 服务器:

mysql -u root -p

经验分享 程序员 微信小程序 职场和发展