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
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
MariaDb Essentials

You're reading from   MariaDb Essentials Quickly get up to speed with MariaDB—the leading, drop-in replacement for MySQL, through this practical tutorial

Arrow left icon
Product type Paperback
Published in Oct 2015
Publisher
ISBN-13 9781783982868
Length 206 pages
Edition 1st Edition
Tools
Arrow right icon
Toc

Table of Contents (10) Chapters Close

Preface 1. Installing MariaDB 2. Databases and Tables FREE CHAPTER 3. Getting Started with SQL 4. Importing and Exporting Data 5. Views and Virtual Columns 6. Dynamic Columns 7. Full-Text Searches 8. Using the CONNECT Storage Engine 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
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image