Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
MariaDB Cookbook
MariaDB Cookbook

MariaDB Cookbook: Learn how to use the database that's growing in popularity as a drop-in replacement for MySQL. The MariaDB Cookbook is overflowing with handy recipes and code examples to help you become an expert simply and speedily.

Arrow left icon
Profile Icon Daniel Bartholomew Profile Icon Daniel Bartholomew
Arrow right icon
$22.99 $32.99
Full star icon Full star icon Full star icon Full star icon Half star icon 4.2 (9 Ratings)
eBook Mar 2014 282 pages Edition
eBook
$22.99 $32.99
Paperback
$54.99
Subscription
Free Trial
Renews at $19.99p/m
Arrow left icon
Profile Icon Daniel Bartholomew Profile Icon Daniel Bartholomew
Arrow right icon
$22.99 $32.99
Full star icon Full star icon Full star icon Full star icon Half star icon 4.2 (9 Ratings)
eBook Mar 2014 282 pages Edition
eBook
$22.99 $32.99
Paperback
$54.99
Subscription
Free Trial
Renews at $19.99p/m
eBook
$22.99 $32.99
Paperback
$54.99
Subscription
Free Trial
Renews at $19.99p/m

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Table of content icon View table of contents Preview book icon Preview Book

MariaDB Cookbook

Chapter 2. Diving Deep into MariaDB

In this chapter, we will cover the following recipes:

  • Importing the data exported by mysqldump

  • Using SHOW EXPLAIN with running queries

  • Using LIMIT ROWS EXAMINED

  • Using INSTALL SONAME

  • Producing HTML output

  • Producing XML output

  • Migrating a table from MyISAM to Aria

  • Migrating a table from MyISAM or Aria to InnoDB or XtraDB

Introduction


Now that we've got our feet wet with MariaDB, it's time to dive deeper and experiment with some of the useful features of MariaDB.

Importing the data exported by mysqldump


Importing data from a mysqldump backup is easy and quick. In this recipe, we'll import a backup of the Internet Speculative Fiction Database (ISFDB). This database is licensed under the Creative Commons Attribution license (CC BY) which allows us to use this database for this recipe and many of the other recipes in this book.

How to do it...

  1. Go to http://www.isfdb.org/wiki/index.php/ISFDB_Downloads and download the latest MySQL 5.5 compatible file. The file will be almost 80 megabytes and will be named with the date the backup was made. In this recipe, we'll be using the backup-MySQL-55-2014-02-22.zip file. We can download that file or a more recent one. If we do use a more recent file, we'll need to update the names in the following steps.

  2. After the download finishes, we unzip the file using the following command:

    unzip backup-MySQL-55-2014-02-22.zip
    
  3. When unzipped, the file will be over 300 megabytes.

  4. Our next step is to launch the mysql command-line...

Using SHOW EXPLAIN with running queries


The SHOW EXPLAIN feature was introduced in MariaDB 10.0. It enables us to get an EXPLAIN (that is, a description of the query plan) of the query running in a given thread.

Getting ready

Import the ISFDB database as described in the Importing the data exported by mysqldump recipe of this chapter.

How to do it...

  1. Open a terminal window and launch the mysql command-line client and connect to the isfdb database.

    mysql isfdb
    
  2. Next, we open another terminal window and launch another instance of the mysql command-line client.

  3. Run the following command in the first window:

    ALTER TABLE title_relationships DROP KEY titles;
    
  4. Next, in the first window, start the following example query:

    SELECT titles.title_id AS ID, 
           titles.title_title AS Title, 
           authors.author_legalname AS Name, 
           (SELECT COUNT(DISTINCT title_relationships.review_id) 
             FROM title_relationships
             WHERE title_relationships.title_id = titles.title_id)
      AS reviews 
    FROM...

Using LIMIT ROWS EXAMINED


The LIMIT ROWS EXAMINED clause is a good way to minimize the overhead of a very large or otherwise expensive query if we don't necessarily want or need to search every row in a large table or set of tables.

Getting ready

Import the ISFDB database as described in the Importing the data exported by mysqldump recipe, earlier in this chapter.

