1.下载链接
https://downloads.mysl.com/archives/get/p/23/file/ mysql-5.7.28-1.el7.x86_64.rpm-bundle.tar
2.vm虚拟机链接xshell
查ip:ifconfig
之后在xshell中连接,将压缩包传至虚拟机。
3.卸载mariadb
查看mariadb:rpm -qa | grep mariadb
卸载mariadb:yum remove mariadb-libs-5.5.52-1.el7.x86_64-y
再次查看是否卸载成功:rpm -qa | grep mariadb
4.创建mysql目录到/usr/local目录下:mkdir mysql /usr/local
上传安装包到 /usr/local/mysql中,进行解压:
tar-xvf mysql-5.7.28-1.el7.x86_64.rpm-bundle.tar
5.按照依赖关系依次安装rpm包 依赖关系依次common→libs→client→server
按照顺序依次输入下列命令
rpm -ivh mysql-community-common-5.7.28-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-5.7.28-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-5.7.28-1.el7.x86_64.rpm yum install -y net-tools
rpm -ivh mysql-community-server-5.7.28-1.el7.x86_64.rpm
如果安装异常,修改Redhat的镜像源:
cd /etc/yum.repos.d
mv redhat.repo redhat.repo-backup
下载一份源文件进行修改,移至目录下 /etc/yum.repos.d/CentOS7-
Base-163.repo
wget http://mirrors.163.com/.help/CentOS7-Base-163.repo
cp CentOS7-Base-163.repo /etc/
替换 $releasever 为版本号 7.9.2009 ,替换好的文件内如如下:
*# CentOS-Base.repo*
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client. You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the
# remarked out baseurl= line instead.
#
#
[base]
name=CentOS-7.9.2009 - Base - 163.com
#mirrorlist=http://mirrorlist.centos.org/?
release=7.9.2009&arch=$basearch&repo=os
baseurl=Index of /centos/7.9.2009/os/$basearch/
gpgcheck=1
gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7
#released updates
[updates]
name=CentOS-7.9.2009 - Updates - 163.com
#mirrorlist=http://mirrorlist.centos.org/?
release=7.9.2009&arch=$basearch&repo=updates
baseurl=Index of /centos/7.9.2009/updates/$basearch/
gpgcheck=1
gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7
2/9#additional packages that may be useful
[extras]
name=CentOS-7.9.2009 - Extras - 163.com
#mirrorlist=http://mirrorlist.centos.org/?
release=7.9.2009&arch=$basearch&repo=extras
baseurl=Index of /centos/7.9.2009/extras/$basearch/
gpgcheck=1
gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-7.9.2009 - Plus - 163.com
baseurl=Index of /centos/7.9.2009/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7
保存退出后,执行如下指令:
mv CentOS7-Base-163.repo redhat.repo
yum clean all
yum makecache
6.查看版本
mysql --version
mysql Ver 14.14 Distrib 5.7.28, for Linux (x86_64) using EditLine
wrapper,
如果出现该提示,则证明mysql已经安装成功了。
7.启动mysql服务
== 每次开机都要手动启动mysql ==
systemctl start mysqld
== 开机时自动开启mysql ==
systemctl enable mysqld
3/9== 停止mysql服务器 ==
service mysqld stop
== 启动mysql服务器 ==
service mysqld start
== 查看mysql是否启动 ==
service mysqld status
8.登录mysql
mysql -u root -p
ERROR 1045 (28000): Access denied for user ‘root’@‘localhost’ (using
password: YES)
提示错误,是因为第一次登录mysql需要使用mysql的临时密码,
该密码存放在mysql日志文件中。在 /var/log/mysqld.log 文件中
cd /var/log
查询临时密码
grep -n password mysqld.log
[Note] A temporary password is generated for root@localhost:
0x(g<n074&7W
0x(g<n074&7W 就是mysql自动生成的临时密码
重新登录mysql,隐式登录
mysql -u root -p
把临时密码粘贴
如果出现 mysql>则登录成功
9.修改密码
mysql> set global validate_password_policy=LOW;
mysql> set global validate_password_length=4;
4/9mysql> alter user ‘root’@‘localhost’ identified by ‘你自己得mysql密码’;
10.配置mysql远程访问
此时,虽然防火墙是关着的,但root用户只能用于本机访问,不能用于远
程访问,否则会报错误。如果navicat想远程连接,是无法连接的
因此,接下来要做的是授予root用户远程访问权限
mysql> update mysql.user set host=‘%’ where user=‘root’;
mysql> flush privileges;
输入完以上命令后就可以使用连接工具连接到该linux的mysql了。
11.修改编码
为了防止以后出现乱码问题,我们需要把mysql的编码修改为utf8
[root@localhost mysql]# vim /etc/my.cnf || vi /etc/my.cnf