【shell 每日一練7】一鍵安裝mysql5.7,以及密碼及策略修改

1、一鍵安裝Mysql腳本

[root@uat01 ~]# cat InstallMysql01.sh #!/bin/bash #2018-10-13 #旅行者-Travel #1.安裝wget yum -y install  wget #2、下載mysql的yum源 URL="https://repo.mysql.com//mysql80-community-release-el7-1.noarch.rpm"
wget $URL -P /etc/yum.repos.d/
yum -y install yum-utils   #若是沒有該包,下邊執行yum-config-manager不生效 yum -y install /etc/yum.repos.d/mysql80-community-release-el7-1.noarch.rpm if [ $? -eq 0 ];then
        rm -rf /etc/yum.repos.d/mysql80-community-release-el7-1.noarch*
    fi
yum-config-manager --disable mysql80-community yum-config-manager --enable mysql57-community yum -y install mysql-community-server sleep 5 systemctl start mysqld systemctl enable mysqld systemctl status mysqld if [ $? -eq 0 ];then
        echo -e "install succefull" result="`grep 'temporary password' /var/log/mysqld.log`" p1="`echo $result |awk '{print $NF}'`"
        echo "數據庫密碼爲:$p1"
    
    fi [root@uat01 ~]#

2、修改策略和密碼

執行完以上腳本能夠看到Mysql的密碼,以下方法登陸修改策略,由於默認密碼要求比較高,能夠根據本身需求來決定是否更改策略:mysql

install succefull 數據庫密碼爲:9aTR&ok>f;1K [root@uat01 ~]# mysql -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 2 Server version: 5.7.23 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> set global validate_password_policy=0; Query OK, 0 rows affected (0.00 sec) mysql> set global validate_password_length=4; Query OK, 0 rows affected (0.00 sec) mysql>  alter user 'root'@'localhost' identified by 'Yanglt123.'; Query OK, 0 rows affected (0.00 sec) mysql> flush privileges; Query OK, 0 rows affected (0.00 sec) mysql> quit

 3、數據庫密碼策略:

一、查看數據庫策略:sql

由於上文已經將 validate_password_length 值改成4,因此下文顯示爲4,默認狀況下爲8數據庫

[root@uat01 ~]# mysql -uroot -p ..... Server version: 5.7.23 MySQL Community 
...... mysql
> show variables like 'validate_password%'; +--------------------------------------+-------+ | Variable_name | Value | +--------------------------------------+-------+ | validate_password_check_user_name | OFF | | validate_password_dictionary_file | | | validate_password_length | 4 | | validate_password_mixed_case_count | 1 | | validate_password_number_count | 1 | | validate_password_policy | LOW | | validate_password_special_char_count | 1 | +--------------------------------------+-------+ 7 rows in set (0.00 sec) mysql>

二、各項值說明安全

validate_password_policy:密碼安全策略,默認MEDIUM策略bash

策略 檢查規則
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

 

 

 

    

validate_password_dictionary_file:密碼策略文件,策略爲STRONG才須要ide

validate_password_length:密碼最少長度 ,測試發現最小值得爲4。測試

validate_password_mixed_case_count:大小寫字符長度,至少1個ui

validate_password_number_count :數字至少1個 spa

validate_password_special_char_count:特殊字符至少1個code

三、修改策略,跟上文第二操做同樣

mysql> set global validate_password_policy=0; Query OK, 0 rows affected (0.00 sec) mysql> set global validate_password_length=4; Query OK, 0 rows affected (0.00 sec), mysql> flush privileges; Query OK, 0 rows affected (0.00 sec)

四、修改簡單密碼測試

mysql> alter user 'root'@'localhost' identified by '1234'; #測試發現密碼長度最少爲4位 Query OK, 0 rows affected (0.00 sec) mysql> flush privileges; Query OK, 0 rows affected (0.01 sec) mysql> quit Bye [root@uat01 ~]# mysql -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 5 Server version: 5.7.23 MySQL Community Server (GPL) 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>
相關文章
相關標籤/搜索