MySQL 8 Cookbook
eBook - ePub

MySQL 8 Cookbook

Karthik Appigatla, Kedar Mohaniraj Vaijanapukar

Partager le livre
  1. 446 pages
  2. English
  3. ePUB (adapté aux mobiles)
  4. Disponible sur iOS et Android
eBook - ePub

MySQL 8 Cookbook

Karthik Appigatla, Kedar Mohaniraj Vaijanapukar

DĂ©tails du livre
Aperçu du livre
Table des matiĂšres
Citations

À propos de ce livre

Design and administer enterprise-grade MySQL 8 solutionsAbout This Book‱ Store, retrieve, and manipulate your data using the latest MySQL 8 features‱ Practical recipes on effective administration in MySQL, with a focus on security, performance tuning, troubleshooting, and more‱ Contains tips, tricks, and best practices for designing, developing, and administering your MySQL 8 database solution without any hassleWho This Book Is ForIf you are a MySQL developer or administrator looking for quick, handy solutions to solve the most common and not-so-common problems in MySQL, this book is for you. MySQL DBAs looking to get up-to-speed with the latest MySQL 8 development and administration features will also find this book very useful. Prior knowledge of Linux and RDBMS is desirable.What You Will Learn‱ Install and configure your MySQL 8 instance without any hassle‱ Get to grips with new features of MySQL 8 like CTE, Window functions and many more‱ Perform backup tasks, recover data and set up various replication topologies for your database‱ Maximize performance by using new features of MySQL 8 like descending indexes, controlling query optimizer and resource groups‱ Learn how to use general table space to suit the SaaS or multi-tenant applications‱ Analyze slow queries using performance schema, sys schema and third party tools‱ Manage and monitor your MySQL instance and implement efficient performance-tuning tasksIn DetailMySQL is one of the most popular and widely used relational databases in the World today. The recently released MySQL 8 version promises to be better and more efficient than ever before.This book contains everything you need to know to be the go-to person in your organization when it comes to MySQL. Starting with a quick installation and configuration of your MySQL instance, the book quickly jumps into the querying aspects of MySQL. It shows you the newest improvements in MySQL 8 and gives you hands-on experience in managing high-transaction and real-time datasets. If you've already worked with MySQL before and are looking to migrate your application to MySQL 8, this book will also show you how to do that. The book also contains recipes on efficient MySQL administration, with tips on effective user management, data recovery, security, database monitoring, performance tuning, troubleshooting, and more.With quick solutions to common and not-so-common problems you might encounter while working with MySQL 8, the book contains practical tips and tricks to give you the edge over others in designing, developing, and administering your database effectively.Style and approachThis book takes a recipe-based approach to tackling the pain points of SQL developers. It is a comprehensive book full of solutions to common problems faced by SQL administrators and developers alike.

Foire aux questions

Comment puis-je résilier mon abonnement ?
Il vous suffit de vous rendre dans la section compte dans paramĂštres et de cliquer sur « RĂ©silier l’abonnement ». C’est aussi simple que cela ! Une fois que vous aurez rĂ©siliĂ© votre abonnement, il restera actif pour le reste de la pĂ©riode pour laquelle vous avez payĂ©. DĂ©couvrez-en plus ici.
Puis-je / comment puis-je télécharger des livres ?
Pour le moment, tous nos livres en format ePub adaptĂ©s aux mobiles peuvent ĂȘtre tĂ©lĂ©chargĂ©s via l’application. La plupart de nos PDF sont Ă©galement disponibles en tĂ©lĂ©chargement et les autres seront tĂ©lĂ©chargeables trĂšs prochainement. DĂ©couvrez-en plus ici.
Quelle est la différence entre les formules tarifaires ?
Les deux abonnements vous donnent un accĂšs complet Ă  la bibliothĂšque et Ă  toutes les fonctionnalitĂ©s de Perlego. Les seules diffĂ©rences sont les tarifs ainsi que la pĂ©riode d’abonnement : avec l’abonnement annuel, vous Ă©conomiserez environ 30 % par rapport Ă  12 mois d’abonnement mensuel.
Qu’est-ce que Perlego ?
Nous sommes un service d’abonnement Ă  des ouvrages universitaires en ligne, oĂč vous pouvez accĂ©der Ă  toute une bibliothĂšque pour un prix infĂ©rieur Ă  celui d’un seul livre par mois. Avec plus d’un million de livres sur plus de 1 000 sujets, nous avons ce qu’il vous faut ! DĂ©couvrez-en plus ici.
Prenez-vous en charge la synthÚse vocale ?
Recherchez le symbole Écouter sur votre prochain livre pour voir si vous pouvez l’écouter. L’outil Écouter lit le texte Ă  haute voix pour vous, en surlignant le passage qui est en cours de lecture. Vous pouvez le mettre sur pause, l’accĂ©lĂ©rer ou le ralentir. DĂ©couvrez-en plus ici.
Est-ce que MySQL 8 Cookbook est un PDF/ePUB en ligne ?
Oui, vous pouvez accĂ©der Ă  MySQL 8 Cookbook par Karthik Appigatla, Kedar Mohaniraj Vaijanapukar en format PDF et/ou ePUB ainsi qu’à d’autres livres populaires dans Ciencia de la computaciĂłn et Bases de datos. Nous disposons de plus d’un million d’ouvrages Ă  dĂ©couvrir dans notre catalogue.

