Charles Bell
Introducing MySQL Shell
Administration Made Easy with Python
Charles Bell
Warsaw, VA, USA
Any source code or other supplementary material referenced by the author in this book is available to readers on GitHub via the books product page, located at www.apress.com/9781484250822 . For more detailed information, please visit http://www.apress.com/source-code .
ISBN 978-1-4842-5082-2 e-ISBN 978-1-4842-5083-9
https://doi.org/10.1007/978-1-4842-5083-9
Charles Bell 2019
This work is subject to copyright. All rights are reserved by the Publisher, whether the whole or part of the material is concerned, specifically the rights of translation, reprinting, reuse of illustrations, recitation, broadcasting, reproduction on microfilms or in any other physical way, and transmission or information storage and retrieval, electronic adaptation, computer software, or by similar or dissimilar methodology now known or hereafter developed.
Trademarked names, logos, and images may appear in this book. Rather than use a trademark symbol with every occurrence of a trademarked name, logo, or image we use the names, logos, and images only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark. The use in this publication of trade names, trademarks, service marks, and similar terms, even if they are not identified as such, is not to be taken as an expression of opinion as to whether or not they are subject to proprietary rights.
While the advice and information in this book are believed to be true and accurate at the date of publication, neither the authors nor the editors nor the publisher can accept any legal responsibility for any errors or omissions that may be made. The publisher makes no warranty, express or implied, with respect to the material contained herein.
Distributed to the book trade worldwide by Springer Science+Business Media New York, 233 Spring Street, 6th Floor, New York, NY 10013. Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail orders-ny@springer-sbm.com, or visit www.springeronline.com. Apress Media, LLC is a California LLC and the sole member (owner) is Springer Science + Business Media Finance Inc (SSBM Finance Inc). SSBM Finance Inc is a Delaware corporation.
I dedicate this book to my big brother, William E. Bell, who left this world too soon. I miss you, Bill.
Introduction
MySQL has been around a long time. I have had the pleasure of witnessing its evolution firsthand as a software developer for Oracle working on MySQL. I have watched MySQL grow from a small database server for web applications to an enterprise-grade high availability database system. The road has not always been smooth as there have been some bumps along the way, but overall Oracle has demonstrated its commitment to the product and continued its evolution.
A perfect example of this dedication is shown in the creation of MySQL Shell, which is a completely new look at how to create a MySQL client. Not only does it replace the existing venerable client, it expands productivity to include programmatic access to the new MySQL Document store (a NoSQL interface) as well as mechanisms for working with MySQL InnoDB Cluster the next iteration of MySQL high availability.
If you have used the older MySQL client, you will be especially surprised to see how much easier the new MySQL Shell is to use. If that wasnt enough of an incentive, consider you can now write, debug, and execute Python and JavaScript code right from the shell! Yes, we now have scripting capability native to the new client. Yippee!
This book will give you an introduction to MySQL Shell and teach you how to use it for SQL development, working with databases (SQL), writing scripts to interact with the MySQL Document Store to create NoSQL applications, and even how to use Python to work with high availability features such as MySQL Replication, Group Replication and InnoDB Cluster. As you will see, MySQL Shell is the one source for all these uses.
Intended Audience
I wrote this book to share my passion for MySQL and the giant leap forward for MySQL users. I especially wanted to show just how easy and sophisticated MySQL Shell has become. Now, anyone can use MySQL Shell to increase their productivity no matter whether theyre working with SQL, NoSQL, or even InnoDB Cluster. The intended audience includes anyone interested in learning about working with MySQL such as database administrators, developers, information technology managers, systems architects, and strategic planners.
How This Book Is Structured
The book was written to guide the reader from a general knowledge of MySQL Shell by introducing its features using example scenarios such as SQL and NoSQL development with the X Developer API (X DevAPI) via Python examples, managing MySQL Replication and Group Replication, working with MySQL InnoDB Cluster via Python scripts, and how to set up and configure MySQL Shell.
The first several chapters cover general topics such as what MySQL Shell is, its features, and how to install it on your system. Later chapters present four scenarios for using MySQL Shell including working with SQL databases with Python, working with MySQL Document Store with Python, configuring MySQL Replication and Group Replication, and setup and managing MySQL InnoDB Cluster with Python. Each of these chapters is presented with an introduction for each topic followed by a companion chapter that presents a detailed example to illustrate the concepts.
Chapter , Introducing MySQL Shell: This chapter introduces MySQL Shell including a brief tour of the new features in MySQL realized in the shell.
Chapter , Installing the MySQL Shell: This chapter discusses and presents an example of how to download and install MySQL Shell on Windows, macOS, and Linux.
Chapter , MySQL Shell Tutorial: This chapter presents a short tutorial on the commands and options used in MySQL Shell, how to use the shell to connect to MySQL servers, and how to work with the shell.
Chapter , Using the Shell with SQL Databases: This chapter briefly discusses working with relational databases including a brief look at the more common SQL commands and functions.
Chapter , Example: SQL Database Development: This chapter presents a complete Flask Python web application that demonstrates how to use MySQL Shell to develop the Python modules for the SQL application.
Chapter , Using the Shell with a Document Store: This chapter briefly introduces JSON documents and the MySQL Document Store including a brief demonstration of the Document Store. The chapter also demonstrates how to use JSON in SQL databases.
Chapter , Example: Document Store Development: This chapter presents a complete Flask Python web NoSQL application that demonstrates how to use MySQL Shell to develop the Python modules for the NoSQL application.
Chapter , Using the Shell with MySQL Replication: This chapter presents an overview of the high availability features in MySQL including a brief tutorial on MySQL Replication.
Chapter , Example: Group Replication Setup and Administration: This chapter presents a short tutorial on Group Replication including a demonstration of how to use MySQL Shell to configure MySQL Group Replication. The chapter also demonstrates how failover works in MySQL Group Replication.