20191209_Centos7.2使用yum安装mysql

时间:2021-08-27 07:13:47

1. 下载mysql的rpm包

[[email protected] ~]# wget http://dev.mysql.com/get/mysql57-community-release-el7-7.noarch.rpm

2. 安装rpm包

[[email protected] ~]# yum localinstall -y mysql57-community-release-el7-7.noarch.rpm

3. 安装mysql 5.7

[[email protected] ~]# yum install -y mysql-community-server

4. 启动mysql 5.7

[[email protected] ~]# systemctl start mysqld.service

5. 查看数据库的状态:

service mysql status

6. MySQL在5.7安装完成之后有一个默认密码, 查看默认密码:

[[email protected] ~]# grep ‘temporary password‘ /var/log/mysqld.log
2019-12-09T04:21:12.283622Z 1 [Note] A temporary password is generated for [email protected]: b;M%;tBXw5E8

7. 修改默认密码:

[[email protected] ~]# mysql -u root -p
Enter password:  --使用上面的密码进入mysql
mysql> set password = password(‘yourpassword‘);
Query OK, 0 rows affected, 1 warning (0.00 sec) mysql> alter user ‘root‘@‘localhost‘ password expire never; Query OK, 0 rows affected (0.00 sec) mysql> flush privileges; Query OK, 0 rows affected (0.00 sec) mysql> quit; --退出后再使用密码登陆

8. 赋远程访问权限:

mysql> grant all privileges on *.* to ‘root‘@‘%‘ IDENTIFIED BY ‘yourpassword‘ WITH GRANT OPTION;
Query OK, 0 rows affected, 1 warning (0.00 sec)

9. 看下防火墙:

[[email protected] ~]# firewall-cmd  --list-all
FirewallD is not running

10. 我这里防火墙没有运行直接可以使用navicat远程访问了, 默认端口3306

11. 关于防火墙:

1. 查看防火墙
firewall-cmd --list-all 
2. 加入3306端口
firewall-cmd --permanent --add-port=3306/tcp
3. 重启防火墙
service firewalld restart
4. 查看3306是否开放
 firewall-cmd --query-port=3306/tcp
-----------------------------------------------------------
5. 查看防火墙状态
systemctl status firewalld.service
6. 关闭防火墙
systemctl stop firewalld.service
7. 启动防火墙
systemctl start firewalld
8. 开机禁用防火墙
systemctl disable firewalld
9. 开机启用防火墙
systemctl enable firewalld