Linux 环境下快速部署 MySQL 的替代方案

原创
运维 系统运维
MariaDB 是一个采用 Maria 存储引擎的 MySQL 分支版本,与 MySQL 相比较,MariaDB 更强的地方在于,二者支持的不同的引擎。通常可以通过show engines 命令来查看两种数据库服务器 支持的不同的引擎。本文主要讲解了Linux 环境下快速部署 MySQL 的替代方案。

【51CTO专稿】一 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、安装软件包

  1. #yum -y install mariadb-server mariadb 
  2. #systemctl start mysqld.service 
  3. #systemctl enable mysqld.service 
  4. ln -s '/lib/systemd/system/mysqld.service' '/etc/systemd/system/multi-user.target.wants/mysqld.service' 

2、数据库的基本操作

***连接MariaDB如图4:

  1. #mysql -u root 

图4***连接MariaDB

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

查看用户信息

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

图5查看用户信息

设置root用户密码

  1. MariaDB [(none)]> set password for root@localhost=password('password'); 
  2. Query OK, 0 rows affected (0.00 sec) 
  3. # set root password 
  4. MariaDB [(none)]> set password for root@'127.0.0.1'=password('password'); 
  5. Query OK, 0 rows affected (0.00 sec) 

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

  1. MariaDB [(none)]> delete from mysql.user where user='root' and host='::1'
  2. Query OK, 1 rows affected (0.00 sec) 
  3. MariaDB [(none)]> delete from mysql.user where user=''
  4. Query OK, 2 rows affected (0.00 sec) 

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

  1. #mysql -u root -p 
  2. Enter password: 
  3. # MariaDB root password you set 
  4. Welcome to the MariaDB monitor.  Commands end with ; or \g. 
  5. Your MariaDB connection id is 3 
  6. Server version: 5.5.31-MariaDB MariaDB Server 
  7. Copyright (c) 2000, 2013, Oracle, Monty Program Ab and others. 
  8. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. 
  9. 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 相关软件包:

  1. # yum -y install httpd php php-mbstring php-pear 
  2. # yum -y install phpMyAdmin php-mysql php-mcrypt 

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

  1. vi /etc/httpd/conf.d/phpMyAdmin.conf 
  2. # line 15: add IP address you permit 
  3. Require ip 127.0.0.1 10.0.0.0/24 
  4. # line 32: add IP address you permit 
  5. Require ip 127.0.0.1 10.0.0.0/24 
  6. #systemctl restart httpd.service 

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

图6 phpMyAdmin管理mariadb数据库

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

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

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

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

安装命令

  1. #yum -y install MariaDB-server MariaDB-client 
  2. # service mysql start 
  3. # chkconfig mysql on 

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

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

  1. deb http://ftp.heanet.ie/mirrors/mariadb/repo/5.5/ubuntu lucid main 
  2. deb-src http://ftp.heanet.ie/mirrors/mariadb/repo/5.5/ubuntu lucid main 

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

  1. # apt-key adv --recv-keys --keyserver keyserver.ubuntu.com 0xcbcb082a1bb943db 

3. 更新

  1. #apt-get update 

4. 安装

  1. #apt-get install mariadb-server-5.5 

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

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

#p#

三 Mariadb的root密码的重新设置

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

  1. # service mysql stop 

安全模式启动:

  1. # mysqld_safe --skip-grant-tables & 

登录MariaDb server:

  1. # mysql -u root 
  2. Welcome to the MariaDB monitor. Commands end with ; or \g. 
  3. Your MariaDB connection id is 1 
  4. Server version: 5.5.32-MariaDB MariaDB Server 
  5. Copyright (c) 2000, 2013, Oracle, Monty Program Ab and others. 
  6. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. 

设置密码:

  1. MariaDB [(none)]> update mysql.user set password=PASSWORD("newpassword") where User='root'
  2. Query OK, 4 rows affected (0.00 sec) 
  3. Rows matched: 4 Changed: 4 Warnings: 0 

授权后退出:

  1. MariaDB [(none)]> flush privileges; 
  2. Query OK, 0 rows affected (0.00 sec) 
  3. MariaDB [(none)]> exit; 
  4. Bye 

重新启动数据库进程:

  1. # service mysql restart 

使用新密码登录:

  1. # mysql -u root -p 
  2. Enter password: 
  3. Welcome to the MariaDB monitor. Commands end with ; or \g. 
  4. Your MariaDB connection id is 1 
  5. Server version: 5.5.32-MariaDB MariaDB Server 
  6. Copyright (c) 2000, 2013, Oracle, Monty Program Ab and others. 
  7. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. 

总结:

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

责任编辑:黄丹 来源: 51CTO.com
相关推荐

2020-12-18 09:15:16

LinuxVue命令

2024-01-10 14:24:32

Docker容器Kafka

2021-12-10 11:30:58

Linux工具命令

2013-08-12 10:15:34

2021-06-03 08:04:13

LinuxMySQL配置

2020-10-30 10:49:37

DockerGPULinux

2017-05-08 15:25:25

虚拟私有云公共云

2010-10-15 13:45:20

安装MySql数据库

2021-08-25 12:55:33

Linuxcron

2011-09-29 10:03:02

2016-08-16 13:44:28

AndroidLinuxADT

2010-07-09 09:37:32

2010-05-28 09:39:45

Linux系统Windows

2011-08-10 13:46:36

Navicat MySMySQL

2010-07-09 13:07:58

Linux环境浏览器

2023-08-09 13:46:39

2009-03-09 09:45:07

MVCAjax.Net

2022-08-02 16:54:23

Kubernetes容器工具

2023-01-05 13:19:38

2016-12-14 08:49:22

LinuxWeblogic部署
点赞
收藏

51CTO技术栈公众号