環境
OS:CentOS7.6
Mysql:Mysql5.7
- 獲取更新包
Mysql官網:https://dev.mysql.com/
到http://dev.mysql.com/downloads/repo/yum/ 去下載rpm包更新一下。#下載mysql源安裝包 wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm #安裝mysql源 yum localinstall mysql57-community-release-el7-8.noarch.rpm #檢測源是否安裝成功 yum repolist enabled | grep "mysql.*-community.*"
- 安裝
修改配置yum 安裝mysql的版本,這裏安裝MySQL5.7版本,修改“enabled=1”。
vim /etc/yum.repos.d/mysql-community.repo#Enable to use MySQL 5.6 [mysql56-community] name=MySQL 5.6 Community Server baseurl=http://repo.mysql.com/yum/mysql-5.6-community/el/7/$basearch/ enabled=0 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql [mysql57-community] name=MySQL 5.7 Community Server baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/7/$basearch/ enabled=1 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
yum安裝
yum install mysql-community-server
systemctl start mysqld //啓動mysql服務
systemctl status mysqld
systemctl enable mysqld
systemctl daemon-reload //重載服務 - 配置
mysql5.7安裝時會產生一個默認密碼,查看此密碼的文件一般存在於/var/log/mysqld.log上。
grep 'temporary password' /var/log/mysqld.log
登錄mysql
mysql -uroot -p
可看到mysql5.7版本默認登錄後要求修改密碼,採用了密碼機制,默認爲medium,要求密碼有大寫字母及特殊字符。
修改密碼:mysql> set password for 'root'@'localhost'=password('xxxxxxxx');
查看密碼策略:
mysql> show variables like '%password%'
0 => LOW,1 => MEDIUM,2 => STRONG
命令行修改:
set global validate_password_policy=0; //設置密碼策略等級
set global validate_password_length=6; //設置密碼最小長度
重啓mysql服務
systemctl restart mysqld