How to do it...

  1. Open a terminal window and launch the mysql command-line client and connect to the isfdb database.

  2. Run the following query from the Using SHOW EXPLAIN with running queries recipe, with one small addition at the end:

    SELECT titles.title_id AS ID, 
           titles.title_title AS Title, 
           authors.author_legalname AS Name, 
           (SELECT COUNT(DISTINCT title_relationships.review_id) 
             FROM title_relationships 
             WHERE title_relationships.title_id = titles.title_id) AS reviews 
    FROM  titles,authors,canonical_author 
    WHERE 
           (SELECT COUNT(DISTINCT title_relationships.review_id) 
             FROM title_relationships...

Using INSTALL SONAME


The INSTALL SONAME command is used to install plugins in MariaDB. In this recipe, we'll install the Cassandra storage engine.

How to do it...

  1. Connect to MariaDB using the mysql command-line client with a user that has the INSERT privilege on the mysql.plugins table. The root user has this privilege, but other users might as well.

  2. Install the Cassandra storage engine plugin using the following command line:

    INSTALL SONAME 'ha_cassandra';
    
  3. Issue the SHOW plugins; command and look for the following text:

    | CASSANDRA | ACTIVE | STORAGE ENGINE | ha_cassandra.so | GPL | 
    
  4. Next, issue the SHOW STORAGE ENGINES; command and look for the following text:

    | CASSANDRA | YES | Cassandra storage engine| NO | NO | NO | 
    
  5. The preceding output indicates that the Cassandra storage engine is installed and ready to go. The three NO columns are about transactions, distributed XA transactions, and savepoints, respectively. All three are features that the Cassandra storage engine does not support...

Producing HTML output


The mysql command-line client has several different output options. One of these is HTML.

Getting ready

Import the ISFDB database as described in the Importing the data exported by mysqldump recipe in this chapter. Create a file called isfdb-001.sql using the following command line:

SELECT * FROM authors LIMIT 100;

We could put whatever commands we want in this file, or give it a different name, but this works for the purposes of this recipe.

How to do it...

  1. Open a terminal and navigate to where we saved the isfdb-001.sql file.

  2. Issue the following command on the command line (not from within the mysql command-line client, but by calling the client with some special options):

    mysql --html isfdb < isfdb-001.sql > isfdb-001.html
    
  3. Execute either a dir or ls command and we'll see that now there is a file named isfdb-001.html in the directory.

  4. We can now either open the newly created isfdb-001.html file in our favorite text editor, or view it in a web browser, such as Firefox...

Producing XML output


The mysql command-line client has several different output options. One of these is XML.

Getting ready

Import the ISFDB database as described in the Importing the data exported by mysqldump recipe in this chapter. Create a file called isfdb-001.sql using the following command line:

SELECT * FROM authors LIMIT 100;

We could put whatever commands we want in this file, or give it a different name, but this works for the purposes of this recipe. This file has the same name and contents as the file used in the previous recipe. If we've already completed that recipe, we can just reuse the same file.

How to do it...

  1. Open a terminal and navigate to where we saved the isfdb-001.sql file.

  2. Issue the following command on the command line (not from within the mysql command-line client, but by calling the client with some special options):

    mysql --xml isfdb < isfdb-001.sql > isfdb-001.xml
    
  3. Execute either a dir or ls command and we'll see that there is now a file named isfdb-001.xml...

Migrating a table from MyISAM to Aria


MariaDB ships with the MyISAM and Aria storage engines, among many others. The main difference between these two is that Aria is crash safe, whereas MyISAM is not. Being crash safe means that an Aria table can recover from catastrophic power loss or other unexpected failures in a much better way than a MyISAM table can. If we use MyISAM tables, an easy upgrade is to convert them to Aria tables.

Getting ready

Import the ISFDB database as described in the Importing the data exported by mysqldump recipe in this chapter.

How to do it...

  1. Open the mysql command-line client and connect to the isfdb database.

  2. Run the following command line:

    ALTER TABLE authors ENGINE=Aria;
    
  3. The ALTER command will then change the table so that it uses the Aria storage engine.

  4. After it has finished, a message similar to the following will be displayed:

    Query OK, 110829 rows affected (3.14 sec)              
    Records: 110829  Duplicates: 0  Warnings: 0 
    
  5. If our system is older or is under...

Migrating a table from MyISAM or Aria to InnoDB or XtraDB


The default storage engine of MariaDB is XtraDB, which is an enhanced version of InnoDB.

Getting ready

Import the ISFDB database as described in the Importing the data exported by mysqldump recipe in this chapter.

How to do it...

  1. Open the mysql command-line client and connect to the isfdb database.

  2. Run the following command line:

    ALTER TABLE awards ENGINE=InnoDB;
    
  3. After the command line gets executed, a message similar to the following will be displayed:

    Query OK, 33102 rows affected (5.37 sec)
    Records: 33102  Duplicates: 0  Warnings: 0
    
  4. If our system is older or is under heavy load and it takes longer than 5 seconds for the ALTER TABLE command line execution to complete, we'll see a progress message letting us know how much of the task has been completed. The message gets updated every 5 seconds, until the task is finished.

How it works...

The ALTER TABLE command converts the table over in two stages. First, it creates a new table, identical...

Left arrow icon Right arrow icon

What you will learn

  • Enable various MariaDB optimizations
  • Link MariaDB to a Cassandra cluster
  • Enable and use the TokuDB storage engine
  • Read from and write to various data formats including XML and CSV
  • Search through your data with Sphinx
  • Connect to other databases with ODBC
  • Tune MariaDB for the best performance

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Mar 20, 2014
Length: 282 pages
Edition :
Language : English
ISBN-13 : 9781783284405
Category :
Languages :
Concepts :
Tools :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Product Details

Publication date : Mar 20, 2014
Length: 282 pages
Edition :
Language : English
ISBN-13 : 9781783284405
Category :
Languages :
Concepts :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
$19.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
$199.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts
$279.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total $ 158.97
MariaDB High Performance
$48.99
Mastering MariaDB
$54.99
MariaDB Cookbook
$54.99
Total $ 158.97 Stars icon

Table of Contents

13 Chapters
Getting Started with MariaDB Chevron down icon Chevron up icon
Diving Deep into MariaDB Chevron down icon Chevron up icon
Optimizing and Tuning MariaDB Chevron down icon Chevron up icon
The TokuDB Storage Engine Chevron down icon Chevron up icon
The CONNECT Storage Engine Chevron down icon Chevron up icon
Replication in MariaDB Chevron down icon Chevron up icon
Replication with MariaDB Galera Cluster Chevron down icon Chevron up icon
Performance and Usage Statistics Chevron down icon Chevron up icon
Searching Data Using Sphinx Chevron down icon Chevron up icon
Exploring Dynamic and Virtual Columns in MariaDB Chevron down icon Chevron up icon
NoSQL with HandlerSocket Chevron down icon Chevron up icon
NoSQL with the Cassandra Storage Engine Chevron down icon Chevron up icon
MariaDB Security Chevron down icon Chevron up icon

Customer reviews

Top Reviews
Rating distribution
Full star icon Full star icon Full star icon Full star icon Half star icon 4.2
(9 Ratings)
5 star 33.3%
4 star 55.6%
3 star 11.1%
2 star 0%
1 star 0%
Filter icon Filter
Top Reviews

Filter reviews by




123monkey45 Apr 16, 2014
Full star icon Full star icon Full star icon Full star icon Full star icon 5
This is a very useful book but the title is not exactly correct. This is not what one usually thinks of as a cookbook and to be fair the author states this in the introduction.This book isn't chock full of the usual how to create users. how to create tables ......, rather the author recommends you get an intro book for that. What this book does have is good coverage of advanced features of MariaDB. To name a few , changing storage engines (Tokudb,Connect,NoSQL), replication including Galera cluster, Sphinx text search, dynamic and virtual columns.This book is excellent in this regard it will make you aware of features you may not have known even existed and for that reason I would recommend buying it.
Amazon Verified review Amazon
Minh Tran May 18, 2014
Full star icon Full star icon Full star icon Full star icon Full star icon 5
I worked for MySQL for 7, 8 years and i am very interesting to read this book. The author has very much experience on Maria DB. He explained most of the thing short and clear that you could follow immediately.You could found most of good stuffs related to MariaDB like: * Migrate your current MySQL database to MariaDB * Talked about some interesting engines: Aria, CONNECT, TokuDB engines. * Optimization and Tuning are also mentioned * Some very specific features for MariaDB like Dynamic & Virtual Columns are understandable and able to apply easily.Besides talking about normal full text search support like other normal database, author also shows us about the search feature with Sphinx.For someone who wants to set up your database as clustering, you could found in a chapter with MariaDB Cluster. Author puts every detail for you that could follow quickly.Even author has a chapter talks about HandlerSocket plugin that allows programming languages (Perl, Python, Ruby) to interact with MariaDB directly. I would like to see more about other programming languages like Java and .NET, how do they interact with MariaDBIf author could provide some comparison for Dynamic & Virtual Columns from Maria DB with Schema less feature from NoSQL database, that would help much for us to choose the right database.This book is a very good start for Developers, DBAs, Consultants working with MariaDB. This is definitely in my must-read-book collection
Amazon Verified review Amazon
LM Baker May 03, 2014
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Written by someone who has been on board since the MariaDB project started, this cookbook is the ideal guide for those who want to unlock advanced features of MariaDB.
Amazon Verified review Amazon
Pethuru Raj May 14, 2014
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
MariaDB is being prescribed as a venerable offshoot of the proven MySQL database technology yet it has surpassed comfortably its parent on several aspects in order to be a quick choice for many kinds of enterprise-scale and multi-tier applications. This book, not only provides a comprehensive introduction but also details all the latest developments around and on this fast-evolving database system. Besides the explanation of the installation, configuration, optimization and tuning of MariaDB, the author had tried to convey a lot of advanced topics that have a direct synchronization with the database in a seamless and sequential fashion. For example, he has described about the replication aspect in MariaDB. The chapter titled as "Replication with MariaDB Galera Cluster" includes recipes that cover how to install and use this new clustering solution. It seems that the author has a leaning towards multiple search engines (TokuDB Storage Engine CONNECT Storage Engine and Cassandra Storage Engine) and has explained the nitty-gritty in a spectacular style. There is an interesting chapter "Searching Data Using Sphinx" that covers how to install and use this useful full-text database indexer and search engine. Finally there is a separate chapter for MariaDB SecurityPrecisely speaking, this book is telling a compact and convincing story about the new database "MariaDB". I am doubly sure that this book is an awesome for developers, architects, evangelists, DB administrators, and consultants.
Amazon Verified review Amazon
David Villalobos Jul 02, 2014
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
It is a bit complicated give my opinion about this book, the thing is that I expected more, let's see it this way, I bought the digital copy and it is OK, but, I will be very disappointed if I had bought the printed book since I think $45 is to much for this book.All the recipes are good, but I like a bit more technical explanation since I like to understand the thinks I am doing.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.