引言: 本文将简要介绍如何在CentOS 7的环境下,安装Mariadb,配置用户和访问权限等类似操作。

  1. CentOS

Cent OS是业界中大名鼎鼎的RedHat红帽系统的开源编译版本,站在巨人的肩上是可以看得更高更远, 由于RedHat的Linux系统非常稳定和强大,且已经得到了业界的普遍认可,这一点从Red Hat的公司业绩就一目了然得感觉到。

由于Red Hat Linux系统是基于开源的Linux系统而来,故其的代码需要进行开源,所以我们才可以见得到Centos系统,其是基于Red Hat Linux开源的源代码编译而来, 目前绝大多数的业界Linux系统都是基于CentOS的衍生系统。

目前Centos的最新版本为7.2, 感兴趣的童鞋可以访问其官网: www.centos.org, 支持开源,人人受益。

2. 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的基础上,其依然开发了若干很好的特性,比如集群的解决方案,高可用性等等技术方案,感兴趣的童鞋可以访问其官网获取更多信息。

官网:www.mariadb.org

3. Yum

Yum(全称为 Yellow dog Updater,Modified)是一个在Fedora和RedHat以及CentOS中的Shell前端软件包管理器。基于RPM包管理,能够从指定的服务器自动下载RPM包并且安装,可以自动处理依赖性关系,并且一次安装所有依赖的软件包,无须繁琐地一次次下载、安装。

基本上每个Linux发行版都会开发一套自己的包管理工具,故这个也是在使用Linux之时非常让人头痛的地方,目前几个主流的包管理工具有:

>> RPM 同样来自 Red Hat的贡献

>> APT 大规模使用在Ubuntu的发行版本上

