# Linux环境安装-MySQL安装 **Published by:** [Yeanuo](https://paragraph.com/@yeanuo/) **Published on:** 2023-10-27 **URL:** https://paragraph.com/@yeanuo/linux-mysql ## Content 本文记录在CentOS中使用yum方式安装MySQL的详细步骤 操作环境 Linux版本:CentOS Linux release 7.9.2009 安装的MySQL版本:mysql-community-common.x86_64 0:8.0.35-1.el7 安装路径:/usr/local/mysql/ yum方式安装 从CentOS 7.0发布以来,yum源中开始使用Mariadb来代替MySQL的安装。即使你输入的是yum install -y mysql , 显示的也是Mariadb的安装内容。使用源代码进行编译安装又太麻烦。因此,如果想使用yum安装MySQL的话,就需要去下载官方指定的yum源。 yum下载网址为:https://dev.mysql.com/downloads/repo/yum/,找到Red Hat Enterprise Linux 7 / Oracle Linux 7 (Architecture Independent), RPM Package,单击后面的Download,在新的页面中单击最下面的No thanks, just start my download.就可以下载到yum源了。 安装yum资源库 需要去官网下载最新的版本,否则可能因为版本更新依赖问题,导致安装失败 yum localinstall https://repo.mysql.com//mysql80-community-release-el7-11.noarch.rpm 安装MySQL yum install -y mysql-community-server 安装成功 验证安装 systemctl start mysqld.service systemctl status mysqld.service mysql status 登录 由于MySQL从5.7开始不允许首次安装后使用空密码进行登录。为了加强安全性,系统会随机生成一个密码以供管理员首次登录使用,这个密码记录在/var/log/mysqld.log文件中,使用下面的命令可以查看此密码: cat /var/log/mysqld.log|grep 'A temporary password' 使用临时密码登录 mysql -p 修改密码 mysql> alter user 'root'@'localhost' identified by '123456'; 刷新权限 mysql> flush privileges; 验证 查看版本 mysql> select version(); mysql version 开通3306端口 firewall-cmd --permanent --zone=public --add-port=3306/tcp ## Publication Information - [Yeanuo](https://paragraph.com/@yeanuo/): Publication homepage - [All Posts](https://paragraph.com/@yeanuo/): More posts from this publication - [RSS Feed](https://api.paragraph.com/blogs/rss/@yeanuo): Subscribe to updates - [Twitter](https://twitter.com/JiemaoJob): Follow on Twitter