1. 程式人生 > 其它 >centos7安裝MySQL5.7.28

centos7安裝MySQL5.7.28

配置yum源

// 1)下載
wget https://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm
// 2)安裝
rpm -ivh mysql57-community-release-el7-9.noarch.rpm
// 執行完成後會在/etc/yum.repos.d/目錄下生成兩個repo檔案mysql-community.repo mysql-community-source.repo
// 3)更新yum源
yum clean all
yum makecache
yum update

安裝及配置

// 1) 安裝MySQL-5.7.28
yum install mysql-server
// 2) 安裝完成後啟動mysql
systemctl start mysqld
// 3) 設定開機啟動
systemctl enable mysqld
// 4) 獲取安裝時的臨時密碼(在第一次登入時就是用這個密碼)
grep 'temporary password' /var/log/mysqld.log
// 5) 登入mysql
mysql -u root -p
// 然後輸入密碼(剛剛獲取的臨時密碼)
// 6) 登入後修改root密碼
ALTER USER 'root'@'localhost' IDENTIFIED BY '@abcd123456'; 
// 注意:mysql5.7預設安裝了密碼安全檢查外掛(validate_password),預設密碼檢查策略要求密碼必須包含:大小寫字母、數字和特殊符號,並且長度不能少於8// 位。否則會提示ERROR 1819 (HY000): Your password does not satisfy the current policy requirements錯誤
// 不需要此策略可以進行修改
// 在/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

// 7) 新增遠端登入使用者
create user 'pyjsh'@'localhost' identified by 'pyjsh';
grant all on *.* to pyjsh@'%' identified by 'pyjsh';
grant all on *.* to pyjsh@'localhost' identified by 'pyjsh';
flush privileges;

// 8) 配置預設編碼為utf8
// 修改/etc/my.cnf配置檔案,在[mysqld]下新增編碼配置,如下所示:
[mysqld]
character_set_server=utf8
init_connect='SET NAMES utf8'
// 重新啟動mysql服務使配置生效
systemctl restart mysqld

預設配置檔案路徑

    配置檔案:/etc/my.cnf  
    日誌檔案:/var/log/mysqld.log  
 服務啟動指令碼:/usr/lib/systemd/system/mysqld.service  
  socket檔案:/var/run/mysqld/mysqld.pid