欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

Centos7使用yum安装MySQL以及如何实现远程连接

程序员文章站 2022-04-15 11:51:32
centos7使用yum安装mysql以及如何实现远程连接,因为mysql被oracle收购,目前推荐使用mariadb 步骤如下: 1)yum install mariadb...

centos7使用yum安装mysql以及如何实现远程连接,因为mysql被oracle收购,目前推荐使用mariadb

步骤如下:

1)yum install mariadb

2) yum install mariadb-server

3) yum install mariadb-devel

chmod -r 770 /var/lib/mysql

systemctl restart mariadb.service

至此mysql安装完成

初始化密码:

执行mysql命令,设置初始密码

set password for 'root'@'localhost' = password('input the password you like');

tips:

远程连接数据库:

1)mysql -u root -p password ;use mysql ;

grant all privileges on *.* to 'root'@'%' identified by 'root' with grant option; 允许任何ip以root用户登录

flush privileges;立即生效

2)修改my.cnf文件 注释掉bindaddress这句话,如果有的话

3)检查防火墙

systemctl status iptables.service /firewalld.service 并关闭

另外 如果不想关闭防火墙,那么可以添加规则,下面是使用命令添加

1)先确保防火墙已启动

2)执行命令 firewall-cmd --permanent(永久) --add-port=3306(默认端口)/tcp(协议) 响应 success

3) 执行命令查看规则添加是否成功 firewall-cmd --permanent --query-port=3306/tcp

4)重启防火墙生效 systemctl restart mariadb.service

all work is done, good luck!