CentOS7-64 環境 MySQL5.7安裝與配置(YUM)

按照原文安裝後自己整理,原文地址:http://www.linuxidc.com/Linux/2016-09/135288.htm

賬號:root 密碼:Zhangle123456!

賬號:admin  密碼:Admin123456!


service mysqld start
service mysqld stop

service mysqld restart

mysql -uroot -p


默認配置文件路徑: 
配置文件:/etc/my.cnf 
日誌文件:/var/log//var/log/mysqld.log 
服務啓動腳本:/usr/lib/systemd/system/mysqld.service 
socket文件:/var/run/mysqld/mysqld.pid

1、配置YUM源

# 官網下載路徑,下載mysql源安裝包
shell> wget  http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm
# 安裝mysql源
shell> yum localinstall mysql57-community-release-el7-8.noarch.rpm
#檢查mysql源是否安裝成功
shell> yum repolist enabled | grep "mysql.*-community.*"
#出現如下代碼:
mysql-connectors-community/x86_64   MySQL Connectors Community     42
mysql-tools-community/x86_64             MySQL Tools Community               55
mysql57-community/x86_64                  MySQL 5.7 Community Server         227

2、安裝MySQL
shell> yum install mysql-community-server
3、啓動MySQL服務
shell> systemctl start mysqld
4、查看MySQL的啓動狀態

     shell> systemctl status mysqld

         顯示如下:

        mysqld.service - MySQL Server

        Loaded: loaded (/usr/lib/systemd/system/mysqld.service; disabled; vendor preset: disabled)

        Active: active (running) since 五 2016-06-24 04:37:37 CST; 35min ago

         Main PID: 2888 (mysqld)
         CGroup: /system.slice/mysqld.service

         └─2888 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid

        6月 24 04:37:36 localhost.localdomain systemd[1]: Starting MySQL Server...
        6月 24 04:37:37 localhost.localdomain systemd[1]: Started MySQL Server.


5、設置開機啓動

    shell>
systemctl enable mysqld
    shell> systemctl daemon-reload


6、修改root本地登錄密碼

        mysql安裝完成之後,在/var/log/mysqld.log文件中給root生成了一個默認密碼。

        通過下面的方式找到root默認密碼,然後登錄mysql進行修改:

        shell> grep 'temporary password' /var/log/mysqld.log

        顯示如下:

2018-03-01T03:43:04.000704Z 1 [Note] A temporary password is generated for root@localhost: CcyrIPRKk5=K
其中默認密碼爲最後的:CcyrIPRKk5=K

       shell> mysql -uroot -p
       Enter password:    //輸入上面查到的密碼 CcyrIPRKk5=K
    出現如下界面:
        Welcome to the MySQL monitor.  Commands end with ; or \g.
        Your MySQL connection id is 4
        Server version: 5.7.21
        Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
        Oracle is a registered trademark of Oracle Corporation and/or its
        affiliates. Other names may be trademarks of their respective
        owners.
        Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

    #輸入命令:
    mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'Zhangle123456'; 
    或者
    mysql> set password for 'root'@'localhost'=password('Zhangle123456'); 

    注意:mysql5.7默認安裝了密碼安全檢查插件(validate_password),默認密碼檢查策略要求密碼必須包含:大小寫字母、數字和特殊符號,並且長度不能少於8位。否則會提示ERROR 1819 (HY000): Your password does not satisfy the current policy requirements錯誤,

#重新輸入複雜密碼
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'Zhangle123456!';
Query OK, 0 rows affected (0.00 sec)


以下是密碼策略,可跳過:
    密碼策略提示
    通過msyql環境變量可以查看密碼策略的相關信息:
    mysql> show variables like '%password%';
    #顯示如下:
    +---------------------------------------+--------+
    | Variable_name                         | Value  |
    +---------------------------------------+--------+
    | default_password_lifetime             | 0      |
    | disconnect_on_expired_password        | ON     |
    | log_builtin_as_identified_by_password | OFF    |
    | mysql_native_password_proxy_users     | OFF    |
    | old_passwords                         | 0      |
    | report_password                       |        |
    | sha256_password_proxy_users           | OFF    |
    | validate_password_check_user_name     | OFF    |
    | validate_password_dictionary_file     |        |
    | validate_password_length              | 8      |
    | validate_password_mixed_case_count    | 1      |
    | validate_password_number_count        | 1      |
    | validate_password_policy              | MEDIUM |
    | validate_password_special_char_count  | 1      |
    +---------------------------------------+--------+
    14 rows in set (0.04 sec)

    validate_password_dictionary_file:密碼策略文件,策略爲STRONG才需要 
    validate_password_length:密碼最少長度 
    validate_password_mixed_case_count:大小寫字符長度,至少1個 
    validate_password_number_count :數字至少1個 
    validate_password_policy:密碼策略,默認爲MEDIUM策略 
    validate_password_special_char_count:特殊字符至少1個 
    上述參數是默認策略MEDIUM的密碼檢查規則。


    共有以下幾種密碼策略:

    策略 檢查規則
    0 or LOW Length
    1 or MEDIUM Length; numeric, lowercase/uppercase, and special characters
    2 or STRONG Length; numeric, lowercase/uppercase, and special characters; dictionary file
 MySQL官網密碼策略詳細說明:http://dev.mysql.com/doc/refman/5.7/en/validate-password-options-variables.html#sysvar_validate_password_policy

    修改密碼策略
    在/etc/my.cnf文件添加validate_password_policy配置,指定密碼策略
    # 選擇0(LOW),1(MEDIUM),2(STRONG)其中一種,選擇2需要提供密碼字典文件
    validate_password_policy=0
    如果不需要密碼策略,添加my.cnf文件中添加如下配置禁用即可:
    validate_password = off
    重新啓動mysql服務使配置生效:
    systemctl restart mysqld

7、添加遠程登錄用戶
    默認只允許root帳戶在本地登錄,如果要在其它機器上連接mysql,必須修改root允許遠程連接,或者添加一個允許遠程連接的帳戶,爲了安全起見,我添加一個新的帳戶:
mysql> GRANT ALL PRIVILEGES ON *.* TO admin'@'%' IDENTIFIED BY 'Admin123456!' WITH GRANT OPTION;

8、配置默認編碼爲utf8
        修改/etc/my.cnf配置文件
    vim  /etc/my.cnf
        在[mysqld]下添加編碼配置,如下所示:
    [mysqld]
    character_set_server=utf8
    init_connect='SET NAMES utf8'

        重新啓動mysql服務,
             systemctl restart mysqld
        登錄數據庫
             mysql -uroot -p 

        輸入密碼    //更改後的新密碼

        查看默認編碼如下所示:

         mysql>show variables like '%characters%';

         顯示如下:

        +--------------------------+----------------------------+
        | Variable_name            | Value                      |
        +--------------------------+----------------------------+
        | character_set_client     | utf8                       |
        | character_set_connection | utf8                       |
        | character_set_database   | utf8                       |
        | character_set_filesystem | binary                     |
        | character_set_results    | utf8                       |
        | character_set_server     | utf8                       |
        | character_set_system     | utf8                       |
        | character_sets_dir       | /usr/share/mysql/charsets/ |

        +--------------------------+----------------------------+

-------end-------

按照原文安裝後自己整理,原文地址:http://www.linuxidc.com/Linux/2016-09/135288.htm

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