安裝環境:CentOS7 64位,MySQL5.7
<code># 下載下傳mysql源安裝包</code>
<code>shell> wget http:</code><code>//dev</code><code>.mysql.com</code><code>/get/mysql57-community-release-el7-8</code><code>.noarch.rpm </code>
<code># 安裝mysql源 </code>
<code>shell> yum localinstall mysql57-community-release-el7-8.noarch.rpm</code>
檢查mysql源是否安裝成功
<code>shell> yum repolist enabled | </code><code>grep</code> <code>"mysql.*-community.*"</code>
<code>shell> yum </code><code>install</code> <code>mysql-community-server</code>
<code>shell> systemctl start mysqld</code>
檢視MySQL的啟動狀态
<code>shell> systemctl status mysqld</code>
<code>shell> systemctl </code><code>enable</code> <code>mysqld </code>
<code>shell> systemctl daemon-reload</code>
mysql安裝完成之後,在/var/log/mysqld.log檔案中給root生成了一個預設密碼。通過下面的方式找到root預設密碼,然後登入mysql進行修改:
<code>shell> </code><code>grep</code> <code>'temporary password'</code> <code>/var/log/mysqld</code><code>.log</code>
<code>shell> mysql -uroot -pmysql> ALTER USER </code><code>'root'</code><code>@</code><code>'localhost'</code> <code>IDENTIFIED BY </code><code>'MyNewPass4!'</code><code>;</code>
或者
<code>mysql> </code><code>set</code> <code>password </code><code>for</code> <code>'root'</code><code>@</code><code>'localhost'</code><code>=password(</code><code>'MyNewPass4!'</code><code>);</code>
注意:mysql5.7預設安裝了密碼安全檢查插件(validate_password),預設密碼檢查政策要求密碼必須包含:大小寫字母、數字和特殊符号,并且長度不能少于8位。否則會提示ERROR 1819 (HY000): Your password does not satisfy the current policy requirements錯誤,如下圖所示:
通過msyql環境變量可以檢視密碼政策的相關資訊:
<code>mysql> show variables like </code><code>'%password%'</code><code>;</code>
validate_password_policy:密碼政策,預設為MEDIUM政策 validate_password_dictionary_file:密碼政策檔案,政策為STRONG才需要 validate_password_length:密碼最少長度 validate_password_mixed_case_count:大小寫字元長度,至少1個 validate_password_number_count :數字至少1個 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
在/etc/my.cnf檔案添加validate_password_policy配置,指定密碼政策
<code># 選擇0(LOW),1(MEDIUM),2(STRONG)其中一種,選擇2需要提供密碼字典檔案</code>
<code>validate_password_policy=0</code>
如果不需要密碼政策,添加my.cnf檔案中添加如下配置禁用即可:
<code>validate_password = off</code>
重新啟動mysql服務使配置生效:
<code>systemctl restart mysqld</code>
預設隻允許root帳戶在本地登入,如果要在其它機器上連接配接mysql,必須修改root允許遠端連接配接,或者添加一個允許遠端連接配接的帳戶,為了安全起見,我添加一個新的帳戶:
<code>mysql> GRANT ALL PRIVILEGES ON *.* TO </code><code>'USERNAME'</code><code>@</code><code>'%'</code> <code>IDENTIFIED BY </code><code>'PWD'</code> <code>WITH GRANT OPTION;</code>
修改/etc/my.cnf配置檔案,在[mysqld]下添加編碼配置,如下所示:
<code>[client]</code>
<code>default-character-</code><code>set</code><code>=utf8</code>
然後重新啟動mysql服務即可。
預設配置檔案路徑:
配置檔案:/etc/my.cnf
日志檔案:/var/log//var/log/mysqld.log
服務啟動腳本:/usr/lib/systemd/system/mysqld.service
socket檔案:/var/run/mysqld/mysqld.pid
--------------------------------------------------------------------------------------------------------------------
原文連結:http://blog.csdn.net/xyang81/article/details/51759200
本文轉自 羽豐1995 51CTO部落格,原文連結:http://blog.51cto.com/13683137989/1932239