linux 環境下安裝MySQL5.7(yum)

安裝環境:html

  CentOS7 64位,MySQL5.7mysql

原文連接:http://www.javashuo.com/article/p-fptazdwa-bh.htmlsql

1. 配置yum源數據庫

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

 複製連接,而後wgetsocket

下載MySQL源安裝包ui

wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm

 安裝MySQL源編碼

yum localinstall mysql57-community-release-el7-8.noarch.rpm

 檢查MySQL源是否安裝成功.net

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

  

 安裝MySQL:插件

yum install mysql-community-server

啓動sql服務

systemctl start mysqld

查看MySQL啓動的狀態

systemctl status mysqld
[root@192 sql]# systemctl status mysqld
● mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: active (running) since Wed 2019-09-25 05:23:26 EDT; 16s ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
  Process: 2071 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OP)
  Process: 1979 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
 Main PID: 2074 (mysqld)
   CGroup: /system.slice/mysqld.service
           └─2074 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid

Sep 25 05:23:22 192.168.142.131 systemd[1]: Starting MySQL Server...
Sep 25 05:23:26 192.168.142.131 systemd[1]: Started MySQL Server.

 設置開機啓動

systemctl enable mysqld
systemctl daemon-reload

 修改root本地登錄密碼

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

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

  

mysql -uroot -p
ALTER USER 'root'@'localhost' IDENTIFIED BY'原始密碼'

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

 

經過環境變量查看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

修改密碼:

set password=password('123456');

重啓MySQL服務:

systemctl restart mysqld

設置默認編碼爲utf8

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

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

重啓服務,查看數據庫編碼

show variables like '%character%';

 

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

相關文章
相關標籤/搜索