准备工作:
删除mariadb
$ rpm -qa|grep mariadb
mariadb-libs-5.5.56-2.el7.x86_64
## 上一步查出来的文件名,直接复制下来就OK,删除maridab
$ rpm -e --nodeps mariadb-libs-5.5.56-2.el7.x86_64
删除遗留目录
ls /etc/my.cnf
ll /var/lib/mysql/
rm –rf /etc/my.cnf
rm –rf /var/lib/mysql/
安装mysql
1、下载mysql5.7的rpm安装包
- 下载地址:https://downloads.mysql.com/archives/community/
我选择下面红框内的版本:
image.png
下载后的文件如下:
image.png
2、我是使用xshell连接服务器,使用lrzsz命令上传。
image.png
3、查看linux上是否已经安装了mysql,有则卸载。
一般centos7默认安装了mariadb,这里把它卸载。
image.png
4、安装mysql5.7所需要的依赖
[root@ecs-e50ota-0009 opt]# yum install -y libaio
[root@ecs-e50ota-0009 opt]# yum install -y perl
[root@ecs-e50ota-0009 opt]# yum install -y net-tools
5、解压mysql5.7安装包
[root@ecs-e50ota-0009 opt]# tar -xvf mysql-5.7.30-1.el7.x86_64.rpm-bundle.tar
解压后如下:
[root@ecs-e50ota-0009 opt]# tar -xvf mysql-5.7.30-1.el7.x86_64.rpm-bundle.tar
mysql-community-common-5.7.30-1.el7.x86_64.rpm
mysql-community-server-5.7.30-1.el7.x86_64.rpm
mysql-community-test-5.7.30-1.el7.x86_64.rpm
mysql-community-client-5.7.30-1.el7.x86_64.rpm
mysql-community-embedded-5.7.30-1.el7.x86_64.rpm
mysql-community-libs-5.7.30-1.el7.x86_64.rpm
mysql-community-devel-5.7.30-1.el7.x86_64.rpm
mysql-community-embedded-compat-5.7.30-1.el7.x86_64.rpm
mysql-community-embedded-devel-5.7.30-1.el7.x86_64.rpm
mysql-community-libs-compat-5.7.30-1.el7.x86_64.rpm
6、安装msyql5.7,按照顺序一步一步安装。
[root@ecs-e50ota-0009 opt]# rpm -ivh mysql-community-common-5.7.30-1.el7.x86_64.rpm
[root@ecs-e50ota-0009 opt]# rpm -ivh mysql-community-libs-5.7.30-1.el7.x86_64.rpm
[root@ecs-e50ota-0009 opt]# rpm -ivh mysql-community-client-5.7.30-1.el7.x86_64.rpm
[root@ecs-e50ota-0009 opt]# rpm -ivh mysql-community-server-5.7.30-1.el7.x86_64.rpm
7、查看mysql启动状态,一般是没有启动
[root@ecs-e50ota-0009 opt]# systemctl status mysqld
● mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: inactive (dead)
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
[root@ecs-e50ota-0009 opt]#
8、启动mysql active(running)代表启动成功
[root@ecs-e50ota-0009 opt]# systemctl start mysqld
[root@ecs-e50ota-0009 opt]# systemctl status mysqld
● mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: active (running) since Fri 2021-07-30 17:11:36 CST; 1min 6s ago
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
Process: 19077 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
Process: 19019 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
Main PID: 19080 (mysqld)
CGroup: /system.slice/mysqld.service
└─19080 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid
Jul 30 17:11:25 ecs-e50ota-0009.novalocal systemd[1]: Starting MySQL Server...
Jul 30 17:11:36 ecs-e50ota-0009.novalocal systemd[1]: Started MySQL Server.
[root@ecs-e50ota-0009 opt]#
9、修改默认密码
查看临时密码:得知临时密码就是如下:m3XR<L/)k<Pk
[root@ecs-e50ota-0009 opt]# grep password /var/log/mysqld.log
2021-07-30T09:11:33.741759Z 1 [Note] A temporary password is generated for root@localhost: m3XR<L/)k<Pk
用临时密码登录mysql
[root@ecs-e50ota-0009 opt]# mysql -uroot -p
修改成新的密码
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'Abcd@1234';
10、 开启远程连接,允许远程连接数据库
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'Abcd@1234' WITH GRANT OPTION;
11、配置mysql的配置文件my.cnf(用默认的也行)
打开配置文件my.cnf
[root@localhost src]# vi /etc/my.cnf
在[mysqld]下面配置几行
lower_case_table_names=1 #配置表名不区分大小写 1:不区分大小写 0:区分大小写 这行必须配置 默认表名是区分大小写的,不利于开发
character-set-server=utf8 #设置为默认编码为utf8
init_connect='SET NAMES utf8'
max_connections=1024 #设置最大连接数
重启mysql 重启配置才能生效
[root@localhost src]# service mysqld restart
12、关闭防火墙。
至此,centos7下安装mysql5.7完毕.
网友评论