https://www.cnblogs.com/ccsert/p/12296213.html

检查mysql环境是否已存在

虽然我的是纯净系统,但别人的不能保证,为了避免发生什么问题我们还是先检查下mysql是否已经安装过

[root@localhost ~]# rpm -qa | grep mysql [root@localhost ~]# rpm -qa |grep mariadb mariadb-libs-5.5.64-1.el7.x86_64

我这里要卸载mariadb

[root@localhost ~]# yum remove mariadb-libs-5.5.64-1.el7.x86_64

假如你发现类似的就和我一样删除就好了

切换阿里云镜像源

先安装wget

[root@localhost ~]# yum install wget -y

然后下载阿里云yum源配置

[root@localhost ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

然后生成缓存

[root@localhost ~]# yum makecache

显视元数据缓存已建立就代表完成了

然后我们更新一下yum

[root@localhost ~]# yum update -y

这可能需要一点时间,耐心等待一下

下载国内的mysql rpm包并安装

地址为http://mirrors.ustc.edu.cn/mysql-ftp/Downloads
我这里直接通过下载地址下载

先是server包

[root@localhost ~]# wget http://mirrors.ustc.edu.cn/mysql-ftp/Downloads/MySQL-5.7/mysql-community-server-5.7.32-1.el7.x86_64.rpm

然后是client包

wget http://mirrors.ustc.edu.cn/mysql-ftp/Downloads/MySQL-5.7/mysql-community-client-5.7.32-1.el7.x86_64.rpm

还有common

[root@localhost ~]# wget http://mirrors.ustc.edu.cn/mysql-ftp/Downloads/MySQL-5.7/mysql-community-common-5.7.32-1.el7.x86_64.rpm

最后还有一个lib

[root@localhost ~]# wget http://mirrors.ustc.edu.cn/mysql-ftp/Downloads/MySQL-5.7/mysql-community-libs-5.7.32-1.el7.x86_64.rpm

在此之前我们还要先安装三个依赖环境
net-tools.x86_64,libaio.x86_64,perl.x86_64

我们直接使用yum安装

yum install -y perl.x86_64 yum install -y libaio.x86_64 yum install -y net-tools.x86_64

然后按照顺序安装mysql的依赖

[root@localhost ~]# rpm -ivh mysql-community-common-5.7.32-1.el7.x86_64.rpm
[root@localhost ~]# rpm -ivh mysql-community-libs-5.7.32-1.el7.x86_64.rpm
[root@localhost ~]# rpm -ivh mysql-community-client-5.7.32-1.el7.x86_64.rpm
[root@localhost ~]# rpm -ivh mysql-community-server-5.7.32-1.el7.x86_64.rpm

然后我们重启下mysql服务

[root@localhost ~]# service mysqld.service restart

我们查看下默认密码

[root@localhost etc]# grep 'temporary password' /var/log/mysqld.log
2020-02-11T09:49:32.224110Z 1 [Note] A temporary password is generated for root@localhost: E;#ySql0!>

我的密码为 E;#ySql0!>

[root@localhost mysql]# mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 10 Server version: 5.7.25 Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql>

登录成功,接着改下密码和远程连接

修改密码并开启远程连接

修改密码

这里因为mysql的新版本限制了密码复杂度,所以我们需要设置一个稍微复杂的密码

mysql> set password=password('这里输入你想改的密码'); Query OK, 0 rows affected, 1 warning (0.00 sec)

密码需要包含数字和特殊符号,以及大写字母和小写字母
当然你设置完成以后可以就将密码限制关闭后在重新改密码,这里不过多演示

开启远程连接

打开mysql数据库

mysql> use mysql;

修改一条数据使其支持远程连接

mysql> update user set Host = '%' where Host = 'localhost' and User='root';

刷新系统权限相关表

mysql> flush privileges;
posted on 2020-11-09 22:39  查祝兆  阅读(953)  评论(0编辑  收藏  举报