Centos7 x86_64 安装MariaDB

本文介绍如何在CentOS7上安装并配置MariaDB数据库。首先需要移除系统默认的Mysql/MariaDB,然后可以通过yum源或RPM包进行安装。文中详细介绍了两种安装方法的具体步骤,并给出了配置MariaDB的指导。

1. 全部删除系统自带的Mysql/MariaDB

  • MySQL 已经不再包含在 CentOS 7 的源中,而改用了 MariaDB;MySQL 已经不再包含在 CentOS 7 的源中,而改用了 MariaDB;如果存在,使用:

    sudo rpm -e –nodeps mariadb-* //全部删除

    或者:

    sudo yum remove mysql mysql-server mysql-libs compat-mysql51

2.安装 MariaDB

MariaDB有三种安装方式,源码安装、yum安装、rpm离线包安装。
源码安装很麻烦,还会遇到一些错误,不建议新手使用。所以这里给出yum 和rpm 离线包安装两种方式。

yum 安装

  • 添加MariaDB的yum源

sudo vim /etc/yum.repos.d/MariaDB.repo

将下面的内容粘贴进去:

# MariaDB 10.0 CentOS repository list - created 2017-01-04 03:11 UTC
# http://downloads.mariadb.org/mariadb/repositories/
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.0/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1

  • 安装 MariaDB

    sudo yum install MariaDB-server MariaDB-client


如果想安装其他版本的MariaDB 可以参考 MariaDB官网。 yum源安装的好处是简单方便,通过简单的命令行yum 会帮你全部搞定,但是可能对有些网速不好的朋友来说,yum安装速度会慢的让你无法忍受,还会出现用户退出安装。下面就可以通过rpm 离线包安装

使用RPM包离线安装MariaDB 10.1.20

  • 进入MariaDB官网下载MariaDB需要的RPM包

    我是centos7 64 选 10.1.20 —> centos7-amd64—>rpms ,需要下载:
    MariaDB-10.1.20-centos7-x86_64-common.rpm
    MariaDB-10.1.20-centos7-x86_64-compat.rpm
    galera-25.3.19-1.rhel7.el7.centos.x86_64.rpm
    jemalloc-3.6.0-1.el7.x86_64.rpm
    jemalloc-devel-3.6.0-1.el7.x86_64.rpm
    MariaDB-10.1.20-centos7-x86_64-client.rpm
    MariaDB-10.1.20-centos7-x86_64-server.rpm
    接下来:

    sudo rpm -ivh XXX.rpm

如果还需要其他依赖,请自行搜索安装^_^

3. 配置MariaDB

After the installation completes, start MariaDB with:

sudo systemctl start mariadb

sudo systemctl start mysql.service
sudo systemctl stop mysql.service

//好使

service mysql start

设置root密码

mysqladmin -u root password ‘root’

登录数据库

mysql -u root -p

如果从其它机器登录:

mysql -h ip地址 -u root -p

PLEASE REMEMBER TO SET A PASSWORD FOR THE MariaDB root USER !
To do so, start the server, then issue the following commands:

‘/usr/bin/mysqladmin’ -u root password ‘new-password’
‘/usr/bin/mysqladmin’ -u root -h localhost.localdomain password ‘new-password’

Alternatively you can run:
‘/usr/bin/mysql_secure_installation’

which will also give you the option of removing the test
databases and anonymous user created by default. This is
strongly recommended for production servers.

See the MariaDB Knowledgebase at http://mariadb.com/kb or the
MySQL manual for more instructions.

Please report any problems at http://mariadb.org/jira

The latest information about MariaDB is available at http://mariadb.org/.
You can find additional information about the MySQL part at:
http://dev.mysql.com
Consider joining MariaDB’s strong and vibrant community:
https://mariadb.org/get-involved/

安装 `MariaDB-server-10.11.9-1.el7.centos.x86_64` 时提示 "requires galera-4 but none of the providers can be installed",可以尝试以下解决办法: ### 1. 检查软件源 确保系统的软件源配置正确,并且包含了 `galera-4` 的提供者。可以通过以下命令更新软件源: ```bash yum clean all yum makecache ``` ### 2. 添加官方 MariaDB 软件源 如果默认的软件源中没有 `galera-4`,可以添加 MariaDB 官方软件源。创建 `/etc/yum.repos.d/mariadb.repo` 文件,并添加以下内容: ```ini [mariadb] name = MariaDB baseurl = http://yum.mariadb.org/10.11/centos7-amd64 gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB gpgcheck=1 ``` 然后再次更新软件源: ```bash yum clean all yum makecache ``` ### 3. 手动安装 `galera-4` 可以从 MariaDB 官方网站下载 `galera-4` 的 RPM 包,然后手动安装: ```bash wget https://downloads.mariadb.com/MariaDB/mariadb-galera-4-26.4.10-1.el7.x86_64.rpm yum localinstall mariadb-galera-4-26.4.10-1.el7.x86_64.rpm ``` ### 4. 检查依赖关系 使用 `yum whatprovides` 命令检查哪个包提供了 `galera-4`: ```bash yum whatprovides galera-4 ``` 根据输出结果安装相应的包。 ### 5. 禁用冲突的软件源 有时候,其他软件源可能会与 MariaDB 软件源冲突。可以尝试禁用一些不必要的软件源,然后再次尝试安装: ```bash yum-config-manager --disable <repo-name> ``` ### 6. 升级系统 确保系统已经安装了所有可用的更新: ```bash yum update ``` ### 7. 强制安装 如果以上方法都无法解决问题,可以尝试使用 `--skip-broken` 选项强制安装: ```bash yum install --skip-broken MariaDB-server-10.11.9-1.el7.centos.x86_64 ``` 但这种方法可能会导致系统存在未解决的依赖问题,不建议轻易使用
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值