欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

CentOS7中安装MariaDB

程序员文章站 2023-11-10 22:03:40
安装方式 在线安装(慢的要命) RPM离线安装(CentOS7.X) 在线安装 1. 打开官方网站 "https://mariadb.org/" 2. 点击 "Download" ,跳转到下一页面 3. 继续点击 "Download" ,进到下页 4. 点击红框中的[链接] (https://dow ......

安装方式

  • 在线安装(慢的要命)
  • rpm离线安装(centos7.x)

在线安装

  1. 打开官方网站
    CentOS7中安装MariaDB
  2. 点击download,跳转到下一页面
    CentOS7中安装MariaDB
  3. 继续点击download,进到下页
    CentOS7中安装MariaDB
  4. 点击红框中的[链接] (https://downloads.mariadb.org/mariadb/repositories/#mirror=23media),进到一下页面
    CentOS7中安装MariaDB
  5. 根据自己的服务器的类型/版本来选择要安装的数据库版本.
    按照上述步骤可以在线安装。

离线安装

  1. 点击图4中的
    CentOS7中安装MariaDB
  2. 点击, 可以看到一堆rpm包,不要着急,继续看下一步
    CentOS7中安装MariaDB
  3. 打开mariadb org --> learn --> [mariadb knowledge base] --> mariadb server -->

    getting, installing, and upgrading mariadb --> mariadb binary packages --> installing mariadb rpm files --> mariadb installation (version 10.1.21) via rpms on centos 7

    最终的url点击之后,就可以看到如下图所示界面:
    CentOS7中安装MariaDB
    本来完全可以提供最终的一个url,提供一步一步点击的按钮连接,是为了方便大家来学习路线思路,而不能只拿结果。
  4. 还记得我们之前第二步看到的一堆rpm包吗? 下载第三步方框中的package,当然,这个文档的版本稍有点落后,但是我们只需要搜索前缀名称就行了,比如搜索client:
    CentOS7中安装MariaDB
    我们下载最新版本就可以了。
    接下来进入正式步骤了哦~:
    在图7中有step by step installation:

step by step installation:

  • 1) first install all of the dependencies needed. its easy to do this via yum packages: yum install rsync nmap lsof perl-dbi nc
  • 2) rpm -ivh jemalloc-3.6.0-1.el7.x86_64.rpm
  • 3) rpm -ivh jemalloc-devel-3.6.0-1.el7.x86_64.rpm
  • 4) rpm -ivh mariadb-10.1.21-centos7-x86_64-common.rpm mariadb-10.1.21-centos7-x86_64-compat.rpm mariadb-10.1.21-centos7-x86_64-client.rpm galera-25.3.19-1.rhel7.el7.centos.x86_64.rpm mariadb-10.1.21-centos7-x86_64-server.rpm

