在CentOS7上安装MariaDB10.4

参考资料

官方网站 产品文档 Galera cluster

添加REPO文件

使用vi或者vim编辑/etc/yum.repos.d/MariaDB.repo文件,把下面的内容复制到文件中然后保存退出。

            [mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.4/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1
        

执行安装操作然后启动服务

            yum -y install MariaDB-server MariaDB-client
systemctl enable mariadb
systemctl start mariadb
        

创建用户并授权

安装完成后,我们可以直接在本机登录MariaDB,然后进行授权。授权操作需要特别注意的一点是用%通配所有地址时不能代替localhost,所以如果我们是在本机用localhost访问,一定要再进行一次授权。授权完成后一定要刷新权限,否则不生效。详细内容可以参考下面的示例。

            grant all privileges on *.* to 'username'@'%' identified by 'password' with grant option;
grant all privileges on *.* to 'username'@'localhost' identified by 'password' with grant option;
flush privileges;
        

验证服务

授权后,我们使用新的帐号登录MariaDB,如果能成功连接说明配置成功了。我们还需要使用其他机器进行连接,测试一下非本机是否可以连接MariaDB。如果连接失败请检查防火墙是否有限制。

            mysql -u username -p password
mysql -h x.x.x.x -u username -p password