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%";

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章