CentOs7自带MariaDB数据库,MariaDB是mysql的分支,和mysql基本一样,下面介绍下配置MariaDB
使用命令启动服务
systemctl start mariadb.service
修改root密码
mysqladmin -u root -p password [new password]
后面的 [new password] 是要设置的密码
回车后出现 Enter password
输入就密码,如果没有,直接回车
查看mariadb编码
show variables like ‘%col%’
本例 collation_server 字段不是utf8
修改文件 /etc/my.cnf
在[mysqld]字段下添加:
character-set-server = utf8
重新启动mariadb服务
systemctl stop mariadb.service
systemctl start mariadb.service
systemctl enable mariadb ==> 开机自启动
配置端口,开放3306端口,这里把8080,80也一并开放,
firewall-cmd --zone=public --permanent --add-port=3306/tcp
firewall-cmd --zone=public --permanent --add-port=3306/tcp
firewall-cmd --zone=public --permanent --add-port=3306/tcp
端口配置完成后重启防火墙
firewall 常用命令
# 重启
service firewalld restart
# 开启
service firewalld start
# 关闭
service firewalld stop
# 查看firewall 服务状态
systemctl status firewall
# 查看防火墙
firewall-cmd --list-all
防火墙重启后,可以看到端口已经开放
接下来配置使数据库开放对外连接
首先进入数据库,连接方式和mysql一样
mysql -uroot -p
输入你的密码,第一次进入是没有密码的
# 针对ip
create user 'root'@'192.168.10.10' identified by 'password';
#全部
create user 'root'@'%' identified by 'password';
建议还是针对于ip开放吧,不要全部开放
授权用户:
# 给用户最大权限
grant all privileges on *.* to 'root'@'%' identified by '你想设置的密码';
# 给部分权限(test 数据库)
grant all privileges on test.* to 'root'@'%' identified by '你想设置的密码' with grant option;
# 刷新权限表
flush privileges;
# show grants for 'root'@'localhost';
接下来就是可以本地连接了