安裝環境:CentOS7 64位 MINI版,安裝MySQL5.7html
在MySQL官網中下載YUM源rpm安裝包:https://dev.mysql.com/downloads/repo/yum/
mysql
# 下載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源是否安裝成功linux
shell> yum repolist enabled | grep "mysql.*-community.*"
看到上圖所示表示安裝成功。
sql
shell> yum install mysql-community-server
shell> systemctl start mysqld
查看MySQL的啓動狀態shell
shell> systemctl status mysqld
shell> systemctl enable mysqld shell> systemctl daemon-reload
mysql安裝完成以後,在/var/log/mysqld.log文件中給root生成了一個默認密碼。經過下面的方式找到root默認密碼,而後登陸mysql進行修改:安全
shell> grep 'temporary password' /var/log/mysqld.log
shell> mysql -u root -p mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass4!';
或者bash
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%';
MySQL官網密碼策略詳細說明:http://dev.mysql.com/doc/refman/5.7/en/validate-password-options-variables.html#sysvar_validate_password_policyspa
在/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
默認配置文件路徑:
配置文件:/etc/my.cnf
日誌文件:/var/log//var/log/mysqld.log
服務啓動腳本:/usr/lib/systemd/system/mysqld.service
socket文件:/var/run/mysqld/mysqld.pid
若是忘記root密碼,則按以下操做恢復:
在[mysqld]的段中加上一句:skip-grant-tables 保存而且退出vi。
mysql -u root
update mysql.user set authentication_string=password('123qwe') where user='root' and Host = 'localhost';
flush privileges