4. 安装步骤

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 (builder@kbuilder.dev.centos.org) (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

======================================================================================= N/S matched: mariadb ========================================================================================

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 sales@mariadb.com.

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中的日志信息,非常有帮助的。

将mariadb设置为开机启动:

systemctl enable mariadb

输出信息为:

Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.

5. 设置Root 用户的登陆密码

MysqL_secure_installation

根据命令提示,主要是做以下几件事情:

>> 设置root密码

>> 是否禁止远程 root访问

>> 是否禁止 test数据库的访问

>> 是否禁用匿名用户

>> 是否重新加载privilleges-table信息

具体的执行信息如下:

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB

SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it,we'll need the current

password for the root user. If you've just installed MariaDB,and

you haven't set the root password yet,the password will be blank,

so you should just press enter here.

Enter current password for root (enter for none):

OK,successfully used password,moving on...

Setting the root password ensures that nobody can log into the MariaDB

root user without the proper authorisation.

Set root password? [Y/n] y

New password:

Re-enter new password:

Password updated successfully!

Reloading privilege tables..

... Success!

By default,a MariaDB installation has an anonymous user,allowing anyone

to log into MariaDB without having to have a user account created for

them. This is intended only for testing,and to make the installation

go a bit smoother. You should remove them before moving into a

production environment.

Remove anonymous users? [Y/n] y

... Success!

normally,root should only be allowed to connect from 'localhost'. This

ensures that someone cannot guess at the root password from the network.

disallow root login remotely? [Y/n] y

... Success!

By default,MariaDB comes with a database named 'test' that anyone can

access. This is also intended only for testing,and should be removed

before moving into a production environment.

Remove test database and access to it? [Y/n] y

- Dropping test database...

... Success!

- Removing privileges on test database...

... Success!

Reloading the privilege tables will ensure that all changes made so far

will take effect immediately.

Reload privilege tables Now? [Y/n] y

... Success!

Cleaning up...

All done! If you've completed all of the above steps,your MariaDB

installation should Now be secure.

Thanks for using MariaDB!

6. 创建用户以及设置权限

创建用户:

MysqL>create user username@localhost identified by 'password';

授予用户权利:

MysqL>grant all on *.* to username@localhost indentified by 'password';

授予用户访问外网的权利:

MysqL>grant all privileges on *.* to username@'%' identified by 'password';

授予权限并且可以授权

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

刷新权限表,让各种设置立即生效。

flush privileges;

验证用户是否被正确创建, 访问MysqL.user 表,看看其中是否存在bladestone用户。

7. 配置Mariadb数据库的字符设置

>> 在/etc/my.cnf中的MysqLd标签下,新增字符设置:

init_connect='SET collation_connection = utf8_unicode_ci' init_connect='SET NAMES utf8' character-set-server=utf8

>> 在/etc/my.cnf.d/client.cnf中的client标签下,新增字符设置:

default-character-set=utf8

>> 在/etc/my.cnf.d/MysqL-clients.cnf下的[MysqLd]标签下,新增字符设置:

设置完成后,重新启动mariadb-server,将设置生效。

>> systemctl restart mariadb

>> systemctl status mariadb # 检查启动状态是否正确,详细信息参照本文中的样例

>> vi /var/log/mariadb/mariadb.log # 查看其中是否有错误信息

如果木有错误信息,则设置成功生效了。

那我们来查看一下是否真的生效了:

登陆MySQL命令行, 输入命令:

show variables like "%character%";show variables like "%collation%";

输出结果信息:

MariaDB [(none)]> show variables like "%character%";show variables like "%collation%";

+--------------------------+----------------------------+

| Variable_name | Value |

+--------------------------+----------------------------+

| character_set_client | utf8 |

| character_set_connection | utf8 |

| character_set_database | utf8 |

| character_set_filesystem | binary |

| character_set_results | utf8 |

| character_set_server | utf8 |

| character_set_system | utf8 |

| character_sets_dir | /usr/share/MysqL/charsets/ |

+--------------------------+----------------------------+

8 rows in set (0.00 sec)

+----------------------+-----------------+

| Variable_name | Value |

+----------------------+-----------------+

| collation_connection | utf8_unicode_ci |

| collation_database | utf8_unicode_ci |

| collation_server | utf8_unicode_ci |

+----------------------+-----------------+

3 rows in set (0.00 sec)

8. 测试连接

在目的主机上通过MysqL的命令行是可以直接访问的,但是基于远程的主机访问模式,则无法被正确的访问和数据读取,那问题出在什么地方呢?

基于ping命令测试ip地址,可以正确访问。 基于telnet测试,结果确认估计是端口未曾打开,或者是防火墙将其进行了端口屏蔽。

故首先确认,其端口是否正常的工作:

>> netstat -anp | grep 3306

结果发现,其应用正常启动,故确认其为防火墙的问题以及规则设置。

在Centos 7中的防火墙规则为firewall-cmd, iptables在centos 7中将被替代了。

新增3306的端口开发规则:

firewall-cmd --zone=public --add-port=3306/tcp --permanen

重新加载规则:

firewall-cmd --reload

重新测试连接状态,显示 可以正确远程访问了。

9. 总结

在Cent OS上安装mariadb是比较容易的,但是将其配置好,并允许其正常访问确实一个繁琐的过程,希望本文中涉及到的若干技术点,大家都可以有一个直观的认知和后续的了解使用。

如果您有什么问题,还请大家给我留言。

--------------------------------------- 罪恶的分割线--------------------------------

本文系CDSN的博主《木小鱼的笔记》个人原创,如无允许,请勿转载。如要转载,请保留原始链接和原作者信息,支持原创,尊重原创,让知识的世界更美好。

作者本人也维护了一个今日头条上的头条号:程序加油站,欢迎大家关注。

在Centos 7下安装MariaDB简明教程的更多相关文章

  1. ios – NSString cString已被弃用.什么是替代品?

    我有另一个新手问题.我写了一段代码,将Nsstring转换为NSMutableData,以模拟一个webService结果.但事实证明,cString已被弃用.你可以帮我更换吗?这是我的代码解决方法>从字符串获取原始字节.>获取UTF8编码中这些字节的长度.>使用dataWithBytes:length:方法创建NSData对象.

  2. 从iOS应用程序发送帖子到PHP脚本不工作…简单的解决方案就像

    我之前已经做了好几次了但是由于某些原因我无法通过这个帖子…我尝试了设置为_POST且没有的变量的PHP脚本……当它们未设置为发布时它工作精细.这是我的iOS代码:这里是PHP的一大块,POST变量不在正确的位置?我想这对于更有经验的开发人员来说是一个相当简单的答案,感谢您的帮助!解决方法$_POST是一个数组,而不是一个函数.您需要使用方括号来访问数组索引:

  3. 驳狗屎文 "我为什么放弃Go语言"

    开门见山地说,我当初放弃Go语言,就是因为两个“不爽”:第一,对Go语言本身不爽;第二,对Go语言社区里的某些人不爽。两年之后,2011年底,Go语言发布1.0的计划被提上日程,相关的报道又多起来,我再次关注它,重新评估之后决定深入参与Go语言。外加Go语言社区里的某些人,其中也包括Google公司负责开发Go语言的某些人,其态度、言行,让我极度厌恶,促使我决绝地离弃Go语言。第1节:我为什么对Go语言不爽?

  4. [Swift]NSString、NSData、Base64互转

    ####Nsstring、NSData互转########Base64互转####

  5. android – java.lang.RuntimeException:无法在未调用Looper.prepare()的线程内创建处理程序

    嗨,我的代码有问题.我的代码是和这样的错误:如果活动将数据保存到服务器我命令进度条可以运行,但如果没有这不起作用..我应该怎么做才能解决这个问题?解决方法由于您正在使用活动上下文的线程,您可能会收到错误.您应该使用AsyncTask而不是普通线程.在AsyncTask中,有一个onPreExecute()和onPostExecute()方法,它们在主线程上执行,并且有一个方法doInBackground()将在后台执行,以便您可以轻松实现长期进程.你可以参考thisexample

  6. Android – 将SQLite与MySQL同步的最佳方式

    参见英文答案>Synchronizingclient-serverdatabases5个我正在开发一个包含网络应用和移动应用程序的项目,该应用程序记录每日用户的数据.用户可以删除,更新他们的数据,他们可以使用许多设备插入数据.我打算这样开发:用户输入他们的数据然后插入sqlite.服务将定期启动(每5小时或每小时)以使用时间戳与MysqL同步.我确实在互联网上使用服务和时间戳搜索了一个样本,但我一

  7. android – 如何将唯一的GCM注册标识存储到MySQL中

    我正在设置GoogleCloudMessaging机制的服务器端,使用MySQL存储移动应用提供的注册ID.Google可以发出最多4k个注册码,我被迫将其存储在TEXT字段中.所有的好,到目前为止,问题是我必须处理这样的情况:>用户登录到应用程序>该应用从google请求注册ID>应用程序将新的注册ID发送到应用服务器>服务器存储该注册ID并将其链接到当前登录的用户>该用户注销并且新用户登录>应

  8. CentOS 8.2服务器上安装最新版Node.js的方法

    这篇文章主要介绍了CentOS 8.2服务器上安装最新版Node.js的方法,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下

  9. nodeJs链接Mysql做增删改查的简单操作

    本篇文章主要介绍了nodeJs链接Mysql做增删改查的简单操作,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧

  10. PHP连接MYSQL数据库的3种常用方法

    这篇文章主要介绍了PHP连接MYSQL数据库的3种常用方法,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

随机推荐

  1. 在airgapped(离线)CentOS 6系统上安装yum软件包

    我有一个CentOS6系统,出于安全考虑,它已经被空气泄漏.它可能从未连接到互联网,如果有,它很长时间没有更新.我想将所有.rpm软件包放在一个驱动器上,这样它们就可以脱机安装而无需查询互联网.但是,我在测试VM上遇到的问题是,即使指定了本地路径,yum仍然会挂起并尝试从在线存储库进行更新.另外,有没有办法使用yum-utils/yumdownloader轻松获取该包的所有依赖项和所有依赖项?目前

  2. centos – 命名在日志旋转后停止记录到rsyslog

    CentOS6.2,绑定9.7.3,rsyslog4.6.2我最近设置了一个服务器,我注意到在日志轮换后,named已停止记录到/var/log/messages.我认为这很奇怪,因为所有日志记录都是通过rsyslog进行的,并且named不会直接写入日志文件.这更奇怪,因为我在更新区域文件后命名了HUPed,但它仍然没有记录.在我停止并重新启动命名后,记录恢复.这里发生了什么?

  3. centos – 显示错误的磁盘大小

    对于其中一个磁盘,Df-h在我的服务器上显示错误的空白区域:Cpanel表明它只有34GB免费,但还有更多.几分钟前,我删除了超过80GB的日志文件.所以,我确信它完全错了.fdisk-l/dev/sda2也显示错误:如果没有格式化,我该怎么做才能解决这个问题?并且打开文件描述符就是它需要使用才能做到这一点.所以…使用“lsof”并查找已删除的文件.重新启动写入日志文件的服务,你很可能会看到空间可用.

  4. 如何在centos 6.9上安装docker-ce 17?

    我目前正在尝试在centOS6.9服务器上安装docker-ce17,但是,当运行yuminstalldocker-ce时,我收到以下错误:如果我用跳过的标志运行它我仍然得到相同的消息,有没有人知道这方面的方法?

  5. centos – 闲置工作站的异常负载平均值

    我有一个新的工作站,具有不寻常的高负载平均值.机器规格是:>至强cpu>256GB的RAM>4x512GBSSD连接到LSI2108RAID控制器我从livecd安装了CentOS6.564位,配置了分区,网络,用户/组,并安装了一些软件,如开发工具和MATLAB.在启动几分钟后,工作站负载平均值的值介于0.5到0.9之间.但它没有做任何事情.因此我无法理解为什么负载平均值如此之高.你能帮我诊断一下这个问题吗?

  6. centos – Cryptsetup luks – 检查内核是否支持aes-xts-plain64密码

    我在CentOS5上使用cryptsetupluks加密加密了一堆硬盘.一切都很好,直到我将系统升级到CentOS6.现在我再也无法安装磁盘了.使用我的关键短语装载:我收到此错误:在/var/log/messages中:有关如何装载的任何想法?找到解决方案问题是驱动器使用大约512个字符长的交互式关键短语加密.出于某种原因,CentOS6中的新内核模块在由旧版本创建时无法正确读取512个字符的加密密钥.似乎只会影响内核或cryptsetup的不同版本,因为在同一系统上创建和打开时,512字符的密钥将起作用

  7. centos – 大量ssh登录尝试

    22个我今天登录CentOS盒找到以下内容这是过去3天内的11次登录尝试.WTF?请注意,这是我从我的提供商处获得的全新IP,该盒子是全新的.我还没有发布任何关于此框的内容.为什么我会进行如此大量的登录尝试?是某种IP/端口扫描?基本上有4名匪徒,其中2名来自中国,1名来自香港,1名来自Verizon.这只发生在SSH上.HTTP上没有问题.我应该将罪魁祸首子网路由吗?你们有什么建议?

  8. centos – kswap使用100%的CPU,即使有100GB的RAM也可用

    >Linux内核是否应该足够智能,只需从内存中清除旧缓存页而不是启动kswap?

  9. centos – Azure将VM从A2 / 3调整为DS2 v2

    我正在尝试调整前一段时间创建的几个AzureVM,从基本的A3和标准A3到标准的DS2v2.我似乎没有能力调整到这个大小的VM.必须从头开始重建服务器会有点痛苦.如果它有所不同我在VM中运行CentOS,每个都有一个带有应用程序和操作系统的磁盘.任何人都可以告诉我是否可以在不删除磁盘的情况下删除VM,创建新VM然后将磁盘附加到新VM?

  10. centos – 广泛使用RAM时服务器计算速度减慢

    我在非常具体的情况下遇到服务器速度下降的问题.事实是:>1)我使用计算应用WRF>2)我使用双XeonE5-2620v3和128GBRAM(NUMA架构–可能与问题有关!

返回
顶部