按照步骤我们开始:

  1. 安装依赖信息,命令行执行:

    [root@iz2ze7s2v0b78922wia32rz software]#  yum install rsync nmap lsof perl-dbi nc
  2. 安装我们之前下载的版本jemalloc-3.6.0-1.el7.x86_64.rpm

    [root@iz2ze7s2v0b78922wia32rz mariadb]# rpm -ivh jemalloc-3.6.0-1.el7.x86_64.rpm 
  3. 安装jemalloc-devel-3.6.0-1.el7.x86_64.rpm

    [root@iz2ze7s2v0b78922wia32rz mariadb]# rpm -ivh jemalloc-devel-3.6.0-1.el7.x86_64.rpm
  4. 安装剩余的mariadb相关的包,一定要注意顺序.common > compat > client > galera > server

    [root@iz2ze7s2v0b78922wia32rz mariadb]# rpm -ivh mariadb-common-10.4.8-1.el7.centos.x86_64.rpm mariadb-compat-10.4.8-1.el7.centos.x86_64.rpm mariadb-client-10.4.8-1.el7.centos.x86_64.rpm galera-4-26.4.3-1.rhel7.el7.centos.x86_64.rpm mariadb-server-10.4.8-1.el7.centos.x86_64.rpm 
    warning: mariadb-common-10.4.8-1.el7.centos.x86_64.rpm: header v4 dsa/sha1 signature, key id 1bb943db: nokey
    error: failed dependencies:
            mariadb-libs < 1:10.1.0 conflicts with mariadb-compat-10.4.8-1.el7.centos.x86_64
            mariadb-libs is obsoleted by mariadb-compat-10.4.8-1.el7.centos.x86_64
            libaio.so.1()(64bit) is needed by mariadb-client-10.4.8-1.el7.centos.x86_64
            libaio.so.1(libaio_0.1)(64bit) is needed by mariadb-client-10.4.8-1.el7.centos.x86_64
            libaio.so.1(libaio_0.4)(64bit) is needed by mariadb-client-10.4.8-1.el7.centos.x86_64
            libboost_program_options.so.1.53.0()(64bit) is needed by galera-4-26.4.3-1.rhel7.el7.centos.x86_64
            libaio.so.1()(64bit) is needed by mariadb-server-10.4.8-1.el7.centos.x86_64
            libaio.so.1(libaio_0.1)(64bit) is needed by mariadb-server-10.4.8-1.el7.centos.x86_64
            libaio.so.1(libaio_0.4)(64bit) is needed by mariadb-server-10.4.8-1.el7.centos.x86_64

    执行之后发现报错,还是在图7显示页面,我们可以看见step by step installation: 段落结束之后有这么一句: here is the error message for dependencies:

    # rpm -ivh mariadb-10.1.21-centos7-x86_64-common.rpm 
    warning: mariadb-10.1.21-centos7-x86_64-common.rpm: header v4 dsa/sha1 signature, key id 1bb943db: nokey
    error: failed dependencies:
       mariadb-libs < 1:10.1.21-1.el7.centos conflicts with mariadb-common-10.1.21-1.el7.centos.x86_64

    是不是和我们的错误很相似?按照官方提供的solution就可以解决了。

    后续还有几个错误,同样按照官方给出的解决方案处理,一步一步就搞定了,如下:

    [root@iz2ze7s2v0b78922wia32rz mariadb]# rpm -qa | grep mariadb-libs
    mariadb-libs-5.5.60-1.el7_5.x86_64
    [root@iz2ze7s2v0b78922wia32rz mariadb]# rpm -ev --nodeps mariadb-libs-5.5.60-1.el7_5.x86_64
    preparing packages...
    mariadb-libs-1:5.5.60-1.el7_5.x86_64
    [root@iz2ze7s2v0b78922wia32rz mariadb]# rpm -qa | grep mariadb-libs                        
    [root@iz2ze7s2v0b78922wia32rz mariadb]# yum install boost-devel.x86_64
    loaded plugins: fastestmirror
    loading mirror speeds from cached hostfile
    resolving dependencies
    --> running transaction check
    ...
    is this ok [y/d/n]: y
    ...
    
    complete!
    [root@iz2ze7s2v0b78922wia32rz mariadb]# rpm --import http://yum.mariadb.org/rpm-gpg-key-mariadb

    然后重新回到安装的第四步:

    [root@iz2ze7s2v0b78922wia32rz mariadb]# rpm -ivh mariadb-common-10.4.8-1.el7.centos.x86_64.rpm mariadb-compat-10.4.8-1.el7.centos.x86_64.rpm mariadb-client-10.4.8-1.el7.centos.x86_64.rpm galera-4-26.4.3-1.rhel7.el7.centos.x86_64.rpm mariadb-server-10.4.8-1.el7.centos.x86_64.rpm 
    error: failed dependencies:
            libaio.so.1()(64bit) is needed by mariadb-client-10.4.8-1.el7.centos.x86_64
            libaio.so.1(libaio_0.1)(64bit) is needed by mariadb-client-10.4.8-1.el7.centos.x86_64
            libaio.so.1(libaio_0.4)(64bit) is needed by mariadb-client-10.4.8-1.el7.centos.x86_64
            libaio.so.1()(64bit) is needed by mariadb-server-10.4.8-1.el7.centos.x86_64
            libaio.so.1(libaio_0.1)(64bit) is needed by mariadb-server-10.4.8-1.el7.centos.x86_64
            libaio.so.1(libaio_0.4)(64bit) is needed by mariadb-server-10.4.8-1.el7.centos.x86_64

    发现还是报错???

    CentOS7中安装MariaDB

    这个是官方在10.4.8中新引入的一个问题,需要下载一个依赖包libaio:

    [root@iz2ze7s2v0b78922wia32rz mariadb]# wget http://mirror.centos.org/centos/6/os/x86_64/packages/libaio-0.3.107-10.el6.x86_64.rpm
    --2019-11-28 10:52:26--  http://mirror.centos.org/centos/6/os/x86_64/packages/libaio-0.3.107-10.el6.x86_64.rpm

    下载成功之后,安装一下当前下载的依赖包:

    [root@iz2ze7s2v0b78922wia32rz mariadb]# rpm -ivh libaio-0.3.107-10.el6.x86_64.rpm

