方法一:
二进制 rpm Yum Repository 方式
首先下载yum资源包
官网下载地址 https://dev.mysql.com/downloads/repo/yum/
进入DownLoad New 下载仓库文件
命令:
下载资源包
[root@localhost ~]# wget https://dev.mysql.com/get/mysql80-community-release-el7-2.noarch.rpm
查看yum仓库
[root@localhost ~]# yum repolist
安装mysql仓库
[root@localhost ~]# rpm -ivh mysql80-community-release-el7-2.noarch.rpm
查看mysql仓库
[root@localhost ~]# ls /etc/yum.repos.d/
更新仓库
[root@localhost ~]# yum makecache
查看yum仓库,此时已经有了mysql8.0
[root@localhost ~]# yum repolist
查看mysql的md5值 和官网的一样代表文件没有损坏或篡改
[root@localhost ~]# md5sum mysql80-community-release-el7-2.noarch.rpm
如果官网给的是sha1值就用sha1sum命令查看
[root@localhost ~]# sha1sum mysql80-community-release-el7-2.noarch.rpm
过滤一下mysql-com的文件
[root@localhost ~]# yum list | grep mysql-com
[root@localhost ~]# yum -y install mysql-community-server
如果出现以下错误使用命令
[root@localhost ~]# yum remove “mysql56-community-release-el7.*”
[root@localhost ~]# yum clean all
启动mysql
[root@localhost ~]# service mysqld start
查看mysql服务器的状态
[root@localhost ~]# service mysqld status
生成临时密码在日志中
[root@localhost ~]# grep ‘temporary password’ /var/log/mysqld.log
登录mysql,密码为临时密码
[root@localhost ~]# mysql -uroot -p
更改密码
[root@localhost ~]# ALTER USER ‘root’@‘localhost’ IDENTIFIED BY ‘MyNewPass4!’;
方案一:改表法
1
查看mysql库中的user表
mysql> use mysql;
mysql> select host,user from user;
±----------------------------±-----+
| host | user |
±----------------------------±-----+
| localhost | root |
| 127.0.0.1 | root |
| ::1 | root |
| node404v.add.bjsc.qihoo.net | root |
±----------------------------±-----+
查看发现root用户只有本机可以访问
把User表中的host字段”localhost”改称”%”
mysql> update user set host = ‘%’ where user = ‘root’;
mysql> select host,user from user;
±----------------------------±-----+
| host | user |
±----------------------------±-----+
| % | root |
| 127.0.0.1 | root |
| ::1 | root |
| node404v.add.bjsc.qihoo.net | root |
±----------------------------±-----+
方案二:授权法
1、如果你想myuser使用mypassword从任何主机连接到mysql服务器的话。
GRANT ALL PRIVILEGES ON . TO ‘myuser’@’%’ IDENTIFIED BY ‘mypassword’ WITH GRANT OPTION;
这样有点不安全,所以建议指定ip才能访问。
2、如果你想允许用户myuser从ip为192.168.1.18的主机连接到mysql服务器,并使用mypassword作为密码。
GRANT ALL PRIVILEGES ON . TO ‘myuser’@‘192.168.1.18’ IDENTIFIED BY ‘mypassword’ WITH GRANT OPTION;
重载授权表:
FLUSH PRIVILEGES
参考:https://blog.csdn.net/lcyaiym/article/details/77282348
或参考:https://www.cnblogs.com/davidgu/p/3706663.html
设置开机自动开启mysql
chkconfig mysqld on
关闭防火墙 : service iptables stop
或 chkconfig iptables off
参考:https://blog.csdn.net/weixin_35353187/article/details/81734982