官术网_书友最值得收藏!

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
主站蜘蛛池模板: 遵义县| 长岭县| 长岛县| 子长县| 贡嘎县| 会昌县| 依安县| 措美县| 衡水市| 乡城县| 连江县| 綦江县| 盘山县| 金华市| 资中县| 甘孜县| 伊金霍洛旗| 任丘市| 平顶山市| 怀远县| 沭阳县| 南陵县| 舒城县| 双城市| 乌兰浩特市| 舞阳县| 蓬莱市| 凌源市| 高雄市| 临洮县| 岑溪市| 翁源县| 辰溪县| 商丘市| 光泽县| 临泽县| 确山县| 顺平县| 报价| 合江县| 丹凤县|