CentOS-mysql安装

yum换源[可选]

备份原始源

mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup

更换阿里源

以CentOS7为例

wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

或者

curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

安装源

下载源文件

以mysql5.7为例

wget http://repo.mysql.com/mysql57-community-release-el7-10.noarch.rpm

安装源文件

rpm -Uvh mysql57-community-release-el7-10.noarch.rpm

安装使用Mysql

安装命令

yum install -y mysql-community-server

注意此处如果出现

The GPG keys listed for the "MySQL 5.7 Community Server" repository are already installed 
but they are not correct for this package.
Check that the correct key URLs are configured for this repository.

这是由于MySQL GPG 密钥已过期导致的 问题解决出处
需要运行命令, 以2022年为例

rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022

启动Mysql

systemctl restart mysqld.service

检查是否启动成功

systemctl status mysqld.service

配置Mysql

查看随机初始密码

grep 'temporary password' /var/log/mysqld.log 

登录Mysql

输入初始密码

mysql -u root -p

修改密码

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

授权其他机器远程登录

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'yourpassword' WITH GRANT OPTION;

设置开机自启

systemctl enable mysqld
systemctl daemon-reload
posted @ 2022-03-14 15:33  漫漫长夜何时休  阅读(1440)  评论(0编辑  收藏  举报