centos7下通過yum安裝mysql5 7

2021-08-19 10:50:21 字數 4031 閱讀 4207

第一部分:centos 7安裝mysql 5.7

shell > wget

2.安裝yum庫

shell > yum localinstall -y mysql57-community-release-el7-7.noarch.rpm

3.安裝資料庫

shell > yum install -y mysql-community-server

4.啟動mysql服務

shell > systemctl start mysqld.service

5、修改root密碼

mysql安裝完成之後,在/var/log/mysqld.log檔案中為root使用者生成了乙個隨機的預設密碼。可以通過以下方式檢視,之後可登陸mysql進行修改:

#grep 'temporary password' /var/log/mysqld.log

這裡需要注意:mysql5.7預設的密碼檢查策略要求密碼必須包含:大小寫字母、數字和特殊符號,並且長度不能少於8位。否則會提示error 1819 (hy000): your password does not satisfy the current policy requirements錯誤。

通過msyql環境變數可以檢視密碼策略的相關資訊:

說明: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的密碼檢查規則。

validate_password_policy:密碼策略,預設為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配置,來指定密碼策略,如下:

validate_password_policy=0 #0(low),1(medium),2(strong)其中一種,注意2需要提供密碼字典檔案

如果不需要密碼策略,新增my.cnf檔案中新增如下配置禁用即可:

[plain]

view plain

copy

validate_password = off  

修改完後記得需要重新啟動mysql服務

shell > mysql -uroot -p

6.重置root密碼後重啟mysql服務

shell > update mysql.user set authentication_string=password("yourpassword") where user="root" and host="localhost";

shell > flush privileges;

shell > quit;

shell > systemctl restart mysqld;

如果手賤或者不知道啥原因出現如下問題:

error 1045 (28000): access denied for user 'root'@'localhost' (using password: no)

請修改my.cnf,新增skip-grant-tables和skip-networking:

shell > vi /etc/my.cnf

[mysqld]

skip-grant-tables

skip-networking

重啟mysql,然後重複以上修改密碼步驟即可,記得修改完後,去掉my.cnf新增的兩行。

第二部分:配置

1、新增遠端登入使用者(登入mysql)

use mysql;

grant all privileges on *.* to 'root'@'%' identified by '你的密碼' with grant option;

注:'%'代表任意位址,也可以指定ip

2、檢查使用者表,重新整理記憶體許可權

3、設定防火牆(centos7 不推薦)

vi /etc/sysconfig/iptables

在-a rh-firewall-1-input -j reject –reject-with icmp-host-prohibited之前,新增

-a input -m state --state new -m tcp -p tcp --dport 3306 -j accept

重啟防火牆

service iptables restart

注:centos7使用的是firewall防火牆

systemctl stop firewalld.service #停止

systemctl disable firewalld.service #禁用

4、設定字元編碼集和區分大小寫

4.1修改mysql配置檔案(設定字元編碼集)

預設位置:/etc/my.cnf

進入etc資料夾》vim my.cnf

* systemctl restart mysql.service #重啟mysql

* 檢視當前mysql執行狀態

mysql>status

引數說明:

haracter_set_client:客戶端請求資料的字符集。

character_set_connection:從客戶端接收到資料,然後傳輸的字符集。

character_set_database:預設資料庫的字符集,無論預設資料庫如何改變,都是這個字符集;如果沒有預設資料庫,使character_set_server指定的字符集,此引數無需設定。

character_set_filesystem:把作業系統上檔名轉化成此字符集,即把character_set_client轉換character_set_filesystem,預設binary即可。

character_set_results:結果集的字符集。

character_set_server:資料庫伺服器的預設字符集。

character_set_system:這個值總是utf8,不需要設定,儲存系統元資料的字符集。

4.2修改mysql配置檔案(設定區分大小寫)

lower_case_table_names 引數詳解:

0:區分大小寫

1:不區分大小寫

下面看下修改後的預覽圖:

centos7下通過yum安裝nginx及配置

1.安裝 因centos7預設的源中沒有nginx,所以需要先安裝nginx的庫,然後通過yum安裝即可 rpm uvh 2.配置中遇到的問題 i.修改主目錄訪問的時候提示403,找不到 解決辦法 確保selinux是關閉狀態 可以臨時關閉 setenforce 0 主目錄需要有執行許可權,建議設定...

CentOS7下通過yum安裝p7zip

雲ecs主機上,沒有裝p7zip,然後通過yum安裝,發現也沒有這樣包。再仔細檢查了下,發現本機環境中,沒有啟用epel源,致使通過yum無法安裝p7zip包。檢視資料得知,p7zip在yum epel repository中,但本機沒有epel源 通過該命令查詢本機使用的yum repositor...

centos7通過yum安裝mysql

yum list installed grep mysql 如果有的話 就全部解除安裝 yum y remove 資料庫名稱yum search libaio 檢索相關資訊 yum install libaio 安裝依賴包如果找不到wget命令則先yum install wget wget新增 my...