MySQL 5.7.25 yum仓库安装教程(Linux RedHat7.2)

使用此方法将默认安装最新的GA版本

1、将MySQL Yum仓库加入系统仓库中
 a.Go to the Download MySQL Yum Repository page (https://dev.mysql.com/downloads/repo/yum/) in the MySQL Developer Zone. 

 b.Select and download the release package for your platform.

 c.Install the downloaded release package with the following command, replacing platform-and-version-specific-package-name with the name of the downloaded RPM package:

 [root@localhost ~]# yum install mysql80-community-release-el7-2.noarch.rpm

 d.验证仓库是否新增成功
  shell> ll /etc/yum.repos.d/
  shell> yum repolist enabled | grep "mysql.*-community.*"

 Note
Once the MySQL Yum repository is enabled on your system, any system-wide update by the yum update command (or dnf upgrade for Fedora) will upgrade MySQL packages on your system and also replace any native third-party packages, if Yum finds replacements for them in the MySQL Yum repository; see Section 2.11.5, “Upgrading MySQL with the MySQL Yum Repository” and, for a discussion on some possible effects of that on your system, see Upgrading the Shared Client Libraries. 

2、选择版本
 a.如果要安装最近的GA版本,本步骤可以忽略,刚刚新增的MySQL Yum仓库里面的子仓库包括很多版本,如下命令查看哪些默认启用,哪些未启用
 可以看到默认启用的是最新的MySQL 8.0

 [root@localhost yum.repos.d]# yum repolist all | grep mysql
 mysql-cluster-7.5-community/x86_64 MySQL Cluster 7.5 Community   disabled
 mysql-cluster-7.5-community-source MySQL Cluster 7.5 Community - disabled
 mysql-cluster-7.6-community/x86_64 MySQL Cluster 7.6 Community   disabled
 mysql-cluster-7.6-community-source MySQL Cluster 7.6 Community - disabled
 mysql-connectors-community/x86_64  MySQL Connectors Community    enabled:     95
 mysql-connectors-community-source  MySQL Connectors Community -  disabled
 mysql-tools-community/x86_64       MySQL Tools Community         enabled:     84
 mysql-tools-community-source       MySQL Tools Community - Sourc disabled
 mysql-tools-preview/x86_64         MySQL Tools Preview           disabled
 mysql-tools-preview-source         MySQL Tools Preview - Source  disabled
 mysql55-community/x86_64           MySQL 5.5 Community Server    disabled
 mysql55-community-source           MySQL 5.5 Community Server -  disabled
 mysql56-community/x86_64           MySQL 5.6 Community Server    disabled
 mysql56-community-source           MySQL 5.6 Community Server -  disabled
 mysql57-community/x86_64           MySQL 5.7 Community Server    disabled
 mysql57-community-source           MySQL 5.7 Community Server -  disabled
 mysql80-community/x86_64           MySQL 8.0 Community Server    enabled:     82
 mysql80-community-source           MySQL 8.0 Community Server -  disabled

 b.假如我们是要安装5.7版本,按如下操作(禁用8.0,启用5.7,最后验证)
     shell> sudo yum-config-manager --disable mysql80-community 
     shell> sudo yum-config-manager --enable mysql57-community
     shell> yum repolist all | grep mysql
    c.如果系统没有安装yum-config-manager工具,也可以直接编辑文件/etc/yum.repos.d/mysql-community.repo,指定enabled属性。
     注意只能设置最多一个版本的enabled=1
3、安装MySQL
        shell> sudo yum install mysql-community-server
      系统会自动创建mysql用户组,mysql用户,设置目录权限等等
      This installs the package for MySQL server (mysql-community-server) 
                    and also packages for the components required to run the server,
          including packages for the client (mysql-community-client), the common error messages 
                    and character sets for client and server (mysql-community-common),
                    and the shared client libraries (mysql-community-libs).
4、启动MySQL
     Start the MySQL server with the following command:

       shell> sudo service mysqld start
       Starting mysqld:[ OK ]
 You can check the status of the MySQL server with the following command:

      shell> sudo service mysqld status
       mysqld (pid 3066) is running.
 At the initial start up of the server, the following happens, given that the data directory of the server is empty:
    The server is initialized.
    SSL certificate and key files are generated in the data directory.
    validate_password is installed and enabled.
    A superuser account 'root'@'localhost is created. A password for the superuser is set and stored in the error log file. To reveal it, use the following command:
    shell> sudo grep 'temporary password' /var/log/mysqld.log
    Change the root password as soon as possible by logging in with the generated, temporary password and set a custom password for the superuser account:
    shell> mysql -uroot -p 
    mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass4!';
    
    Note
    validate_password is installed by default. The default password policy implemented by validate_password requires that passwords contain at least one upper case letter, 
           one lower case letter, one digit, and one special character, and that the total password length is at least 8 characters.
5、使用yum安装其他产品和组件
 查看仓库中的组件
 shell> sudo yum --disablerepo=\* --enablerepo='mysql*-community*' list available
 安装组件
 shell> sudo yum install package-name
6、使用yum更新
 Besides installation, you can also perform updates for MySQL products and components using the MySQL Yum repository. See Section 2.11.5, “Upgrading MySQL with the MySQL Yum Repository” for details. 

7、登陆、修改默认密码、设置远程登陆

 a.获取临时密码
  shell> sudo grep 'temporary password' /var/log/mysqld.log
   b.登陆
       shell> mysql -uroot -p 
   c. 修改默认密码
      mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass4!';
   d.设置远程登陆
     --设置root账户的host地址(修改了才可以远程连接)
     mysql>grant all privileges on *.* to 'root'@'%' identified by 'MyNewPass4!';
     mysql>flush privileges;
     --查看表
     mysql> use mysql;
     mysql> select host,user from user;
     --这里就可以使用远程连接测试了;

 --如果不行,可能需要开启端口
 firewall-cmd --query-port=3306/tcp
 firewall-cmd --add-port=3306/tcp --permanent
 firewall-cmd --reload

8、配置自动启动
 systemctl enable mysqld
 systemctl daemon-reload

9、修改字符集

# cat /etc/my.cnf
#
# This group is read both both by the client and the server
# use it for options that affect everything
#
[client-server]

#
# include all files from the config directory
#
!includedir /etc/my.cnf.d

[mysqld]
 
init_connect='SET collation_connection = utf8_general_ci'
 
init_connect='SET NAMES utf8'
 
character-set-server=utf8
 
collation-server=utf8_general_ci


验证(全部为utf-8为正常)
MySQL> show variables like "%character%";show variables like "%collation%";

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值