在Centos 7下安装MariaDB简明教程
程序加油站 2017-02-20 14:48:46
本文将简要介绍如何在CentOS 7的环境下,安装Mariadb,配置用户和访问权限等类似操作。
- CentOS
Cent OS是业界中大名鼎鼎的RedHat红帽系统的开源编译版本,站在巨人的肩上是可以看得更高更远, 由于RedHat的Linux系统非常稳定和强大,且已经得到了业界的普遍认可,这一点从Red Hat的公司业绩就一目了然得感觉到。
由于Red Hat Linux系统是基于开源的Linux系统而来,故其的代码需要进行开源,所以我们才可以见得到Centos系统,其是基于Red Hat Linux开源的源代码编译而来, 目前绝大多数的业界Linux系统都是基于CentOS的衍生系统。
目前Centos的最新版本为7.2, 感兴趣的童鞋可以访问其官网: www.centos.org, 支持开源,人人受益。
在Centos 7下安装MariaDB简明教程
- MaraDB
MariaDB数据库管理系统是MySQL的一个分支,采用GPL授权许可 MariaDB的目的是完全兼容MySQL,包括API和命令行,使之能轻松成为MySQL的代替品;其目前版本开源,相对于Oracle旗下的MySQL而言,无法确认某一天MySQL是否会转换为商业产品,且目前这个迹象已经非常明显。在大名鼎鼎的Ubuntu Linux发行版中,已经将MySQL数据库替换为了MariaDB数据库,由此可见开源社区对Oracle不明朗态度的担忧。
MariaDB由MySQL的创始人Michael Widenius主导开发,其目前的版本为10.1/10.2 Series,兼容MySQL的5.6, 5.7版本。 简单而言,大家可以把其当作一模一样的MySQL来用,完全没有问题。当然MariaDB没有停留在MySQL的基础上,其依然开发了若干很好的特性,比如集群的解决方案,高可用性等等技术方案,感兴趣的童鞋可以访问其官网获取更多信息。
在Centos 7下安装MariaDB简明教程
- Yum
Yum(全称为 Yellow dog Updater, Modified)是一个在Fedora和RedHat以及CentOS中的Shell前端软件包管理器。基于RPM包管理,能够从指定的服务器自动下载RPM包并且安装,可以自动处理依赖性关系,并且一次安装所有依赖的软件包,无须繁琐地一次次下载、安装。
基本上每个Linux发行版都会开发一套自己的包管理工具,故这个也是在使用Linux之时非常让人头痛的地方,目前几个主流的包管理工具有:
> RPM 同样来自 Red Hat的贡献
> APT 大规模使用在Ubuntu的发行版本上
- 安装步骤
a.1 检查当下操作系统的版本
>> uname -a
Linux AY131203102210033c39Z 3.10.0-327.22.2.el7.x86_64 #1 SMP Thu Jun 23 17:05:11 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
>> cat /proc/version
Linux version 3.10.0-327.22.2.el7.x86_64 ([email protected]) (gcc version 4.8.3 20140911 (Red Hat 4.8.3-9) (GCC) ) #1 SMP Thu Jun 23 17:05:11 UTC 2016
>> lsb_release
LSB Version: :core-4.1-amd64:core-4.1-noarch
针对Centos或者Red Hat的系统,可以基于如下命令来检查其版本:
> cat /etc/redhat-release
CentOS Linux release 7.2.1511 (Core)
a.2 检查MaraiDB是否已经安装
> yum search mariadb
[root@xxxxxx~]# yum search mariadb
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
-
base: mirrors.aliyuncs.com
-
epel: mirrors.aliyuncs.com
-
extras: mirrors.aliyuncs.com
- updates: mirrors.aliyuncs.com
mariadb-bench.x86_64 : MariaDB benchmark scripts and data
mariadb-devel.i686 : Files for development of MariaDB/MySQL applications
mariadb-devel.x86_64 : Files for development of MariaDB/MySQL applications
mariadb-embedded.i686 : MariaDB as an embeddable library
mariadb-embedded.x86_64 : MariaDB as an embeddable library
mariadb-embedded-devel.i686 : Development files for MariaDB as an embeddable library
mariadb-embedded-devel.x86_64 : Development files for MariaDB as an embeddable library
mariadb-libs.i686 : The shared libraries required for MariaDB/MySQL clients
mariadb-libs.x86_64 : The shared libraries required for MariaDB/MySQL clients
mariadb-server.x86_64 : The MariaDB server and related files
mariadb.x86_64 : A community developed branch of MySQL
mariadb-test.x86_64 : The test suite distributed with MariaD
percona-xtrabackup.x86_64 : Online backup for InnoDB/XtraDB in MySQL, Percona Server and MariaDB
Name and summary matches only, use "search all" for everything.
> yum info mariadb
可以获取到mariadb的安装状态信息
a.3 安装
> yum install mariadb mariadb-server
[root@xxxxx ~]# yum install mariadb mariadb-server
Loaded plugins: fastestmirror
base | 3.6 kB 00:00:00
epel | 4.3 kB 00:00:00
extras | 3.4 kB 00:00:00
updates | 3.4 kB 00:00:00
(1/2): epel/x86_64/updateinfo | 738 kB 00:00:00
(2/2): epel/x86_64/primary_db | 4.5 MB 00:00:04
Loading mirror speeds from cached hostfile
-
base: mirrors.aliyuncs.com
-
epel: mirrors.aliyuncs.com
-
extras: mirrors.aliyuncs.com
- updates: mirrors.aliyuncs.com
Package 1:mariadb-5.5.52-1.el7.x86_64 already installed and latest version
Resolving Dependencies
--> Running transaction check
........................................................
Verifying : perl-DBD-MySQL-4.023-5.el7.x86_64 9/10
Verifying : perl-IO-Compress-2.061-2.el7.noarch 10/10
Installed:
mariadb-server.x86_64 1:5.5.52-1.el7
Dependency Installed:
libaio.x86_64 0:0.3.109-13.el7 perl-Compress-Raw-Bzip2.x86_64 0:2.061-3.el7 perl-Compress-Raw-Zlib.x86_64 1:2.061-4.el7 perl-DBD-MySQL.x86_64 0:4.023-5.el7 perl-DBI.x86_64 0:1.627-4.el7
perl-Data-Dumper.x86_64 0:2.145-3.el7 perl-IO-Compress.noarch 0:2.061-2.el7 perl-Net-Daemon.noarch 0:0.48-5.el7 perl-PlRPC.noarch 0:0.2020-14.el7
Complete!
以上就安装成功了。
a.4 启动mariadb,并检查其启动状态
systemctl start mariadb
启动完成后,测试启动启动状态:
systemctl status mariadb
以下是启动过程信息,可以查看其失败的原因和成功的过程信息
● mariadb.service - MariaDB database server
Loaded: loaded (/usr/lib/systemd/system/mariadb.service; disabled; vendor preset: disabled)
Active: active (running) since Mon 2017-02-20 13:01:25 CST; 7s ago
Process: 32136 ExecStartPost=/usr/libexec/mariadb-wait-ready $MAINPID (code=exited, status=0/SUCCESS)
Process: 32056 ExecStartPre=/usr/libexec/mariadb-prepare-db-dir %n (code=exited, status=0/SUCCESS)
Main PID: 32134 (mysqld_safe)
CGroup: /system.slice/mariadb.service
├─32134 /bin/sh /usr/bin/mysqld_safe --basedir=/usr
└─32292 /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --log-error=/var/log/mariadb/mariadb.log --pid-file=/var/run/mariadb/mariadb.p...
Feb 20 13:01:21 AY131203102210033c39Z mariadb-prepare-db-dir[32056]: The latest information about MariaDB is available at http://mariadb.org/.
Feb 20 13:01:21 AY131203102210033c39Z mariadb-prepare-db-dir[32056]: You can find additional information about the MySQL part at:
Feb 20 13:01:21 AY131203102210033c39Z mariadb-prepare-db-dir[32056]: http://dev.mysql.com
Feb 20 13:01:21 AY131203102210033c39Z mariadb-prepare-db-dir[32056]: Support MariaDB development by buying support/new features from MariaDB
Feb 20 13:01:21 AY131203102210033c39Z mariadb-prepare-db-dir[32056]: Corporation Ab. You can contact us about this at [email protected].
Feb 20 13:01:21 AY131203102210033c39Z mariadb-prepare-db-dir[32056]: Alternatively consider joining our community based development effort:
Feb 20 13:01:21 AY131203102210033c39Z mariadb-prepare-db-dir[32056]: http://mariadb.com/kb/en/contributing-to-the-mariadb-project/
Feb 20 13:01:21 AY131203102210033c39Z mysqld_safe[32134]: 170220 13:01:21 mysqld_safe Logging to '/var/log/mariadb/mariadb.log'.
Feb 20 13:01:21 AY131203102210033c39Z mysqld_safe[32134]: 170220 13:01:21 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
Feb 20 13:01:25 AY131203102210033c39Z systemd[1]: Started MariaDB database server.
看到最后一句的时候,就知道其已经正常启动了.....
另外大家也可以访问/var/log/mariadb/mariadb.log中的日志信息,非常有帮助的。