Unix Postinstallation Procedures
After installing MariaDB on Unix, you must initialize the grant tables, start the server, and make sure that the server works satisfactorily. You may also wish to arrange for the server to be started and stopped automatically when your system starts and stops. You should also assign passwords to the accounts in the grant tables.
On Unix, the grant tables are set up by the mysql_install_db program. For some installation methods, this program is run for you automatically if an existing database cannot be found.
- If you install MariaDB on Linux using RPM distributions, the server RPM runs mysql_install_db.
- Using the native packaging system on many platforms, including Debian Linux, Ubuntu Linux, Gentoo Linux and others, the mysql_install_db command is run for you.
- If you install MariaDB on Mac OS X using a PKG distribution, the installer runs mysql_install_db.
For other platforms and installation types, including generic binary and source installs, you will need to run mysql_install_db yourself.
The following procedure describes how to initialize the grant tables (if that has not previously been done) and start the server. It also suggests some commands that you can use to test whether the server is accessible and working properly. For information about starting and stopping the server automatically, see , "Starting and Stopping MariaDB Automatically".
After you complete the procedure and have the server running, you should assign passwords to the accounts created by mysql_install_db and perhaps restrict access to test databases. For instructions, see , "Securing the Initial MariaDB Accounts".
In the examples shown here, the server runs under the user ID of the MariaDB
login account. This assumes that such an account exists. Either create the account if it does not exist, or substitute the name of a different existing login account that you plan to use for running the server. For information about creating the account, see Creating a MariaDB
System User and Group, in , "Installing MariaDB from Generic Binaries on Unix/Linux".
- Change location into the top-level directory of your MariaDB installation, represented here by
BASEDIR
:shell>
cd
BASEDIR
BASEDIR
is the installation directory for your MariaDB instance. It is likely to be something like/usr/local/mysql
or/usr/local
. The following steps assume that you have changed location to this directory.You will find several files and subdirectories in the
BASEDIR
directory. The most important for installation purposes are thebin
andscripts
subdirectories:- The
bin
directory contains client programs and the server. You should add the full path name of this directory to yourPATH
environment variable so that your shell finds the MariaDB programs properly. See , "Environment Variables". - The
scripts
directory contains the mysql_install_db script used to initialize theMariaDB
database containing the grant tables that store the server access permissions.
- The
- If necessary, ensure that the distribution contents are accessible to
MariaDB
. If you installed the distribution asMariaDB
, no further action is required. If you installed the distribution asroot
, its contents will be owned byroot
. Change its ownership toMariaDB
by executing the following commands asroot
in the installation directory. The first command changes the owner attribute of the files to theMariaDB
user. The second changes the group attribute to theMariaDB
group.shell>
chown -R mysql .
shell>chgrp -R mysql .
- If necessary, run the mysql_install_db program to set up the initial MariaDB grant tables containing the privileges that determine how users are permitted to connect to the server. You will need to do this if you used a distribution type for which the installation procedure does not run the program for you.
shell>
scripts/mysql_install_db --user=mysql
Typically, mysql_install_db needs to be run only the first time you install MySQL, so you can skip this step if you are upgrading an existing installation, However, mysql_install_db does not overwrite any existing privilege tables, so it should be safe to run in any circumstances.
It might be necessary to specify other options such as
--basedir
or--datadir
if mysql_install_db does not identify the correct locations for the installation directory or data directory. For example:shell>
scripts/mysql_install_db --user=mysql \
--basedir=/opt/mysql/mysql \
--datadir=/opt/mysql/mysql/data
The mysql_install_db script creates the server's data directory with
MariaDB
as the owner. Under the data directory, it creates directories for theMariaDB
database that holds the grant tables and thetest
database that you can use to test MySQL. The script also creates privilege table entries forroot
and anonymous-user accounts. The accounts have no passwords initially. , "Securing the Initial MariaDB Accounts", describes the initial privileges. Briefly, these privileges permit the MariaDBroot
user to do anything, and permit anybody to create or use databases with a name oftest
or starting withtest_
. See , "The MariaDB Access Privilege System", for a complete listing and description of the grant tables.It is important to make sure that the database directories and files are owned by the
MariaDB
login account so that the server has read and write access to them when you run it later. To ensure this if you run mysql_install_db asroot
, include the--user
option as shown. Otherwise, you should execute the script while logged in asMariaDB
, in which case you can omit the--user
option from the command.If you do not want to have the
test
database, you can remove it after starting the server, using the instructions in , "Securing the Initial MariaDB Accounts".If you have trouble with mysql_install_db at this point, see , "Problems Running mysql_install_db".
- Most of the MariaDB installation can be owned by
root
if you like. The exception is that the data directory must be owned byMariaDB
. To accomplish this, run the following commands asroot
in the installation directory:shell>
chown -R root .
shell>chown -R mysql data
- If the plugin directory (the directory named by the
plugin_dir
system variable) is writable by the server, it may be possible for a user to write executable code to a file in the directory usingSELECT ... INTO DUMPFILE
. This can be prevented by makingplugin_dir
read only to the server or by setting--secure-file-priv
to a directory whereSELECT
writes can be made safely. - If you installed MariaDB using a source distribution, you may want to optionally copy one of the provided configuration files from the
support-files
directory into your/etc
directory. There are different sample configuration files for different use cases, server types, and CPU and RAM configurations. If you want to use one of these standard files, you should copy it to/etc/my.cnf
, or/etc/mysql/my.cnf
and edit and check the configuration before starting your MariaDB server for the first time.If you do not copy one of the standard configuration files, the MariaDB server will be started with the default settings.
If you want MariaDB to start automatically when you boot your machine, you can copy
support-files/mysql.server
to the location where your system has its startup files. More information can be found in themysql.server
script itself, and in , "Starting and Stopping MariaDB Automatically". - Start the MariaDB server:
shell>
bin/mysqld_safe --user=mysql &
It is important that the MariaDB server be run using an unprivileged (non-
root
) login account. To ensure this if you run mysqld_safe asroot
, include the--user
option as shown. Otherwise, you should execute the script while logged in asMariaDB
, in which case you can omit the--user
option from the command.For further instructions for running MariaDB as an unprivileged user, see , "How to Run MariaDB as a Normal User".
If the command fails immediately and prints
mysqld ended
, look for information in the error log (which by default is the
file in the data directory).host_name
.errIf you neglected to create the grant tables by running mysql_install_db before proceeding to this step, the following message appears in the error log file when you start the server:
mysqld: Can't find file: 'host.frm'
This error also occurs if you run mysql_install_db as
root
without the--user
option. Remove thedata
directory and run mysql_install_db with the--user
option as described previously.If you have other problems starting the server, see , "Starting and Troubleshooting the MariaDB Server". For more information about mysqld-safe, see , "mysqld_safe - MariaDB Server Startup Script".
- Use mysqladmin to verify that the server is running. The following commands provide simple tests to check whether the server is up and responding to connections:
shell>
bin/mysqladmin version
shell>bin/mysqladmin variables
The output from mysqladmin version varies slightly depending on your platform and version of MySQL, but should be similar to that shown here:
shell>
bin/mysqladmin version
mysqladmin Ver 14.12 Distrib 5.6.6, for pc-linux-gnu on i686 ... Server version 5.6.6 Protocol version 10 Connection Localhost via UNIX socket UNIX socket /var/lib/mysql/mysql.sock Uptime: 14 days 5 hours 5 min 21 sec Threads: 1 Questions: 366 Slow queries: 0 Opens: 0 Flush tables: 1 Open tables: 19 Queries per second avg: 0.000To see what else you can do with mysqladmin, invoke it with the
--help
option. - Verify that you can shut down the server:
shell>
bin/mysqladmin -u root shutdown
- Verify that you can start the server again. Do this by using mysqld_safe or by invoking mysqld directly. For example:
shell>
bin/mysqld_safe --user=mysql &
If mysqld-safe fails, see , "Starting and Troubleshooting the MariaDB Server".
- Run some simple tests to verify that you can retrieve information from the server. The output should be similar to what is shown here:
shell>
bin/mysqlshow
+--------------------+ | Databases | +--------------------+ | information_schema | | mysql | | test | +--------------------+ shell>bin/mysqlshow mysql
Database: mysql +---------------------------+ | Tables | +---------------------------+ | columns_priv | | db | | event | | func | | help_category | | help_keyword | | help_relation | | help_topic | | host | | plugin | | proc | | procs_priv | | servers | | tables_priv | | time_zone | | time_zone_leap_second | | time_zone_name | | time_zone_transition | | time_zone_transition_type | | user | +---------------------------+ shell>bin/mysql -e 'SELECT Host,Db,User FROM db' mysql
+------+--------+------+ | host | db | user | +------+--------+------+ | % | test | | | % | test_% | | +------+--------+------+ - There is a benchmark suite in the
sql-bench
directory (under the MariaDB installation directory) that you can use to compare how MariaDB performs on different platforms. The benchmark suite is written in Perl. It requires the Perl DBI module that provides a database-independent interface to the various databases, and some other additional Perl modules:DBI DBD::mysql Data::Dumper Data::ShowTable
These modules can be obtained from CPAN (http://www.cpan.org/). See also , "Installing Perl on Unix".
The
sql-bench/Results
directory contains the results from many runs against different databases and platforms. To run all tests, execute these commands:shell>
cd sql-bench
shell>perl run-all-tests
If you do not have the
sql-bench
directory, you probably installed MariaDB using RPM files other than the source RPM. (The source RPM includes thesql-bench
benchmark directory.) In this case, you must first install the benchmark suite before you can use it. There are separate benchmark RPM files namedmysql-bench-
that contain benchmark code and data.VERSION
.i386.rpmIf you have a source distribution, there are also tests in its
tests
subdirectory that you can run. For example, to runauto_increment.tst
, execute this command from the top-level directory of your source distribution:shell>
mysql -vvf test < ./tests/auto_increment.tst
The expected result of the test can be found in the
./tests/auto_increment.res
file. - At this point, you should have the server running. However, none of the initial MariaDB accounts have a password, and the server permits permissive access to test databases. To tighten security, follow the instructions in , "Securing the Initial MariaDB Accounts".
The MariaDB 5.6 installation procedure creates time zone tables in the MariaDB
database but does not populate them. To do so, use the instructions in , "MySQL Server Time Zone Support".
To make it more convenient to invoke programs installed in the bin
directory under the installation directory, you can add that directory to your PATH
environment variable setting. That enables you to run a program by typing only its name, not its entire path name. See , "Setting Environment Variables".
You can set up new accounts using the bin/mysql_setpermission script if you install the DBI
and DBD::mysql
Perl modules. See , "mysql_setpermission - Interactively Set Permissions in Grant Tables". For Perl module installation instructions, see , "Perl Installation Notes".
If you would like to use mysqlaccess and have the MariaDB distribution in some nonstandard location, you must change the location where mysqlaccess expects to find the mysql client. Edit the bin/mysqlaccess
script at approximately line 18. Search for a line that looks like this:
$MYSQL = '/usr/local/bin/mysql'; # path to mysql executable
Change the path to reflect the location where mysql actually is stored on your system. If you do not do this, a Broken pipe
error will occur when you run mysqlaccess.