然后再一次重复step 4:

[root@iz2ze7s2v0b78922wia32rz mariadb]# rpm -ivh mariadb-common-10.4.8-1.el7.centos.x86_64.rpm mariadb-compat-10.4.8-1.el7.centos.x86_64.rpm mariadb-client-10.4.8-1.el7.centos.x86_64.rpm galera-4-26.4.3-1.rhel7.el7.centos.x86_64.rpm mariadb-server-10.4.8-1.el7.centos.x86_64.rpm 
preparing...                          ################################# [100%]
updating / installing...
   1:mariadb-compat-10.4.8-1.el7.cento################################# [ 20%]
   2:mariadb-common-10.4.8-1.el7.cento################################# [ 40%]
   3:mariadb-client-10.4.8-1.el7.cento################################# [ 60%]
   4:galera-4-26.4.3-1.rhel7.el7.cento################################# [ 80%]
   5:mariadb-server-10.4.8-1.el7.cento################################# [100%]


two all-privilege accounts were created.
one is root@localhost, it has no password, but you need to
be system 'root' user to connect. use, for example, sudo mysql
the second is mysql@localhost, it has no password either, but
you need to be the system 'mysql' user to connect.
after connecting you can set the password, if you would need to be
able to connect as any of these users with a password and without sudo

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/

终于安装成功了。。。
CentOS7中安装MariaDB

接下来,最后一步配置数据库:

# 启动mariadb,(因为mariadb是mysql作者写的新的数据库,其实服务和mysql是一样的,所以启动使用的是下面)
[root@iz2ze7s2v0b78922wia32rz ~]# service mysql start
# 安全配置
[root@iz2ze7s2v0b78922wia32rz ~]# mysql_secure_installation
# 输入root密码,安装后第一次启动为空,直接回车
enter current password for root (enter for none): 
# step 1: 是否切换到unix_socket安全认证,否
switch to unix_socket authentication [y/n] n
# step 2: 更改密码,选择修改
change the root password? [y/n] y
# step 3: 移除匿名用户,选择是
remove anonymous users? [y/n] y
# step 4: 是否允许root远程登录,根据个人需求,因为我是测试服务器选择允许
disallow root login remotely? [y/n] y
# step 5: 移除test数据库
remove test database and access to it? [y/n] y
# step 6: 重新加载权限表
reload privilege tables now? [y/n] y
# 看到下面,说明成功啦!!!
all done!  if you've completed all of the above steps, your mariadb
installation should now be secure.
thanks for using mariadb!

测试

登录数据库:

[root@iz2ze7s2v0b78922wia32rz ~]# mysql -u root -p

修改root远程连接权限

mariadb [(none)]> grant all privileges on *.* to 'root'@'%' identified by 'your password';
query ok, 0 rows affected (0.001 sec)

mariadb [(none)]> flush privileges;
query ok, 0 rows affected (0.000 sec)

客户端远程连接

CentOS7中安装MariaDB