基于centos7.2安装mariadb数据库
一、安装mariadb数据库
客户端:yum -y install mariadb
服务端:yum -y install mariadb-server
二、配置mariadb数据库
1.开启服务
启动服务:systemctl start mariadb
设置开机自启动:systemclt enable mariadb
2.初始设置
[root@localhost ~]# mysql_secure_installation
Enter current password for root (enter for none): # 首次安装后没有密码,直接回车
Set root password? [Y/n] # y
New password: # 新密码
Re-enter new password: # 再次输入
Remove anonymous users? [Y/n] # y
Disallow root login remotely? [Y/n] # 拒绝root远程登录,n,不管y/n,都会拒绝root远程登录
Remove test database and access to it? [Y/n] # 删除test数据库,y:删除。可以不删选:n
Reload privilege tables now? [Y/n] # 重新加载权限表,y。
3.登录数据库
[root@localhost ~]# mysql -uroot -p
三、修改字符编码
[root@localhost ~]# vim /etc/my.cnf.d/server.cnf
在[mysqld]后添加:
init_connect='SET collation_connection = utf8_unicode_ci' init_connect='SET NAMES utf8' character-set-server=utf8 collation-server=utf8_unicode_ci skip-character-set-client-handshake
重启mariadb数据库:
[root@localhost ~]# systemctl restart mariadb.service
四、远程连接数据库
设置防火墙:
[root@localhost ~]# firewall-cmd --query-port=3306/tcp #查看是否开启
no
[root@localhost ~]# firewall-cmd --zone=public --add-port=3306/tcp --permanent #开启端口
success
[root@localhost ~]# firewall-cmd --reload #重启防火墙
success
[root@localhost ~]# firewall-cmd --query-port=3306/tcp #查询已开启端口
yes
修改授权表:
MariaDB [(none)]> use mysql;
MariaDB [mysql]> select host,user from user;
+-----------------------+------+
| host | user |
+-----------------------+------+
| 127.0.0.1 | root |
| ::1 | root |
| localhost | root |
| localhost.localdomain | root |
+-----------------------+------+
4 rows in set (0.00 sec)
MariaDB [mysql]> update user set host="%" where host="127.0.0.1"; #把127.0.0.1改为%,所有的ip都可以登录
MariaDB [mysql]> flush privileges;
参考链接:https://www.cnblogs.com/gyxpy/p/12995164.html
(小白初次上手 不足之处欢迎各位大佬指点)