一、下載 首先進入官網 https://dev.mysql.com/downloads/mysql/ 選擇 Red Hat Enterprise Linux 7 / Oracle Linux 7 分別將 ① mysql community server 5.7.19 1.el7.x86_64.rpm ...
一、下載
首先進入官網
https://dev.mysql.com/downloads/mysql/
選擇 Red Hat Enterprise Linux 7 / Oracle Linux 7
分別將
① mysql-community-server-5.7.19-1.el7.x86_64.rpm
② mysql-community-client-5.7.19-1.el7.x86_64.rpm
③ mysql-community-common-5.7.19-1.el7.x86_64.rpm
④ mysql-community-libs-5.7.19-1.el7.x86_64.rpm
下載下來。
(下載之後的路徑在/root/下載,為了方便我將下載包移到了/opt下麵)
二、檢查卸載mariadb-lib
檢查
[root@localhost opt]# rpm -qa|grep mariadb
mariadb-libs-5.5.52-1.el7.x86_64
卸載
[root@localhost opt]# rpm -e mariadb-libs-5.5.52-1.el7.x86_64 --nodeps
三、安裝mysql-server
rpm -ivh mysql-community-common-5.7.19-1.el7.x86_64.rpm mysql-community-libs-5.7.19-1.el7.x86_64.rpm mysql-community-client-5.7.19-1.el7.x86_64.rpm mysql-community-server-5.7.19-1.el7.x86_64.rpm
也就是將步驟1裡面下載的幾個裝上,但要註意順序,先是common,再是libs,client,最後是server
四、修改root本地密碼
安裝完成後,在
/var/log/mysqld.log
文件暗中給root生成一個隨機預設密碼:
[root@localhost opt]#grep 'temporary password' /var/log/mysqld.log
然後進入/var/lib/mysql中,開啟服務
[root@localhost mysql]# systemctl start mysqld.service
然後cd退出來查看密碼
[root@localhost ~]# cat /var/log/mysqld.log |grep password
2017-08-14T08:10:48.442103Z 1 [Note] A temporary password is generated for root@localhost: :EYc>?fvn4UT知道密碼後登陸mysql
[root@localhost ~]# mysql -uroot -p
Enter password:登陸成功後顯示如下:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.7.19
Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.最後設置密碼
mysql>set password for 'root'@'localhost'=password('12345678');
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements註意:mysql5.7預設安裝了密碼安全檢查插件,預設密碼檢查策略要求密碼必須包含:大小寫字母,數字和特殊符號,並且長度不少於8位。否則就會提示錯誤:ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
五、 查看密碼策略相關信息
mysql> show variables like '%password%';
● validate_password_dictionary_file:密碼策略文件,策略為STRONG才需要
● validate_password_policy:密碼策略,預設為MEDIUM策略
● validate_password_length:密碼最少長度
● validate_password_mixed_case_count:大小寫字元長度,最少1位
● validate_password_number_count:數字最少1位
● validate_password_special_char_count:特殊字元最少一位
共有以下幾種密碼策略:
策略檢查規則
0 or LOW length
1 or MEDIUM length,numeric,lowercase/uppercase and special characters
2 or STRONG length,numeric,lowercase/uppercase , special characters and dictionary file
修改密碼策略:
在/etc/my.cnf文件中添加validate_password_policy配置,制定密碼策略
validate_password_policy=0
如果不需要密碼策略,在文件中添加如下配置就行了:
validate_password=off
然後重啟mysql服務,使配置生效
systemctl restart mysqld
六、開機啟動
[root@localhost ~]# systemctl enable mysqld
[root@localhost ~]# systemctl daemon-reload
檢查Mysql服務是否已啟動
service mysqld status
只要服務啟動,在/var/lib/mysql下麵就會自動生成mysql.sock文件
可用find / -name mysql.sock 搜索是否生成了該文件
七、設置防火牆遠程訪問
開放3306埠
[root@localhost ~]# firewall-cmd --permanent --add-port=3306/tcp重新載入防火牆
[root@localhost ~]# firewall-cmd --reload查看防火牆配置
[root@localhost ~]# firewall-cmd --list-all
public (active)
target: default
icmp-block-inversion: no
interfaces: ens33
sources:
services: dhcpv6-client ssh
ports: 3306/tcp
protocols:
masquerade: no
forward-ports:
sourceports:
icmp-blocks:
rich rules:
八、熟悉預設配置文件路徑
- 配置文件:/etc/my.cnf
- 日誌文件:/var/log/mysqld.log
- 伺服器啟本:/usr/lib/systemd/system/mysqld.service
- 進入mysql命令行:
mysql -u用戶名 -p密碼