阿里云centos7安装mysql8

阿里云centos7安装mysql8

1、mysql软件下载
下载地址:https://dev.mysql.com/downloads/repo/yum/

阿里云centos7安装mysql8

2、将下载好的mysql安装包上传到阿里云centos服务器

2.1、使用xshell登录阿里云centos服务器

阿里云centos7安装mysql8

阿里云centos7安装mysql8

2.2、使用rz命令上传软件包

[[email protected] soft_bag]# rz

阿里云centos7安装mysql8

2.3、查看文件上传结果

[[email protected] soft_bag]# ll

 阿里云centos7安装mysql8

3、安装软件源

[[email protected] soft_bag]# rpm -Uvh mysql80-community-release-el7-3.noarch.rpm

阿里云centos7安装mysql8

4、安装mysql服务端

[[email protected] soft_bag]# yum install -y mysql-community-server

阿里云centos7安装mysql8

5、启动mysql

[[email protected] usr]# service mysqld start

阿里云centos7安装mysql8

6、查看mysql的运行状态

[[email protected] usr]# service mysqld status

阿里云centos7安装mysql8

7、修改临时密码

Mysql8.0默认安装之后root是有密码的。

7.1、 获取MySQL的临时密码

为了加强安全性,MySQL8.0为root用户随机生成了一个密码,在error log中,关于error log的位置,如果安装的是RPM包,则默认是/var/log/mysqld.log。
只有启动过一次mysql才可以查看临时密码

grep 'temporary password' /var/log/mysqld.log(如果之前安装过MySQL则这里可能会有多个密码,用最后一个,注意这个密码输入时是可以粘贴的)。

[[email protected] usr]# grep 'temporary password' /var/log/mysqld.log

阿里云centos7安装mysql8

这里的密码是:,b!(n6=s8.JT

7.2、登录并修改为简单密码

[[email protected] usr]# mysql -uroot –p

阿里云centos7安装mysql8

用该密码登录到服务端后,必须马上修改密码再执行一些数据库操作,不然会报如下错误:

阿里云centos7安装mysql8

mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '[email protected]';

但是这个密码比较复杂,如何设置简单密码呢,操作如下:

密码修改后,可用命令查看 validate_password 密码验证插件是否安装。

mysql> SHOW VARIABLES LIKE 'validate_password%';

阿里云centos7安装mysql8

MySQL 8.0 调整密码验证规则:

mysql> set global validate_password.policy=0;

mysql> set global validate_password.length=1;

阿里云centos7安装mysql8

mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '1234';

阿里云centos7安装mysql8

8、远程连接

8.1、打开3306端口

登录阿里云账号,进入我的控制台找到相应的服务器,配置安全组规则,添加mysql的端口号。

客户端使用telnet查看端口是否能通。

C:\Users\Administrator>telnet 47.97.127.208 3306

如果出现黑色框切换则证明端口已开通。

8.2、使用navicat测试链接数据库

阿里云centos7安装mysql8

报错:1130 – Host ‘xxx.xxx.xxx.xxx’ is not allowed to connect to this MySQL server.

解决方案:

进入mysql以后:

更新域属性

mysql> use mysql;

阿里云centos7安装mysql8

设置允许外地访问

mysql> update user set host='%' where user='root';

阿里云centos7安装mysql8

刷新MySQL的系统权限相关表

mysql> flush privileges;

阿里云centos7安装mysql8

执行授权操作

mysql> grant all privileges on *.* to 'root'@'%' with grant option;

阿里云centos7安装mysql8

然后在用navicat测试链接

阿里云centos7安装mysql8

到现在为止,mysql数据库就可以正常去应用了。