http://blog.csdn.net/xyang81/article/details/51759200
安裝環(huán)境:CentOS7 64位 MINI版,安裝MySQL5.7
1驾霜、配置YUM源
在MySQL官網(wǎng)中下載YUM源rpm安裝包:http://dev.mysql.com/downloads/repo/yum/
[圖片上傳失敗...(image-c9f7b1-1548084901726)]
# 下載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.*"
看到上圖所示表示安裝成功
2父叙、安裝MySQL
shell> yum install mysql-community-server
3、啟動MySQL服務(wù)
shell> systemctl start mysqld
查看MySQL的啟動狀態(tài)
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.
4、開機啟動
shell> systemctl enable mysqld
shell> systemctl daemon-reload
5邑闺、修改root默認密碼
直接登錄是登錄不上的季俩,因為不知道密碼如圖:
mysql安裝完成之后,在/var/log/mysqld.log文件中給root生成了一個默認密碼雀瓢。通過下面的方式找到root默認密碼枢析,然后登錄mysql進行修改:
shell> grep 'temporary password' /var/log/mysqld.log
或
grep "password" /var/log/mysqld.log
-
然后粘貼這個密碼就可登錄了,如圖:
-
如果學(xué)習(xí)的話密碼想設(shè)置簡單一點刃麸,還可以修改安全策略醒叁,即通過圖上這種方式:
-
實際操作圖:
-
修改為簡單密碼:
數(shù)據(jù)庫授權(quán),數(shù)據(jù)庫沒有授權(quán)泊业,只支持localhost本地訪問
mysql>GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;
-
至此mysql數(shù)據(jù)庫已經(jīng)安裝完畢:
下面為另一種詳細設(shè)置策略
接著上面第5點開始:
mysql安裝完成之后把沼,在/var/log/mysqld.log文件中給root生成了一個默認密碼。通過下面的方式找到root默認密碼吁伺,然后登錄mysql進行修改:
shell> grep 'temporary password' /var/log/mysqld.log
shell> mysql -uroot -p
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass4!';
或者
mysql> set password for 'root'@'localhost'=password('MyNewPass4!');
注意:mysql5.7默認安裝了密碼安全檢查插件(validate_password)饮睬,默認密碼檢查策略要求密碼必須包含:大小寫字母、數(shù)字和特殊符號篮奄,并且長度不能少于8位捆愁。否則會提示ERROR 1819 (HY000): Your password does not satisfy the current policy requirements錯誤,如下圖所示:
[圖片上傳失敗...(image-e96eca-1548084901725)]
通過msyql環(huán)境變量可以查看密碼策略的相關(guān)信息:
mysql> show variables like '%password%';
[圖片上傳失敗...(image-96a4bb-1548084901725)]
validate_password_policy:密碼策略窟却,默認為MEDIUM策略 validate_password_dictionary_file:密碼策略文件昼丑,策略為STRONG才需要 validate_password_length:密碼最少長度 validate_password_mixed_case_count:大小寫字符長度,至少1個 validate_password_number_count :數(shù)字至少1個 validate_password_special_char_count:特殊字符至少1個 上述參數(shù)是默認策略MEDIUM的密碼檢查規(guī)則间校。
共有以下幾種密碼策略:
策略 | 檢查規(guī)則 |
---|---|
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官網(wǎng)密碼策略詳細說明: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服務(wù)使配置生效:
systemctl restart mysqld
6滓彰、添加遠程登錄用戶
默認只允許root帳戶在本地登錄控妻,如果要在其它機器上連接mysql,必須修改root允許遠程連接揭绑,或者添加一個允許遠程連接的帳戶弓候,為了安全起見郎哭,我添加一個新的帳戶:
mysql> GRANT ALL PRIVILEGES ON *.* TO 'yangxin'@'%' IDENTIFIED BY 'Yangxin0917!' WITH GRANT OPTION;
7、配置默認編碼為utf8
修改/etc/my.cnf配置文件菇存,在[mysqld]下添加編碼配置夸研,如下所示:
[mysqld]
character_set_server=utf8
init_connect='SET NAMES utf8'
重新啟動mysql服務(wù),查看數(shù)據(jù)庫默認編碼如下所示:
[圖片上傳失敗...(image-27556-1548084901724)]
默認配置文件路徑: 配置文件:/etc/my.cnf 日志文件:/var/log//var/log/mysqld.log
mysql的數(shù)據(jù)文件和二進制文件:/var/lib/mysql/
服務(wù)啟動腳本:/usr/lib/systemd/system/mysqld.service socket文件:/var/run/mysqld/mysqld.pid
參考:
https://www.cnblogs.com/lgqboke/p/6873734.html
https://www.cnblogs.com/xiaopotian/p/8196464.html
https://www.cnblogs.com/weiok/p/5373270.html