# CentOS 安装MYSQL

By [nightelfamber](https://paragraph.com/@nightelfamber) · 2022-01-26

---

查看Linux 版本
----------

    uname -a
    

    Linux iZ2ze9foeig0mb0yaofw8iZ 4.19.91-24.1.al7.x86_64 #1 SMP Wed Jul 21 17:40:23 CST 2021 x86_64 x86_64 x86_64 GNU/Linux
    

下载mysql源

    wget https://repo.mysql.com//mysql80-community-release-el7-5.noarch.rpm 
    

安装mysql源

    yum -y install mysql80-community-release-el7-5.noarch.rpm
    

查看一下安装效果

    yum repolist enabled | grep mysql.*
    

![mysql源](https://storage.googleapis.com/papyrus_images/0e0215b0c1b2021a1d7d5dcbbe8e0d2b001f739fad5050ce132a51a679437606.png)

mysql源

用yum命令直接安装
----------

    yum install mysql-community-server -y
    

阿里云的基本会安装成功

启动mysql服务
---------

    systemctl start  mysqld.service
    

查看服务运行状况

![run-status](https://storage.googleapis.com/papyrus_images/6c378ca3cc4f4d71172e008671b192b5397dde70db34417261ec98b98d6173d1.png)

run-status

初始化数据库
------

查看初始密码

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

![passwd](https://storage.googleapis.com/papyrus_images/67302659acb49e7aae9d222f330c8a5be75c0dd40dca23968341b4a48cbd5a4b.png)

passwd

登录

    mysql -uroot -p
    

修改密码

    ALTER USER 'root'@'localhost' IDENTIFIED BY '****************';
    

支持远程登录
------

    mysql -uroot -p
    

    use mysql; 
    update user set host = '%' where user = 'root'; 
    select host, user from user;
    

![result](https://storage.googleapis.com/papyrus_images/09dc340d16467ee335d2b8470d03ab24f2c1d844d650e409b983c5e94ab85e7b.png)

result

自动启动
----

    systemctl enable mysqld
    systemctl daemon-reload

---

*Originally published on [nightelfamber](https://paragraph.com/@nightelfamber/centos-mysql)*
