一、查看Linux版本和系统内核
[root@localhost ~]# cat /etc/redhat-release 查看版本
CentOS Linux release 7.9.2009 (Core)
[root@localhost ~]# uname -r 查看内核
3.10.0-1160.el7.x86_64
二、下载对应的MySQL
MySQL官网:https://www.mysql.com/downloads/
1)
2)
3)
4)
5)
3.接下来,首先要卸载Centos7 自带的mariadb.
[root@localhost ~]# rpm -qa | grep mariadb
mariadb-libs-5.5.68-1.el7.x86_64
[root@localhost ~]# rpm -e --nodeps mariadb-libs-5.5.68-1.el7.x86_64
[root@localhost ~]#
4.上传到Centos服务上任意文件夹下,tar -xvf myql-xxx.tar 解压
[root@localhost ~]# 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
[root@localhost ~]#
5.rpm命令安装MySQL组件,使用rpm -ivh file 进行安装,按照依赖关系安装,依赖关系依次是common ->libs ->client ->server
[root@localhost ~]# rpm -ivh mysql-community-common-5.7.28-1.el7.x86_64.rpm
warning: mysql-community-common-5.7.28-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:mysql-community-common-5.7.28-1.e################################# [100%]
[root@localhost ~]# rpm -ivh mysql-community-libs-5.7.28-1.el7.x86_64.rpm
warning: mysql-community-libs-5.7.28-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:mysql-community-libs-5.7.28-1.el7################################# [100%]
[root@localhost ~]# rpm -ivh mysql-community-client-5.7.28-1.el7.x86_64.rpm
warning: mysql-community-client-5.7.28-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:mysql-community-client-5.7.28-1.e################################# [100%]
[root@localhost ~]# rpm -ivh mysql-community-server-5.7.28-1.el7.x86_64.rpm
warning: mysql-community-server-5.7.28-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
error: Failed dependencies:
/usr/bin/perl is needed by mysql-community-server-5.7.28-1.el7.x86_64
net-tools is needed by mysql-community-server-5.7.28-1.el7.x86_64
perl(Getopt::Long) is needed by mysql-community-server-5.7.28-1.el7.x86_64
perl(strict) is needed by mysql-community-server-5.7.28-1.el7.x86_64
[root@localhost ~]#
6.当安装到mysql-community-server 报错了,这是缺少依赖,安装对应的依赖后再安装
yum install -y perl net-tools
rpm -ivh mysql-community-client-5.7.28-1.el7.x86_64.rpm
7.安装完成后,会生成几个文件,如下所示:
[root@localhost ~]# ls /etc/ | grep my
my.cnf
my.cnf.d
[root@localhost ~]# ls /var/lib/ | grep my
mysql
mysql-files
mysql-keyring
[root@localhost ~]# ls /var/log/ | grep my
mysqld.log
[root@localhost ~]# ls /var/run/ | grep my
mysqld
8.启动
[root@localhost ~]# systemctl start mysqld.service
[root@localhost ~]# systemctl status mysqld.service
● mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: active (running) since Sat 2021-09-04 11:22:51 EDT; 15s ago
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
Process: 2163 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
Process: 2114 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
Main PID: 2166 (mysqld)
CGroup: /system.slice/mysqld.service
└─2166 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid
Sep 04 11:22:47 localhost.localdomain systemd[1]: Starting MySQL Server...
Sep 04 11:22:51 localhost.localdomain systemd[1]: Started MySQL Server.
[root@localhost ~]#
9.查看临时密码
[root@localhost ~]# grep 'password' /var/log/mysqld.log
2021-09-04T15:22:48.784399Z 1 [Note] A temporary password is generated for root@localhost: e4,28U*G9AtW
[root@localhost ~]#
10.mysql -u root -p 输入日志中的密码登录,修改密码
mysql> set global validate_password_length=1;
Query OK, 0 rows affected (0.00 sec)
mysql> set global validate_password_policy=0;
Query OK, 0 rows affected (0.00 sec)
mysql> alter user user() identified by 'root';
Query OK, 0 rows affected (0.00 sec)
mysql>
11.授权远程登录
mysql> grant all privileges on *.* to 'root'@'%' identified by 'root' with grant option;
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql>
12.开通3306端口
[root@localhost ~]# firewall-cmd --zone=public --add-port=3306/tcp --permanent
success
[root@localhost ~]# firewall-cmd --reload
success