Informations

Année
2018
ISBN
9781788398442

Using MySQL

In this chapter, we will cover the following recipes:
  • Connecting to MySQL using the command-line client
  • Creating databases
  • Creating tables
  • Inserting, updating, and deleting rows
  • Loading sample data
  • Selecting data
  • Sorting results
  • Grouping results (aggregate functions)
  • Creating users
  • Granting and revoking access to users
  • Selecting data into a file and table
  • Loading data into a table
  • Joining tables
  • Stored procedures
  • Functions
  • Triggers
  • Views
  • Events
  • Getting information about databases and tables

Introduction

We are going to learn a lot of things in the following recipes. Let's take a look at each one in detail.

Connecting to MySQL using the command-line client

So far, you have learned how to install MySQL 8.0 on various platforms. Along with the installation, you will get the command-line client utility called mysql, which we use to connect to any MySQL server.

Getting ready

First you need to know to which server you need to connect. If you have the MySQL server installed on one host and you are trying to connect to the server from a different host (usually called client), you should specify the hostname or IP address of the server and the mysql-client package should be installed on the client. In the previous chapter, you installed both MySQL server and client packages. If you are already on the server (through SSH), you can specify localhost, 127.0.0.1, or ::1.
Second, since you are connected to the server, the next thing you need to specify is to which port you want to connect on the server. By default, MySQL runs on port 3306. So, you should specify 3306.
Now you know where to connect. The next obvious thing is the username and password to log in to the server. You have not created any users yet, so use the root user to connect. While installing, you would have supplied a password, use that to connect. In case you changed it, use the new password.

How to do it...

Connecting to the MySQL client can be done with any of the following commands:
shell> mysql -h localhost -P 3306 -u <username> -p<password>
shell> mysql --host=localhost --port=3306 --user=root --password=<password>
shell> mysql --host localhost --port 3306 --user root --password=<password>
It is highly recommended not to give the password in the command line, instead you can leave the field blank; you will be prompted for a password:
shell> mysql --host=localhost --port=3306 --user=root --password 
Enter Password:
  1. The -P argument (in uppercase) is passed for specifying the port.
  2. The -p argument (in lowercase) is passed for specifying the password.
  3. There is no space after the -p argument.
  4. For the password, there is no space after =.
By default, the host is taken as localhost, the port is taken as 3306, and the user is taken as the current shell user.
  1. To know the current user:
shell> whoami
  1. To disconnect, press Ctrl + D or type exit:
mysql> ^DBye
shell>
Or use:
mysql> exit;
Bye
shell>
  1. After connecting to the mysql prompt, you can execute statements followed by the delimiter. The default delimiter is a semicolon (;):
mysql> SELECT 1;
+---+
| 1 |
+---+
| 1 |
+---+
1 row in set (0.00 sec)
  1. To cancel a command, press Ctrl + C or type \c:
mysql> SELECT ^C
mysql> SELECT \c
Connecting to MySQL using the root user is not recommended. You can create users and restrict the user by granting appropriate privileges, which will be discussed in the Creating Users and Granting and revoking access to users sections. Till then, you can use the root user to connect to MySQL.

See also

After connecting, you might have noticed a warning:
Warning: Using a password on the command line interface can be insecure.
To learn about the secure ways of connecting, refer to Chapter 14, Security.
Once you are connected to the command-line prompt, you can execute the SQL statements, which can be terminated by ;, \g, or \G.
; or \g—output is displayed horizontally, \G—output is displayed vertically.

Creating databases

Well, you have installed MySQL 8.0 and connected to it. Now it is time to store some data in it, that's what the database is meant for, after all. In any relational database management system (RDBMS), data is stored in rows, which is the basic building block of the database. Rows contain columns in which we can store several set of values.
For example, if you want to store information about your customers in a database.
Here is the dataset:
customer id=1, first_name=Mike, last_name=Christensen country=USA
customer id=2, first_name=Andy, last_name=Hollands, country=Australia
customer id=3, first_name=Ravi, last_name=Vedantam, country=India
customer id=4, first_name= Rajiv, last_name=Perera, country=Sri Lanka
You should save them as rows: (1, 'Mike', 'Christensen', 'USA'), (2, 'Andy', 'Hollands', 'Australia'), (3, 'Ravi', 'Vedantam', 'India'), (4, 'Rajiv', 'Perera', 'Sri Lanka'). For this dataset, there are four rows described by three columns (id, first_name, last_name and country), which are stored in a table. The number of columns that a table can hold should be defined at the time of the creation of the table, which is the major limitation of RDBMS. However, we can alter the definition of the table any time, but the full table should be rebuilt while doing so. In some cases, the table will be unavailable while doing an alter. Altering a table will be discussed in detail in Chapter 9, Table Maintenance.
A database is a collection of many tables, and a database server can hold many of these databases. The flow is as follows:
Database Server —> Databases —> Tables (defined by columns) —> Rows
Databases and tables are referred to as database objects. Any operation, such as creating, modifying, or d...

Table des matiĂšres