使用:https://dev.mysql.com/downloads/repo/yum/
下载与自己linux对应的版本mysql源
下载和安装mysql源
[root@localhost ~]# wget https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
如果显示wget未找到命令,则需要先安装wget:
yum -y install wget
然后再次执行上面命令
安装mysql源
[root@localhost ~]# sudo rpm -Uvh mysql80-community-release-el7-3.noarch.rpm
选择masql版本
使用MySQL Yum Repository安装MySQL,默认会选择当前最新的稳定版本
使用命令:yum repolist all | grep mysql,查看当前yum repolist的所有版本
切换版本
[root@localhost ~] sudo yum-config-manager --disable mysql80-community
[root@localhost ~] sudo yum-config-manager --enable mysql57-community
安装mysql
[root@localhost ~]# sudo yum install mysql-community-server
该命令会安装MySQL服务器 (mysql-community-server) 及其所需的依赖、相关组件,包括mysql-community-client、mysql-community-common、mysql-community-libs等。安装时间会比较长
启动
[root@localhost ~]# systemctl start mysqld.service
[root@localhost ~]# systemctl status mysqld.service
启动成功
停止
[root@localhost ~]# systemctl stop mysqld.service
重启
[root@localhost ~]# systemctl restart mysqld.service
修改密码及登录
初始密码
MySQL第一次启动后会创建超级管理员账号root@localhost,初始密码存储在日志文件中:
[root@localhost ~]# grep ‘temporary password‘ /var/log/mysqld.log 2020-12-06T07:32:41.399112Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: Nd<-p!Fxt6A8
修改默认密码
# 先进行登录
[root@localhost ~]# mysql -uroot -p Enter password: mysql> ALTER USER ‘root‘@‘localhost‘ IDENTIFIED BY ‘password‘; ERROR 1819 (HY000): Your password does not satisfy the current policy requirements #密码太弱
解决方法如下:
使用复杂密码,MySQL默认的密码策略是要包含数字、大小写字母及特殊字符;