下载地址
- 地址 (提取码: 5em4)
- 名称:
mysql-5.7.28-1.el7.x86_64.rpm-bundle.tar
前置条件
新建虚拟机时最好给4G~8G的内存,不然最后启动mysql时会因为内存不够而报错
安装步骤
1. 使用sftp工具 快捷键: alt + p
上传 mysql-5.7.28-1.el7.x86_64.rpm-bundle.tar
文件到linux
sftp> put F:\software\mysql-5.7.28-1.el7.x86_64.rpm-bundle.tar
默认上传的位置
[root@localhost ~]# ls
anaconda-ks.cfg mysql-5.7.28-1.el7.x86_64.rpm-bundle.tar
移动到/usr/local/mysql
下
[root@localhost ~]# mv mysql-5.7.28-1.el7.x86_64.rpm-bundle.tar /usr/local/mysql
2. 查看是否已经安装mysql
rpm -qa | grep -i mysql
3. 解压tar文件
进入cd /usr/local/mysql
目录
[root@localhost ~]# cd /usr/local/mysql
[root@localhost mysql]# ls
mysql-5.7.28-1.el7.x86_64.rpm-bundle.tar
- 命令
tar -xvf mysql-5.7.28-1.el7.x86_64.rpm-bundle.tar
- 执行结果
[root@localhost mysql]# tar -xvf mysql-5.7.28-1.el7.x86_64.rpm-bundle.tar
mysql-community-embedded-5.7.28-1.el7.x86_64.rpm
mysql-community-libs-compat-5.7.28-1.el7.x86_64.rpm
mysql-community-devel-5.7.28-1.el7.x86_64.rpm
mysql-community-embedded-compat-5.7.28-1.el7.x86_64.rpm
mysql-community-libs-5.7.28-1.el7.x86_64.rpm
mysql-community-test-5.7.28-1.el7.x86_64.rpm
mysql-community-common-5.7.28-1.el7.x86_64.rpm
mysql-community-embedded-devel-5.7.28-1.el7.x86_64.rpm
mysql-community-client-5.7.28-1.el7.x86_64.rpm
mysql-community-server-5.7.28-1.el7.x86_64.rpm
注意:在新版本的CentOS7中,默认的数据库已更新为了Mariadb,而非 MySQL,所以执行
yum install mysql
命令只是更新Mariadb数据库,并不会安装 MySQL 。
4. 解决冲突的rpm组件
(1). postfix
查看postfix
rpm -qa | grep -i postfix
卸载postfix
rpm -ev postfix-2.10.1-7.el7.x86_64
(2). mariadb
查看已安装的 Mariadb 数据库
rpm -qa | grep -i mariadb
卸载已安装的 Mariadb 数据库
rpm -ev mariadb-libs-5.5.64-1.el7.x86_64
5. 按先后顺序安装依赖组件
安装common包:rpm -ivh mysql-community-common-5.7.28-1.el7.x86_64.rpm
[root@VM-4-13-centos soft]# rpm -ivh mysql-community-common-5.7.28-1.el7.x86_64.rpm
Preparing... ################################# [100%]
Updating / installing...
1:mysql-community-common-5.7.28-1.e################################# [100%]
[root@VM-4-13-centos soft]# Preparing... ################################# [100%]
-bash: Preparing...: command not found
[root@VM-4-13-centos soft]# Updating / installing...
-bash: Updating: command not found
[root@VM-4-13-centos soft]# 1:mysql-community-common-5.7.28-1.e################################# [100%]
安装libs包:rpm -ivh mysql-community-libs-5.7.28-1.el7.x86_64.rpm
[root@VM-4-13-centos soft]# rpm -ivh mysql-community-libs-5.7.28-1.el7.x86_64.rpm
Preparing... ################################# [100%]
Updating / installing...
1:mysql-community-libs-5.7.28-1.el7################################# [100%]
安装libs-compat包:rpm -ivh mysql-community-libs-compat-5.7.28-1.el7.x86_64.rpm
[root@VM-4-13-centos soft]# rpm -ivh mysql-community-libs-compat-5.7.28-1.el7.x86_64.rpm
Preparing... ################################# [100%]
Updating / installing...
1:mysql-community-libs-compat-5.7.2################################# [100%]
安装客户端:rpm -ivh mysql-community-client-5.7.28-1.el7.x86_64.rpm
[root@VM-4-13-centos soft]# rpm -ivh mysql-community-client-5.7.28-1.el7.x86_64.rpm
Preparing... ################################# [100%]
Updating / installing...
1:mysql-community-client-5.7.28-1.e################################# [100%]
安装服务端:rpm -ivh mysql-community-server-5.7.28-1.el7.x86_64.rpm
[root@VM-4-13-centos soft]# rpm -ivh mysql-community-server-5.7.28-1.el7.x86_64.rpm
Preparing... ################################# [100%]
Updating / installing...
1:mysql-community-server-5.7.28-1.e################################# [100%]
[root@VM-4-13-centos soft]#
安装工具包:rpm -ivh mysql-community-devel-5.7.28-1.el7.x86_64.rpm
[root@VM-4-13-centos soft]# rpm -ivh mysql-community-devel-5.7.28-1.el7.x86_64.rpm
Preparing... ################################# [100%]
Updating / installing...
1:mysql-community-devel-5.7.28-1.el################################# [100%]
7.初始化和启动mysql
初始化数据库
mysqld --initialize --user=mysql
查看初始登录密码
cat /var/log/mysqld.log
[root@VM-4-13-centos soft]# cat /var/log/mysqld.log
2022-05-28T08:16:01.937822Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2022-05-28T08:16:02.285473Z 0 [Warning] InnoDB: New log files created, LSN=45790
2022-05-28T08:16:02.370656Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2022-05-28T08:16:02.445587Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 69c50a57-de5e-11ec-be04-525400887b52.
2022-05-28T08:16:02.449589Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2022-05-28T08:16:03.395033Z 0 [Warning] CA certificate ca.pem is self signed.
2022-05-28T08:16:03.477406Z 1 [Note] A temporary password is generated for root@localhost: .EAen-5oqRcl
启动mysql服务并设置开机启动
systemctl start mysqld
systemctl enable mysqld
查看mysql启动状态
systemctl status mysqld
[root@VM-4-13-centos soft]# systemctl status mysqld
● mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: active (running) since Sat 2022-05-28 16:20:53 CST; 12s ago
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
Process: 3998 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
Process: 3980 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
Main PID: 4001 (mysqld)
CGroup: /system.slice/mysqld.service
└─4001 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid
May 28 16:20:53 VM-4-13-centos systemd[1]: Starting MySQL Server...
May 28 16:20:53 VM-4-13-centos systemd[1]: Started MySQL Server.
8. 登录mysql
mysql -uroot -p.EAen-5oqRcl
9. 修改mysql密码
mysql> set password = password ('123456');
10. 开启mysql的远程登录权限
mysql> grant all privileges on *.* to 'root'@'%' identified by '123456';
刷新
mysql> flush privileges;
11. 开放对外访问3306端口
/sbin/iptables -I INPUT -p tcp --dport 3306 -j ACCEPT
永久开放3306端口
firewall-cmd --permanent --zone=public --add-port=3306/tcp
12. 查看防火墙开放的端口
firewall-cmd --list-ports
13. 宿主机使用Navicat Premium
工具远程连接mysql
14. rpm安装mysql默认的目录
[root@localhost bin]# find / -name mysql
/run/lock/subsys/mysql
/etc/rc.d/init.d/mysql
/etc/logrotate.d/mysql
/etc/selinux/targeted/active/modules/100/mysql
/var/lib/mysql
/var/lib/mysql/mysql
/usr/bin/mysql
/usr/lib/mysql
/usr/lib64/mysql
/usr/share/mysql
/usr/local/mysql
数据文件:/var/lib/mysql/
配置文件模板:/usr/share/mysql
mysql客户端工具目录:/usr/bin
日志目录:/var/log/
pid,sock文件目录:/tmp/
配置文件会放在/etc
下
15. 修改my-default.cnf的位置并命名为my.cnf
cp /usr/share/mysql/my-default.cnf /etc/my.cnf #移动MySQL配置文件的位置
具体如何修改my.cnf配置,请自行查询my.cnf配置说明文档