# 安装MariaDB ## 删除旧版本 centos7下默认安装有mariadb数据库,但是是旧版本,在安装新版本前需要先把旧版本删除,有些系统还默认安装mysql,也必须删除,否则与mariadb会产生冲突. ``` [root@localhost ~] rpm -qa | grep mariadb ``` ## 创建 MariaDB.repo 在目录下 /etc/yum.repos.d/ 创建文件: MariaDB.repo 并把以下内容添加到所建文件中 ``` [mariadb] name = MariaDB baseurl = http://mirrors.aliyun.com/mariadb/yum/10.4/centos7-amd64/ gpgkey = http://mirrors.aliyun.com/mariadb/yum/RPM-GPG-KEY-MariaDB gpgcheck = 1 ``` ## 安装 使用yum命令安装MariaDB数据库。 ``` [root@localhost ~] yum install MariaDB-client MariaDB-server ``` ## MariaDB服务配置命令 ``` [root@localhost ~] systemctl start mariadb #启动服务 [root@localhost ~] systemctl enable mariadb #设置开机启动 [root@localhost ~] systemctl restart mariadb #重新启动 [root@localhost ~] systemctl stop mariadb.service #停止MariaDB ``` ## 初始化MariaDB /usr/bin/mysql_secure_installation ## 配置远程访问 ``` # 登录mysql [root@localhost ~] mysql # 配置所有IP可以访问 MariaDB [(none)]> create user 'root'@'%' identified by '2009)$@!'; # 给用户最大权限 MariaDB [(none)]> grant all privileges on *.* to 'root'@'%' identified by '2009)$@!'; MariaDB [(none)]> flush privileges; MariaDB [(none)]> exit ```