CentOS7下安裝MySQL5.7安裝與配置(YUM)

http://blog.csdn.net/xyang81/article/details/51759200html

安裝環境:CentOS7 64位 MINI版,安裝MySQL5.7mysql

一、配置YUM源

MySQL官網中下載YUM源rpm安裝包:http://dev.mysql.com/downloads/repo/yum/ 
sql

# 下載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

shell> yum repolist enabled | grep "mysql.*-community.*"

 
看到上圖所示表示安裝成功數據庫

二、安裝MySQL

shell> yum install mysql-community-server

三、啓動MySQL服務

shell> systemctl start mysqld

查看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.

四、開機啓動

shell> systemctl enable mysqld shell> systemctl daemon-reload

五、修改root默認密碼

mysql安裝完成以後,在/var/log/mysqld.log文件中給root生成了一個默認密碼。經過下面的方式找到root默認密碼,而後登陸mysql進行修改:bash

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

shell> mysql -uroot -p mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass4!'; 

或者dom

mysql> set password for 'root'@'localhost'=password('MyNewPass4!'); 

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

經過msyql環境變量能夠查看密碼策略的相關信息:ui

mysql> show variables like '%password%';



  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

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

六、添加遠程登陸用戶

默認只容許root賬戶在本地登陸,若是要在其它機器上鍊接mysql,必須修改root容許遠程鏈接,或者添加一個容許遠程鏈接的賬戶,爲了安全起見,我添加一個新的賬戶:

mysql> GRANT ALL PRIVILEGES ON *.* TO 'yangxin'@'%' IDENTIFIED BY 'Yangxin0917!' WITH GRANT OPTION;

七、配置默認編碼爲utf8

修改/etc/my.cnf配置文件,在[mysqld]下添加編碼配置,以下所示:

[mysqld] character_set_server=utf8 init_connect='SET NAMES utf8'

從新啓動mysql服務,查看數據庫默認編碼以下所示:


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

相關文章
相關標籤/搜索