数据库

 首页 > 数据库 > mariadb > Linux系统下快速部署MariaDB代替MySQL数据库

Linux系统下快速部署MariaDB代替MySQL数据库

分享到:
【字体:
导读:
         摘要:MariaDB名称来自MichaelWidenius的女儿Maria的名字。是MariaDB的LOGO:MariaDB的LOGOMariaDB下载:https://downloads.mariadb.org/MariaDB网站:http://www.mariadb.org/MariaDB最新稳定版为:MariaDB5....

Linux系统下快速部署MariaDB代替MySQL数据库

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

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。

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

MySQL 5.5引擎列表

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分支版本 。

二 主要 Linux 发行版本安装MariaDB

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

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

使用deb软件包格式的Debian /Ubuntu 。

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

(1)这里以Fedora 19为例

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

a、安装软件包

#yum -y install mariadb-server mariadb 

#systemctl start mysqld.service 

#systemctl enable mysqld.service 

ln -s '/lib/systemd/system/mysqld.service' '/etc/systemd/system/multi-user.target.wants/mysqld.service' 

2、数据库的基本操作

首次连接MariaDB如:

#mysql -u root 

首次连接MariaDB

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

查看用户信息

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

查看用户信息

设置root用户密码

MariaDB [(none)]> set password for root@localhost=password('password'); 

Query OK, 0 rows affected (0.00 sec) 

# set root password 

MariaDB [(none)]> set password for root@'127.0.0.1'=password('password'); 

Query OK, 0 rows affected (0.00 sec) 

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

MariaDB [(none)]> delete from mysql.user where user='root' and host='::1'; 

Query OK, 1 rows affected (0.00 sec) 

MariaDB [(none)]> delete from mysql.user where user=''; 

Query OK, 2 rows affected (0.00 sec) 

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

#mysql -u root -p 

Enter password: 

# MariaDB root password you set 

Welcome to the MariaDB monitor.  Commands end with ; or g. 

Your MariaDB connection id is 3 

Server version: 5.5.31-MariaDB MariaDB Server 

Copyright (c) 2000, 2013, Oracle, Monty Program Ab and others. 

Type 'help;' or 'h' for help. Type 'c' to clear the current input statement. 

MariaDB [(none)]> 

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 -y install httpd php php-mbstring php-pear 

# yum -y install phpMyAdmin php-mysql php-mcrypt 

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

vi /etc/httpd/conf.d/phpMyAdmin.conf 

# line 15: add IP address you permit 

Require ip 127.0.0.1 10.0.0.0/24 

# line 32: add IP address you permit 

Require ip 127.0.0.1 10.0.0.0/24 

#systemctl restart httpd.service 

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

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 -y install MariaDB-server MariaDB-client 

# service mysql start 

# chkconfig mysql on 

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

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

deb http://ftp.heanet.ie/mirrors/mariadb/repo/5.5/ubuntu lucid main 

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

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

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

3. 更新

#apt-get update 

4. 安装

#apt-get install mariadb-server-5.5 

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

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

三 Mariadb的root密码的重新设置

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

# service mysql stop 

安全模式启动:

# mysqld_safe --skip-grant-tables & 

登录MariaDb server:

# mysql -u root 

Welcome to the MariaDB monitor. Commands end with ; or g. 

Your MariaDB connection id is 1 

Server version: 5.5.32-MariaDB MariaDB Server 

Copyright (c) 2000, 2013, Oracle, Monty Program Ab and others. 

Type 'help;' or 'h' for help. Type 'c' to clear the current input statement. 

设置密码:

MariaDB [(none)]> update mysql.user set password=PASSWORD("newpassword") where User='root'; 

Query OK, 4 rows affected (0.00 sec) 

Rows matched: 4 Changed: 4 Warnings: 0 

授权后退出:

MariaDB [(none)]> flush privileges; 

Query OK, 0 rows affected (0.00 sec) 

MariaDB [(none)]> exit; 

Bye 

重新启动数据库进程:

# service mysql restart 

使用新密码登录:

# mysql -u root -p 

Enter password: 

Welcome to the MariaDB monitor. Commands end with ; or g. 

Your MariaDB connection id is 1 

Server version: 5.5.32-MariaDB MariaDB Server 

Copyright (c) 2000, 2013, Oracle, Monty Program Ab and others. 

Type 'help;' or 'h' for help. Type 'c' to clear the current input statement. 

总结:

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

Linux系统下快速部署MariaDB代替MySQL数据库
分享到:
MariaDB数据库常见问题
MariaDB数据库常见问题 MariaDB常见问题,同样适用于MySQL 废弃的常见问题 老版本MariaDB服务的相关旧信息 关键字via via似乎是个关键字,但是至少在MySQL5.1文档中找不到。 create table a ( id int, via int ) 在MySQL5.1中执行成功,但是会出现1064错误 (毫无疑问,用avia替代via就可以) 答          ele...
MariaDB 将替代 MySQL
MariaDB 将替代 MySQL MariaDB 现在是很多开源系统默认的 MySQL 实现。MariaDB 基本上和 MySQL 差不多,所以升级非常容易。希望切换的用户需要安装 mariadb, libmariadbclient 或者 mariadb-clients 并执行 mysql_upgrade 来迁移原来的系统。 今日,在一个国外IT博客上看到这样一篇文章:《Google正在用MariaDB替换MySQ...
  •         php迷,一个php技术的分享社区,专属您自己的技术摘抄本、收藏夹。
  • 在这里……