Linux安装MySQL(清华大学镜像源)

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仓库里的连接开源软件镜像站

 
Linux安装MySQL(清华大学镜像源)
image.png
[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
 
Linux安装MySQL(清华大学镜像源)
image.png

6.初始化MySQL

查看初始化密码:
sudo grep ‘temporary password‘ /var/log/mysqld.log
 
Linux安装MySQL(清华大学镜像源)
image.png
使用初始密码进行登录:
mysql -u root -p
 
Linux安装MySQL(清华大学镜像源)
image.png
初始化密码
ALTER USER ‘root‘@‘localhost‘ IDENTIFIED BY ‘初始化密码‘;

7.设置MySQL密码策略

查询MySQL初始的密码策略

 SHOW VARIABLES LIKE ‘validate_password%‘; 
 
Linux安装MySQL(清华大学镜像源)
image.png

修改密码验证强度

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.远程连接

 
Linux安装MySQL(清华大学镜像源)

Linux安装MySQL(清华大学镜像源)

上一篇:平面模特拍的摄技巧分享


下一篇:oracle12514监听程序当前无法识别连接描述符中的服务