centos7 mysql 安裝配置

來源:互聯網
上載者:User

標籤:密碼   href   erro   systemd   border   grant   mysql安裝   src   release   

1、配置Yum源

在mysql官網中下載Yum源rpm安裝包

# 下載mysql源安裝包

shell> wget https://repo.mysql.com//mysql57-community-release-el7-11.noarch.rpm

# 安裝mysql源

shell> yum install mysql57-community-release-el7-11.noarch.rpm

 

檢查mysql源是否安裝成功

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

 

2、安裝mysql

shell> yum install mysql-community-server

 

3、啟動mysql服務

shell> systemctl start mysqld

查看MySQL的啟動狀態

shell> systemctl status mysqld

 

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

 

shell> mysql -uroot -p

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錯誤

 

通過msyql環境變數可以查看密碼原則的相關資訊:

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

 

修改密碼原則

在/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

6、設定mysql遠端存取

預設只允許root帳戶在本地登入,如果要在其它機器上串連mysql,必須修改root允許遠端連線:

mysql> GRANT ALL PRIVILEGES ON *.* TO [email protected]‘%‘ IDENTIFIED BY ‘[email protected]‘ WITH GRANT OPTION;

 

7、配置預設編碼為utf8

修改/etc/my.cnf設定檔,在[mysqld]下添加編碼配置,如下所示:

[mysqld]

character_set_server=utf8

init_connect=‘SET NAMES utf8‘

 

重新啟動mysql服務,查看資料庫預設編碼如下所示:

mysql>show variables like ‘%character%’;

預設設定檔路徑:  設定檔:/etc/my.cnf  記錄檔:/var/log//var/log/mysqld.log  服務啟動指令碼:/usr/lib/systemd/system/mysqld.service  socket檔案:/var/run/mysqld/mysqld.pid

centos7 mysql 安裝配置

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.