首页 运维 正文
Linux 环境下快速部署 MySQL 的替代方案

 2022-10-23    315  

一 MySQL 代替者MariaDB 简介

MariaDB名称来自Michael Widenius的女儿Maria的名字。图1 是MariaDB 的LOGO:

图1 MariaDB 的LOGO

MariaDB 下载:https://downloads.mariadb.org/

MariaDB 网站:http://www.mariadb.org/

MariaDB***稳定版为:MariaDB 5.5。上一个稳定版为:MariaDB 5.3。

MariaDB 是一个采用 Maria 存储引擎的 MySQL 分支版本,与 MySQL 相比较,MariaDB 更强的地方在于,二者支持的不同的引擎。通常可以通过show engines 命令来查看两种数据库服务器 支持的不同的引擎。 Support列的信息包括YES,NO 和 DEFAULT。

图2 和图3 分别是MySQL 5.5 和MariaDB 5.5 引擎列表:

图2 MySQL 5.5引擎列表

图3 MariaDB 5.5 引擎列表

对比二者 Sphinx全文搜索引擎是目前当前市场上最炙手可热的开源搜索引擎,MariaDB利用SphinxSE作为存储引擎。另外MariaDB基于事务的Maria存储引擎,替换了MySQL的MyISAM存储引擎,它使用了Percona的 XtraDB,是InnoDB的变体。MariaDB默认的存储引擎是Aria,不是MyISAM。Aria可以支持事务,但是默认情况下没有打开事务支持,因为事务支持对性能会有影响。PBXT 是 MariaDB 附带的一种存储引擎,PBXT 在 MariaDB 的 5.1/5.2/5.3 版本中存在,但从 MariaDB 5.5 开始就不再提供 PBXT 存储引擎,而且以后也将不再提供。另外MariaDB已经宣布了Cassandra存储引擎的一个预览版本。该插件允许MariaDB通过标准SQL语法使用Cassandra集群。

MariaDB跟MySQL在绝大多数方面是兼容的,对于开发者来说,几乎感觉不到任何不同。目前MariaDB是发展最快的MySQL分支版本 。#p#

二 主要 Linux 发行版本安装MariaDB

本文主要介绍两大主要Linux 发行版本类别:

  • 使用rpm 软件包格式的RHEL/CentOS/Fedora
  • 使用deb软件包格式的Debian /Ubuntu 。

1、使用rpm 软件包格式的RHEL/CentOS/Fedora

(1)这里以Fedora 19为例

其中使用Fedora 19 是最简单的,因为这个***Linux 发行版本可以直接使用yum 软件包工具安装

a、安装软件包

#yum-yinstallmariadb-servermariadb
#systemctlstartmysqld.service
#systemctlenablemysqld.service
ln-s'/lib/systemd/system/mysqld.service''/etc/systemd/system/multi-user.target.wants/mysqld.service'

2、数据库的基本操作

***连接MariaDB如图4:

#mysql-uroot

图4***连接MariaDB

可以看到mariadb 版本号是5.5.31-MariaDB MariaDB Server,其他基本操作(和Mysql操作相同)。

查看用户信息

使用内部命令:select user,host,password from mysql.user; 如图5:

图5查看用户信息

设置root用户密码

MariaDB[(none)]>setpasswordforroot@localhost=password('password');
QueryOK,0rowsaffected(0.00sec)
#setrootpassword
MariaDB[(none)]>setpasswordforroot@'127.0.0.1'=password('password');
QueryOK,0rowsaffected(0.00sec)

删除一些数据库用户(ipv6 和 匿名用户)

MariaDB[(none)]>deletefrommysql.userwhereuser='root'andhost='::1';
QueryOK,1rowsaffected(0.00sec)
MariaDB[(none)]>deletefrommysql.userwhereuser='';
QueryOK,2rowsaffected(0.00sec)

退出后使用root密码重新登录

#mysql-uroot-p
Enterpassword:
#MariaDBrootpasswordyouset
WelcometotheMariaDBmonitor.Commandsendwith;or\g.
YourMariaDBconnectionidis3
Serverversion:5.5.31-MariaDBMariaDBServer
Copyright(c)2000,2013,Oracle,MontyProgramAbandothers.
Type'help;'or'\h'forhelp.Type'\c'toclearthecurrentinputstatement.
MariaDB[(none)]>

#p#

3、安装MariaDB客户端工具

