添加MySQL yum源
rpm -Uvh https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
获取https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
警告:/var/tmp/rpm-tmp.1Ws4Ob: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY
准备中... ################################# [100%]
正在升级/安装...
1:mysql80-community-release-el7-3 ################################# [100%]
直接yum -y install mysql安装的是mariadb
此链接是mysql官网链接,请放心使用。
查看yum源中所有MySQL版本
yum repolist all | grep mysql
mysql57-community/x86_64 MySQL 5.7 Community Server 禁用
mysql57-community-source MySQL 5.7 Community Server - Sou 禁用
mysql80-community/x86_64 MySQL 8.0 Community Server 启用: 177
mysql80-community-source MySQL 8.0 Community Server - Sou 禁用
启用5.7版本,禁用8.0版本MySQL
1.yum -y install yum-utils(安装yum-config-manager指令)
2.yum-config-manager --disable mysql80-community
3.yum-config-manager --enable mysql57-community
4.yum repolist all | grep mysql
mysql57-community/x86_64 MySQL 5.7 Community Server 启用: 424
mysql57-community-source MySQL 5.7 Community Server - Sou 禁用
mysql80-community/x86_64 MySQL 8.0 Community Server 禁用
mysql80-community-source MySQL 8.0 Community Server - Sou 禁用
安装mysql
yum -y install mysql-community-server
下载有点慢 请耐心等到。。。
起服务,开机自启
systemctl start mysqld
systemctl enable mysqld
查看mysql初始密码
grep password /var/log/mysqld.log
2020-05-11T08:15:04.517710Z 1 [Note] A temporary password is generated for root@localhost: %JbzXj?0OGZJ
%JbzXj?0OGZJ 初始密码(随机生成的)
修改初始密码
mysqladmin -uroot -p'%JbzXj?0OGZJ' password
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
New password:
Confirm new password:
warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety.
输入命令mysqladmin -uroot -p’%JbzXj?0OGZJ’ password 按回车再输入新密码,新密码最好要数字+字母+大写字母,不然容易报错!!!
登陆数据库,并授权root
1.mysql -uroot -p新密码(登陆)
2.grant all on *.*(所有库表) to root@'%'(所有登录方式) identified by ‘密码’;
此处密码也要复杂一点,不然密码太简单容易报错!!!切记!!!