Linux操作系统如何使用yum安装mysql

1.卸载旧版mysql

如果安装过先卸载,第一次安装略过此步

[root@bianchengshe etc]# rpm -qa | grep mysql
mysql-community-common-5.7.38-1.el7.x86_64
mysql-community-client-5.7.38-1.el7.x86_64
mysql80-community-release-el7-6.noarch
mysql-community-server-5.7.38-1.el7.x86_64
mysql-community-libs-5.7.38-1.el7.x86_64
# 所有组件都要删除
[root@bianchengshe etc]# rpm -e --nodeps mysql-community-common-5.7.38-1.el7.x86_64
[root@bianchengshe etc]# rpm -e --nodeps mysql-community-client-5.7.38-1.el7.x86_64
[root@bianchengshe etc]# rpm -e --nodeps mysql80-community-release-el7-6.noarch
[root@bianchengshe etc]# rpm -e --nodeps mysql-community-server-5.7.38-1.el7.x86_64
[root@bianchengshe etc]# rpm -e --nodeps mysql-community-libs-5.7.38-1.el7.x86_64
# 清理yum headers cache
[root@bianchengshe etc]# yum clean all

2.MySQL Yum Repository 源

有两种方式安装,其实是一回事儿,选择一种

2.1 rpm安装yum源

[root@bianchengshe tmp]# rpm -ivh https://dev.mysql.com/get/mysql80-community-release-el7-6.noarch.rpm

2.2 下载rpm源文件再安装

[root@bianchengshe tmp]# wget https://dev.mysql.com/get/mysql80-community-release-el7-6.noarch.rpm
[root@bianchengshe tmp]# yum localinstall mysql80-community-release-el7-6.noarch.rpm

3.选择mysql版本

[root@bianchengshe tmp]# yum repolist all | grep mysql
mysql-cluster-7.5-community/x86_64           MySQL Cluster 7.5 Comm 禁用
mysql-cluster-7.5-community-source           MySQL Cluster 7.5 Comm 禁用
mysql-cluster-7.6-community/x86_64           MySQL Cluster 7.6 Comm 禁用
mysql-cluster-7.6-community-source           MySQL Cluster 7.6 Comm 禁用
mysql-cluster-8.0-community/x86_64           MySQL Cluster 8.0 Comm 禁用
mysql-cluster-8.0-community-debuginfo/x86_64 MySQL Cluster 8.0 Comm 禁用
mysql-cluster-8.0-community-source           MySQL Cluster 8.0 Comm 禁用
mysql-connectors-community/x86_64            MySQL Connectors Commu 启用:    192
mysql-connectors-community-debuginfo/x86_64  MySQL Connectors Commu 禁用
mysql-connectors-community-source            MySQL Connectors Commu 禁用
mysql-tools-community/x86_64                 MySQL Tools Community  启用:     90
mysql-tools-community-debuginfo/x86_64       MySQL Tools Community  禁用
mysql-tools-community-source                 MySQL Tools Community  禁用
mysql-tools-preview/x86_64                   MySQL Tools Preview    禁用
mysql-tools-preview-source                   MySQL Tools Preview -  禁用
mysql57-community/x86_64                    MySQL 5.7 Community Se 禁用
mysql57-community-source                     MySQL 5.7 Community Se 禁用
mysql80-community/x86_64                     MySQL 8.0 Community Se 启用:    343
mysql80-community-debuginfo/x86_64           MySQL 8.0 Community Se 禁用
mysql80-community-source                     MySQL 8.0 Community Se 禁用

默认是开启8.0版本,我们要禁用8.0开启5.7

[root@bianchengshe tmp]# yum-config-manager --disable mysql57-community
[root@bianchengshe tmp]# yum-config-manager --enable mysql56-community

4.去除公钥检索校验 (最重要的地方

这个地方容易出错,原因是没有去除校验导致服务安装后无法启动

#gpgcheck改成0
[root@bianchengshe tmp]# vim /etc/yum.repos.d/mysql-community.repo
[mysql57-community]
name=MySQL 5.7 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/6/$basearch/
enabled=1
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

5.安装mysql

[root@bianchengshe tmp]# yum install mysql-community-server

6.配置mysql

[root@bianchengshe tmp]# vim /etc/my.cnf
[mysqld]
# 不区分大小写
lower_case_table_names=1
# 端口号
port = 53306

7.启动mysql

[root@bianchengshe tmp]# systemctl start mysqld

8.修改mysql root密码及外网访问

初始密码在这里

# 密码是:6;-#?gn*q;0H
[root@bianchengshe etc]# grep 'temporary password' /var/log/mysqld.log
2022-06-21T03:25:39.021858Z 1 [Note] A temporary password is generated for root@localhost: 6;-#?gn*q;0H

登录mysql修改密码

[root@bianchengshe etc]# mysql -h localhost -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 13
Server version: 5.7.38 MySQL Community Server (GPL)

mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'newpasswd';

登录mysql修改外网访问

mysql> update user set host='%'' where user ='root';

刷新权限

mysql> flush privileges;

9.检验是否安装成功

# 查看mysql端口号
[root@bianchengshe etc]# netstat -nltp | grep 53306
tcp6       0      0 :::53306                :::*                    LISTEN      6070/mysqld
# 查看mysql状态
[root@bianchengshe etc]# systemctl status mysqld
● mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: active (running) since 二 2022-06-21 11:33:23 CST; 2h 14min ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
  Process: 6067 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
  Process: 6045 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
 Main PID: 6070 (mysqld)
    Tasks: 30
   CGroup: /system.slice/mysqld.service
           └─6070 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid

6月 21 11:33:22 localhost systemd[1]: Starting MySQL Server...
6月 21 11:33:23 localhost systemd[1]: Started MySQL Server.
# 查看mysql安装位置
[root@bianchengshe etc]# whereis mysql
mysql: /usr/bin/mysql /usr/lib64/mysql /usr/share/mysql /usr/share/man/man1/mysql.1.gz

10.开启防火墙进站端口

# 查看防火墙状态
[root@bianchengshe etc]# systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
   Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)
   Active: active (running) since 五 2022-06-17 13:49:36 CST; 4 days ago
     Docs: man:firewalld(1)
 Main PID: 876 (firewalld)
    Tasks: 2
   CGroup: /system.slice/firewalld.service
           └─876 /usr/bin/python2 -Es /usr/sbin/firewalld --nofork --nopid
# 如果没有开启则开启
[root@bianchengshe etc]# systemctl start firewalld
# 查看所有放行端口
[root@bianchengshe etc]# firewall-cmd --list-all
public (active)
  target: default
  icmp-block-inversion: no
  interfaces: em1
  sources: 
  services: dhcpv6-client ssh
  ports: 8080/tcp 56379/tcp 53306/tcp
  protocols: 
  masquerade: no
  forward-ports: 
  source-ports: 
  icmp-blocks: 
  rich rules: 
# 查看mysql端口是否已添加
[root@bianchengshe etc]# firewall-cmd --zone=public --query-port=53306/tcp
yes
# 添加mysql端口
[root@bianchengshe etc]# firewall-cmd --zone=public --add-port=53306/tcp
# 刷新防火墙配置
[root@bianchengshe etc]# firewall-cmd --reload
© 版权声明
THE END
喜欢就支持一下吧
点赞138 分享
评论 抢沙发
头像
欢迎您留下宝贵的见解!
提交
头像

昵称

取消
昵称

    暂无评论内容