MariaDB的API和协议兼容MySQL,另外又添加了一些功能,以支持本地的非阻塞操作和进度报告。这意味着,所有使用MySQL的连接器、库和应用程序也将会在MariaDB下工作。如下是支持MariaDB的工具客户端:

  • DBEdit 一个免费的MariaDB数据库和其他数据库管理应用程序。
  • Navicat 一系列Windows、Mac OS X、Linux下专有数据库管理应用程序。
  • HeidiSQL 一个Windows上自由和开放源码的MySQL客户端。它支持MariaDB的5.2.7版本和以后的版本。
  • phpMyAdmin 一个基于网络的MySQL数据库管理应用程序 。

下面介绍phpMyAdmin ,安装使用phpMyAdmin要配置完成Apache 和 php 相关软件包:

#yum-yinstallhttpdphpphp-mbstringphp-pear
#yum-yinstallphpMyAdminphp-mysqlphp-mcrypt

修改配置文件添加ip地址范围:

vi/etc/httpd/conf.d/phpMyAdmin.conf
#line15:addIPaddressyoupermit
Requireip127.0.0.110.0.0.0/24
#line32:addIPaddressyoupermit
Requireip127.0.0.110.0.0.0/24
#systemctlrestarthttpd.service

然后使用浏览器访问即可,如图6:

图6 phpMyAdmin管理mariadb数据库

(2)其他使用rpm软件包的发行版本

添加文件:/etc/yum.repos.d/MariaDB.repo

CentOS 6 64位发行版本的/etc/yum.repos.d/MariaDB.repo文件内容:

[mariadb]
name=MariaDB
baseurl=http://yum.mariadb.org/5.5/centos6-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1

安装命令

#yum-yinstallMariaDB-serverMariaDB-client
#servicemysqlstart
#chkconfigmysqlon

(3)其他版本安装mariadb(以Ubuntu 12.04 为例子)

首先从 MariaDB 下载页面 选择贴近你的版本的资料库镜像,然后下载页面会在底部显示镜像信息,将这些信息添加到 /etc/apt/source.list

debhttp://ftp.heanet.ie/mirrors/mariadb/repo/5.5/ubuntulucidmain
deb-srchttp://ftp.heanet.ie/mirrors/mariadb/repo/5.5/ubuntulucidmain

2. 接下来需要导入签名密钥:

#apt-keyadv--recv-keys--keyserverkeyserver.ubuntu.com0xcbcb082a1bb943db

3. 更新

#apt-getupdate

4. 安装

#apt-getinstallmariadb-server-5.5

安装过程中要输入mariadb的root密码并且确认一次如图7:

图7 输入mariadb的root密码并且确认一次

#p#

三 Mariadb的root密码的重新设置

首先停止数据库服务器进程:

#servicemysqlstop

安全模式启动:

#mysqld_safe--skip-grant-tables&

登录MariaDb server:

#mysql-uroot
WelcometotheMariaDBmonitor.Commandsendwith;or\g.
YourMariaDBconnectionidis1
Serverversion:5.5.32-MariaDBMariaDBServer
Copyright(c)2000,2013,Oracle,MontyProgramAbandothers.
Type'help;'or'\h'forhelp.Type'\c'toclearthecurrentinputstatement.

设置密码:

MariaDB[(none)]>updatemysql.usersetpassword=PASSWORD("newpassword")whereUser='root';
QueryOK,4rowsaffected(0.00sec)
Rowsmatched:4Changed:4Warnings:0

授权后退出:

MariaDB[(none)]>flushprivileges;
QueryOK,0rowsaffected(0.00sec)
MariaDB[(none)]>exit;
Bye

重新启动数据库进程:

#servicemysqlrestart

使用新密码登录:

#mysql-uroot-p
Enterpassword:
WelcometotheMariaDBmonitor.Commandsendwith;or\g.
YourMariaDBconnectionidis1
Serverversion:5.5.32-MariaDBMariaDBServer
Copyright(c)2000,2013,Oracle,MontyProgramAbandothers.
Type'help;'or'\h'forhelp.Type'\c'toclearthecurrentinputstatement.

总结:

MariaDB 基本上名门之后,加上MySQL创始人Monty的实力和号召力,是作为MySQL一个非常好的替代品,前途发展无限,值得我们尝试使用。二者的常用工具,连接程序都可以如常运作。你也不需要导出和汇入数据。格式与文件名都是相同的。

原文链接:https://77isp.com/post/8716.html

=========================================

https://77isp.com/ 为 “云服务器技术网” 唯一官方服务平台,请勿相信其他任何渠道。