MariaDB Crash Course - Ben Forta [9]
There are many client application options, but when learning MariaDB (and indeed, when writing and testing MariaDB scripts) you are best off using a utility designed for just that purpose. Two tools in particular warrant specific mention.
mysql Command Line
Every MariaDB installation comes with a simple command line utility called mysql. This utility does not have any drop-down menus, fancy user interfaces, mouse support, or anything like that.
Typing mysql at your operating system command prompt displays a welcome message followed by a simple prompt that looks like this:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 1
Server version: 5.2.4-MariaDB Source distribution
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL v2
license
Type 'help;' or '\h' for help. Type '\c' to clear the current input
statement.
MariaDB [(none)]>
* * *
Note: MySQL Options and Parameters
If you just type mysql by itself, you might receive an error message. This will likely be because security credentials are needed or because MySQL is not running locally or on the default port. mysql accepts an array of command line parameters you can (and might need to) use. For example, to specify a user login name of ben, you’d use mysql –u ben. To specify a username, host name, port, and be prompted for a password, you’d use mysql –u ben –p –h myserver –P 9999.
A complete list of command line options and parameters can be obtained using mysql --help.
* * *
Of course, your version and connection information might differ, but you’ll be able to use this utility regardless. Note that:
• Commands are typed after the MariaDB > prompt. (MariaDB > indicates that you are connected to a MariaDB server, the prompt would be MySQL > if you were connected to a MySQL server.)
• Commands end with ; or \g; in other words, just pressing Enter will not execute the command.
• You can use the up and down arrow keys to scroll through previously entered commands.
• You can type help or \h to obtain help. You can also provide additional text to obtain help on specific commands (for example, help select to obtain help on using the SELECT statement).
• You can type quit or exit to quit the command line utility.
* * *
Note: Execute Saved Scripts
You can use mysql to execute saved scripts—the scripts used to create and populate the tables used throughout this book, for example. To do this, enter \. filename (specifying the full path to the file) and press Enter. Appendix B, “The Example Tables,” walks you through this process for the chapters in this book.
* * *
The mysql command line utility is one of the most used, and is invaluable for quick testing and executing scripts (such as the sample table creation and population scripts mentioned in the previous chapter and in Appendix B). In fact, all the output examples used in this book are captured from mysql command line output.
* * *
Tip: Familiarize Yourself with the mysql Command Line
Even if you opt to use a graphical tool like the one described next, you should make sure to familiarize yourself with the mysql command line utility, as this is the one client you can safely rely on to always be present (as it is part of the core MariaDB installation).
* * *
MySQL Workbench
MySQL Workbench is a graphical interactive client designed to simplify the administration of MySQL servers. And, as you’d expect, it works really well with MariaDB, as well.
* * *
Note: Obtaining MySQL Workbench
MySQL Workbench is not installed as part of the MariaDB installation (nor MySQL installations, actually). Instead, it must be downloaded from http://wb.mysql.com/ (versions are available for Linux, Mac OS X, and Windows, and source code is downloadable, too).
* * *
When MySQL Workbench is launched, you see a screen organized in three columns. From left to right these are:
• SQL Development