1.下載並安裝MySQL官方的 Yum Repository
//下載 [root@localhost ~]# wget http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm //安裝 [root@localhost ~]# yum -y install mysql57-community-release-el7-10.noarch.rpm
2.更換repo倉庫里的連接開源軟件鏡像站
[mysql-connectors-community] name=MySQL Connectors Community baseurl=https://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql-connectors-community-el7-$basearch/ enabled=1 gpgcheck=1 gpgkey=https://repo.mysql.com/RPM-GPG-KEY-mysql[mysql-tools-community]
name=MySQL Tools Community
baseurl=https://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql-tools-community-el7-$basearch/
enabled=1
gpgcheck=1
gpgkey=https://repo.mysql.com/RPM-GPG-KEY-mysql[mysql-5.6-community]
name=MySQL 5.6 Community Server
baseurl=https://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql-5.6-community-el7-$basearch/
enabled=0
gpgcheck=1
gpgkey=https://repo.mysql.com/RPM-GPG-KEY-mysql[mysql-5.7-community]
name=MySQL 5.7 Community Server
baseurl=https://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql-5.7-community-el7-$basearch/
enabled=1
gpgcheck=1
gpgkey=https://repo.mysql.com/RPM-GPG-KEY-mysql
[mysql-8.0-community]
name=MySQL 8.0 Community Server
baseurl=https://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql-8.0-community-el7-$basearch/
enabled=0//默認安裝最新版本,因為自己要安裝5.7,所有把enabled=1改成enabled=0
gpgcheck=1
gpgkey=https://repo.mysql.com/RPM-GPG-KEY-mysql
3.安裝MySQL
sudo yum install -y mysql-community-server
4.啟動MySQL
sudo service mysqld start
5.查看MySQL服務狀態
sudo service mysqld status
6.初始化MySQL
查看初始化密碼:
sudo grep 'temporary password' /var/log/mysqld.log
使用初始密碼進行登錄:
mysql -u root -p
初始化密碼 ALTER USER 'root'@'localhost' IDENTIFIED BY '初始化密碼';
7.設置MySQL密碼策略
查詢MySQL初始的密碼策略
SHOW VARIABLES LIKE 'validate_password%';
修改密碼驗證強度
set global validate_password_policy=LOW;
修改密碼長度
set global validate_password_length=6;
設置簡單密碼
ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
8.設置MySQL遠程連接,在sql里面設置
//這里設置登錄密碼和遠程連接密碼都是123456 GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION; //刷新權限 FLUSH PRIVILEGES;
9.設置 MySQL開機啟動
systemctl enable mysqld
設置3306端口開放
firewall-cmd --zone=public --add-port=3306/tcp --permanent //重啟防火牆 firewall-cmd --reload //驗證3306是否開放成功 firewall-cmd --zone=public --query-port=3306/tcp
10.遠程連接
