CentOS7用yum安装MySQL8及各个版本

 配置YUM源

vim /etc/yum.repos.d/mysql-community.repo

填写以下内容(这是mysql8): 

[mysql-connectors-community]
name=MySQL Connectors Community
baseurl=https://opentuna.cn/mysql/yum/mysql-connectors-community-el7-$basearch/
enabled=1
gpgcheck=1
gpgkey=https://repo.mysql.com/RPM-GPG-KEY-mysql

[mysql-tools-community]
name=MySQL Tools Community
baseurl=https://opentuna.cn/mysql/yum/mysql-tools-community-el7-$basearch/
enabled=1
gpgcheck=1
gpgkey=https://repo.mysql.com/RPM-GPG-KEY-mysql

[mysql-8.0-community]
name=MySQL 8.0 Community Server
baseurl=https://opentuna.cn/mysql/yum/mysql-8.0-community-el7-$basearch/
enabled=1
gpgcheck=1
gpgkey=https://repo.mysql.com/RPM-GPG-KEY-mysql

如果你想要其他版本(例如常用的5.7版本)就可以填写以下内容

[mysql-connectors-community]
name=MySQL Connectors Community
baseurl=https://opentuna.cn/mysql/yum/mysql-connectors-community-el7-$basearch/
enabled=1
gpgcheck=1
gpgkey=https://repo.mysql.com/RPM-GPG-KEY-mysql

[mysql-tools-community]
name=MySQL Tools Community
baseurl=https://opentuna.cn/mysql/yum/mysql-tools-community-el7-$basearch/
enabled=1
gpgcheck=1
gpgkey=https://repo.mysql.com/RPM-GPG-KEY-mysql

[mysql-5.7-community]
name=MySQL 5.7 Community Server
baseurl=https://opentuna.cn/mysql/yum/mysql-5.7-community-el7-$basearch/
enabled=1
gpgcheck=1
gpgkey=https://repo.mysql.com/RPM-GPG-KEY-mysql

填完之后先别急着安装

官方文档有说明:对于 RPM 包,没有单独的签名。RPM 包具有内置的 GPG 签名和 MD5 校验

官方地址:MySQL :: MySQL 8.0 Reference Manual :: 2.1.4.4 Signature Checking Using RPM

所以我们要先加载密匙(执行下面语句即可)

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

然后我们就可以安装了,执行下面语句进行安装

yum install -y mysql-community-server

安装完之后,我们可以选择启动它

service mysqld start

我们可以通过命令来查看它的版本(注意是两个横杠)

mysql --version

mysql在安装后会创建一个root@locahost账户,并且把初始的密码放到了/var/log/mysqld.log文件中,我们可以执行下列命令查看密码。

cat /var/log/mysqld.log | grep password

 这个就是我们的初始临时密码

然后我们就可以用临时密码去登陆(特别注意,这里的临时密码很乱,不好检查输入的是否正确,所以我们可以直接右击复制粘贴来输入)

mysql -u root -p 

登录进去之后,我们就可以给root账户修改一个我们自己的密码(当然mysql8为了安全,你需要把密码设置的稍微复杂一点,否则会报错:ERROR 1819 (HY000): Your password does not satisfy the current policy requirements

ALTER USER 'root'@'localhost' IDENTIFIED BY 'Xmm123456!' PASSWORD EXPIRE NEVER;

修改完之后,我们刷新一下权限

FLUSH PRIVILEGES;

然后退出mysql

exit

然后我们就可以,再用自己设置的密码登录一下(输入自己刚刚设置的密码即可)

mysql -u root -p 

到这就算是安装完毕!

有什么不足的,或者有什么不对的,欢迎来指教

end...

猜你喜欢

转载自blog.csdn.net/xiaomaomixj/article/details/125983142