Book Image

MariaDb Essentials

Book Image

MariaDb Essentials

Overview of this book

This book will take you through all the nitty-gritty parts of MariaDB, right from the creation of your database all the way to using MariaDB’s advanced features. At the very beginning, we show you the basics, that is, how to install MariaDB. Then, we walk you through the databases and tables of MariaDB, and introduce SQL in MariaDB. You will learn about all the features that have been added in MariaDB but are absent in MySQL. Moving on, you’ll learn to import and export data, views, virtual columns, and dynamic columns in MariaDB. Then, you’ll get to grips with full-text searches and queries in MariaDb. You’ll also be familiarized with the CONNECT storage engine. At the end of the book, you’ll be introduced to the community of MariaDB.
Table of Contents (15 chapters)
MariaDB Essentials
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Starting and stopping MariaDB


Depending on how MariaDB is installed, it may or may not start automatically at system startup. On Linux, it starts automatically if it is installed using the deb or rpm package. On Windows, it starts automatically if it is installed as a service. Whether or not MariaDB starts automatically, we will be able to start and stop it manually using the command line. The executable files that we need to call, as well as the client and other tools, are situated in the MariaDB binary directory. Since typing this path every time is not convenient, we will add it to the system paths.

On Linux, this is done by adding the path to the $PATH variable, as in the following example:

export PATH=$PATH:/usr/local/bin

However, this change will be lost when the current user logs out. To make it permanent, we must add the preceding line to the .profile start in our home directory, like in the following example:

echo 'export PATH=$PATH:/usr/local/mysql/bin' >> .bash_profile

On Windows, the procedure to add a path to the PATH variable is easy but it depends on the system version. Here we will see how to add the MariaDB path on Windows 8:

  1. Open the Control Panel. Click on the System icon, and then on Advanced. Click on the Environment Variables button. Select PATH, and modify it in the Edit window. Add the path to your MariaDB binary directory. Click on OK.

On other Windows versions, we can check the system's documentation for the correct procedure to use.

Now we can start MariaDB by invoking the server executable, as follows:

mysqld

This command starts a MariaDB demon, the programs which will remain active and waiting for client connections. However, this is not the recommended way to start MariaDB on Linux/UNIX systems. Instead, we can run the mysqld_safe script, which starts mysqld, and constantly checks if it is active. If mysqld crashes, mysqld_safe tries to restart it. It can be invoked in the following way:

mysqld_safe

Many options can be passed to mysqld or mysqld_safe. Most of them should only be used by advanced users and only on rare occasions; thus, they are beyond the purpose of this book. However, we will see some basic options in the Configuring MariaDB section of this chapter. Meanwhile, we can simply start MariaDB with the default values.

To stop MariaDB, we need a user with the SHUTDOWN privilege. We will pass the user's credentials (username and password) to the mysqladmin utility along with the shutdown option. So, provided that the password for the root user is saoirse, the following example will work:

mysqladmin shutdown -uroot -psaoirse

The -u option specifies a username, and the -p option specifies a password. Note that no space is needed after these options.

Sometimes, it could be more convenient to use the SHUTDOWN SQL command, as shown in the following example:

MariaDB [(none)]> SHUTDOWN;
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> SELECT version();
ERROR 2006 (HY000): MySQL server has gone away
No connection. Trying to reconnect...
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2 "No such file or directory")
ERROR: Can't connect to the server