1.首先下载mysql的安装包:
wget https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm
2.如果报错:-bash: wget: 未找到命令
说明服务器上面没有安装wget工具,我们先安装下wget
yum -y install wget
3.安装mysql
yum -y localinstall mysql57-community-release-el7-11.noarch.rpm
4.在线安装mysql服务端
yum -y install mysql-community-server
下载的东西比较多 要等一会
5.启动mysql服务
systemctl start mysqld
6.设置mysql为开机启动;
systemctl enable mysqld
systemctl daemon-reload
7.修改root本地登录密码 (先找到root用户的临时密码,登录MySQL服务,再执行修改命令)
mysql安装完成之后,在/var/log/mysqld.log文件中给root生成了一个临时的默认密码
vi /var/log/mysqld.log
找到这一行:2019-09-15T08:19:41.074255Z 1 [Note] A temporary password is generated for root@localhost: m4sot1K>%k,
这里的临时密码是:m4sot1K>%k,
mysql -u root -p
输入临时密码 进入mysql命令行
ALTER USER ‘root’@‘localhost’ IDENTIFIED BY ‘YangYang#250’;
修改密码YangYang#250 (备注 mysql5.7默认密码策略要求密码必须是大小写字母数字特殊字母的组合,至少8位)
有的版本mysql设置密码方式 SET PASSWORD = PASSWORD('YangYang250#')
关闭防火墙
查看防火墙状态
[tzhang@tzhang ~]$ sudo service iptables status
Table: filter
Chain INPUT (policy ACCEPT)
num target prot opt source destination
1 ACCEPT all -- 0.0.0.0/0 0.0.0.0/0 state RELATED,ESTABLISHED
2 ACCEPT icmp -- 0.0.0.0/0 0.0.0.0/0
3 ACCEPT all -- 0.0.0.0/0 0.0.0.0/0
4 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:22
5 REJECT all -- 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibited
Chain FORWARD (policy ACCEPT)
num target prot opt source destination
1 REJECT all -- 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibited
Chain OUTPUT (policy ACCEPT)
num target prot opt source destination
ACCEPT接受 REJECT拒绝
临时关闭
[tzhang@tzhang ~]$ service iptables stop
iptables: Setting chains to policy ACCEPT: filter [ OK ]
iptables: Flushing firewall rules: [ OK ]
iptables: Unloading modules: [ OK ]
[tzhang@tzhang ~]$ sudo service iptables status
iptables: Firewall is not running.
临时关闭,开机后,防火墙会重新开启
永久关闭
开机防火墙也不会启动
查看防火墙的开机启动设置
[tzhang@tzhang ~]$ chkconfig --list|grep iptables
iptables 0:off 1:off 2:on 3:on 4:on 5:on 6:off
设置开机不启动防火墙
[tzhang@tzhang ~]$ chkconfig iptables off
[tzhang@tzhang ~]$ chkconfig --list|grep iptables
iptables 0:off 1:off 2:off 3:off 4:off 5:off 6:off
mysql 设置允许远程登录
1、mysql>GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root's password' WITH GRANT OPTION //赋予任何主机访问数据的权限
2、mysql>FLUSH PRIVILEGES //修改生效
3、mysql>EXIT //退出MySQL服务器
这样就可以在其它任何的主机上以root身份登录啦!
报错:2003-can't connect to mysql server on ' ' (10038)
出现这个错误的原因是:远程3306端口未对外开放
在服务器上设置允许打开3306端口
配置安全组