> mysql安裝5.7,確定不是mariadb
* [ ] .rpm?-Uvh?http://dev.mysql.com/get/mysql-community-release-el6-5.noarch.rpm #下載
* [ ] .yum?install?yum-utils?-y #裝源
* [ ] .yum-config-manager?--disable?mysql56-community? ?#?禁用MySQL5.6的源
* [ ] .yum-config-manager?--enable?mysql57-community-dmr?#?啟用MySQL5.7的源
* [ ] .yum?repolist?enabled?|?grep?mysql
* [ ] .yum?install?mysql-community-server? #安裝mysql
>先卸載mariaDb
```
yum remove mariadb
刪除配置文件:
rm -f /etc/my.cnf
刪除數據目錄:
rm -rf /var/lib/mysql/
```
>可能會報錯的地方
1. mysql-community-server-5.7.20-1.el6.x86_64 (mysql57-community)需要libsasl2.so.2()(64bit)
* 解決方法
修改 源文件(vim /etc/yum.repos.d/mysql-community.repo):
```
[mysql57-community]
name=MySQL 5.7 Community Server
## baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/6/$basearch/ ??
##修改這里
baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/7/$basearch/
enabled=1
##修改這里:
gpgcheck=0
##修改這里:
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql? ?
```
2.舊的安裝包和現在的沖突
```
Transaction check error:
file /usr/share/mysql/charsets/Index.xml from install of mysql-community-common-5.7.27-1.el7.x86_64 conflicts with file from package MariaDB-common-10.2.18-1.el7.centos.x86_64
```
* 解決方法(刪除舊的安裝包)
rpm -e MariaDB-common-10.2.18-1.el7.centos.x86_64 --nodeps
>安裝
yum?install?mysql-community-server
>啟動
```
systemctl ?start mysqld? ? ? ? ?#啟動mysql
systemctl ?status mysqld? ? ? #查看mysql啟動狀態
```
>修改密碼
1. 查詢初始密碼(grep 'temporary password' /var/log/mysqld.log )
2. mysql -uroot -p
3. 輸入剛才查詢的初始密碼
4. 設置密碼校驗關閉和密碼長度設置允許為0
~~~
set global validate_password_policy=0;
set global validate_password_length=0;
~~~
5. 修改初始密碼(SET PASSWORD = PASSWORD('abc1233');)
6. 如果要修改密碼為空,必須要關掉密碼校驗,否則會出現
**Your password does not satisfy the current policy requirements**
7. 降低密碼校驗長度,密碼校驗長度由多個值組成,需要全部設置為0
```
SHOW VARIABLES LIKE 'validate_password%';
```

```
set global validate_password_mixed_case_count=0;
set global validate_password_number_count=0;
set global validate_password_special_char_count=0;
set global validate_password_length=0;
```
這樣就可以設置密碼為空了
8. 設置密碼為空
```
update user set authentication_string=password('') where user='root' and host='localhost';
```
5.7的mysql或者maria字段是password
9. 刷新權限
```
flush privileges;
```