目录
添加Mysql的 yum 仓库.
访问 https://dev.mysql.com/downloads/repo/yum/ 下载 yum 源
点击 download
复制下载链接使用 wget 下载
[root@VM_121_116_centos ~]# wget https://dev.mysql.com/get/mysql80-community-release-el7-2.noarch.rpm
安装刚刚下载的包
[root@VM_121_116_centos ~]# rpm -Uvh mysql80-community-release-el7-2.noarch.rpm
查看mysql yum源
[root@VM_121_116_centos ~]# yum repolist all | grep mysql
mysql-cluster-7.5-community/x86_64 MySQL Cluster 7.5 Community disabled
mysql-cluster-7.5-community-source MySQL Cluster 7.5 Community - disabled
mysql-cluster-7.6-community/x86_64 MySQL Cluster 7.6 Community disabled
mysql-cluster-7.6-community-source MySQL Cluster 7.6 Community - disabled
mysql-connectors-community/x86_64 MySQL Connectors Community enabled: 95
mysql-connectors-community-source MySQL Connectors Community - disabled
mysql-tools-community/x86_64 MySQL Tools Community enabled: 84
mysql-tools-community-source MySQL Tools Community - Sourc disabled
mysql-tools-preview/x86_64 MySQL Tools Preview disabled
mysql-tools-preview-source MySQL Tools Preview - Source disabled
mysql55-community/x86_64 MySQL 5.5 Community Server disabled
mysql55-community-source MySQL 5.5 Community Server - disabled
mysql56-community/x86_64 MySQL 5.6 Community Server disabled
mysql56-community-source MySQL 5.6 Community Server - disabled
mysql57-community/x86_64 MySQL 5.7 Community Server disabled
mysql57-community-source MySQL 5.7 Community Server - disabled
mysql80-community/x86_64 MySQL 8.0 Community Server enabled: 82
mysql80-community-source MySQL 8.0 Community Server - disabled
[root@VM_121_116_centos ~]#
看到除了刚刚的 mysql80-community/x86_64 是启用的其余都是未启用,
如果不是这样的话, 就要吧 80 改成启用, 其余改成未启用操作命令如下:
yum-config-manager --enable mysql80-community
yum-config-manager --disable mysql57-community
安装mysql
[root@VM_121_116_centos ~]# yum install mysql-community-server
输入 y
继续输入 y
启动mysql
[root@VM_121_116_centos ~]# systemctl start mysqld
查看数据库的 root的密码
[root@VM_121_116_centos ~]# grep 'temporary password' /var/log/mysqld.log
登入mysql 数据库修改root 密码, 执行命令输入刚刚查看的密码
[root@VM_121_116_centos ~]# mysql -uroot -p
修改密码
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'QQ123qaz!';
Query OK, 0 rows affected (0.04 sec)
开启远程访问
查看root用户
mysql> select user,authentication_string,host from user;
+------------------+------------------------------------------------------------------------+-----------+
| user | authentication_string | host |
+------------------+------------------------------------------------------------------------+-----------+
| mysql.infoschema | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | localhost |
| mysql.session | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | localhost |
| mysql.sys | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | localhost |
| root | $A$005$E0<(tf.mL ;CV&43huognIaXeaqXKwlPTEzNCBW5ZHZaM6p3T/9yX5GPffK1 | localhost |
+------------------+------------------------------------------------------------------------+-----------+
4 rows in set (0.00 sec)
更新root的 host 为 '%', 并且刷新权限
mysql> update user set host = '%' where user = 'root';
Query OK, 1 row affected (0.01 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.01 sec)