centos7.3+nginx1.8+php7.1+mysql5.7 安裝(三安裝mysql)
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
- 1
- 2
- 3
- 4
- 1
- 2
- 3
- 4
檢查mysql源是否安裝成功
shell> yum repolist enabled | grep "mysql.*-community.*"
- 1
- 1
看到上圖所示表示安裝成功。
可以修改vim /etc/yum.repos.d/mysql-community.repo
2、安裝MySQL
shell> yum install mysql-community-server
- 1
- 1
3、啟動MySQL服務
shell> systemctl start mysqld
- 1
- 1
檢視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.
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
4、開機啟動
shell> systemctl enable mysqld
shell> systemctl daemon-reload
- 1
- 2
- 1
- 2
5、修改root本地登入密碼
mysql安裝完成之後,在/var/log/mysqld.log檔案中給root生成了一個預設密碼。通過下面的方式找到root預設密碼,然後登入mysql進行修改:
shell> grep 'temporary password' /var/log/mysqld.log
- 1
- 1
shell> mysql -uroot -p
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass4!';
- 1
- 2
- 1
- 2
或者
mysql> set password for 'root'@'localhost'=password('MyNewPass4!');
- 1
- 1
注意:mysql5.7預設安裝了密碼安全檢查外掛(validate_password),預設密碼檢查策略要求密碼必須包含:大小寫字母、數字和特殊符號,並且長度不能少於8位。否則會提示ERROR 1819 (HY000): Your password does not satisfy the current policy requirements錯誤,如下圖所示:
通過msyql環境變數可以檢視密碼策略的相關資訊:
mysql> show variables like '%password%';
- 1
- 1
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配置,指定密碼策略
# 選擇0(LOW),1(MEDIUM),2(STRONG)其中一種,選擇2需要提供密碼字典檔案
validate_password_policy=0
- 1
- 2
- 1
- 2
如果不需要密碼策略,新增my.cnf檔案中新增如下配置禁用即可:
validate_password = off
- 1
- 1
重新啟動mysql服務使配置生效:
systemctl restart mysqld
- 1
- 1
6、新增遠端登入使用者
預設只允許root帳戶在本地登入,如果要在其它機器上連線mysql,必須修改root允許遠端連線,或者新增一個允許遠端連線的帳戶,為了安全起見,我新增一個新的帳戶:
mysql> GRANT ALL PRIVILEGES ON *.* TO 'yangxin'@'%' IDENTIFIED BY 'Yangxin0917!' WITH GRANT OPTION;
- 1
- 1
7、配置預設編碼為utf8
修改/etc/my.cnf配置檔案,在[mysqld]下新增編碼配置,如下所示:
[client]
default-character-set = utf8mb4
[mysql]
default-character-set = utf8mb4
[mysqld]
character-set-client-handshake = FALSE
character-set-server = utf8mb4
collation-server = utf8mb4_general_ci
init_connect='SET NAMES utf8mb4'
- 1
- 2
- 3
- 1
- 2
- 3
重新啟動mysql服務,檢視資料庫預設編碼如下所示:
//資料庫字符集等
show variables
like'
character
%';
//排序字符集
show variables
like '
collation
%';
預設配置檔案路徑:
配置檔案:/etc/my.cnf
日誌檔案:/var/log//var/log/mysqld.log
服務啟動指令碼:/usr/lib/systemd/system/mysqld.service
socket檔案:/var/run/mysqld/mysqld.pid