[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
2.4.2.1 Problems Running mysql_install_db | ||
2.4.2.2 Starting and Stopping MySQL Automatically | ||
2.4.2.3 Starting and Troubleshooting the MySQL Server |
After you install MySQL on Unix, you need to initialize the grant tables, start the server, and make sure that the server works okay. You may also wish to arrange for the server to be started and stopped automatically when your system starts and stops.
Normally you install the grant tables and start the server like this for installation from a source distribution:
shell> cd mysql_installation_directory shell> bin/mysql_install_db shell> bin/mysqld_safe --user=mysql & |
For a binary distribution (not RPM or PKG packages), do this:
shell> cd mysql_installation_directory shell> scripts/mysql_install_db shell> bin/mysqld_safe --user=mysql & |
The mysql_install_db
script creates the mysql
database
that holds all database privileges, and the test
database that
you can use to test MySQL. The script also creates privilege table entries
for root
accounts and anonymous-user accounts.
The entries are created without passwords. The mysqld_safe
script
starts the mysqld
server. (For versions of MySQL older than 4.0,
use safe_mysqld
rather than mysqld_safe
.)
mysql_install_db
will not overwrite any old privilege tables, so
it should be safe to run in any circumstances. If you don't want to
have the test
database you can remove it with mysqladmin -u
root drop test
after starting the server.
Testing is most easily done from the top-level directory of the MySQL distribution. For a binary distribution, this is your installation directory (typically something like `/usr/local/mysql'). For a source distribution, this is the main directory of your MySQL source tree.
In the commands shown in this section and in the following
subsections, BINDIR
is the path to the location in which programs
like mysqladmin
and mysqld_safe
are installed. For a
binary distribution, this is the `bin' directory within the
distribution. For a source distribution, BINDIR
is probably
`/usr/local/bin', unless you specified an installation directory
other than `/usr/local' when you ran configure
.
EXECDIR
is the location in which the mysqld
server is
installed. For a binary distribution, this is the same as
BINDIR
. For a source distribution, EXECDIR
is probably
`/usr/local/libexec'.
Testing is described in detail:
mysqld
server and set up the initial
MySQL grant tables containing the privileges that determine how
users are allowed to connect to the server. This is normally done with the
mysql_install_db
script:
shell> scripts/mysql_install_db |
Typically, mysql_install_db
needs to be run only the first time you
install MySQL. Therefore, if you are upgrading an existing
installation, you can skip this step. (However, mysql_install_db
is
quite safe to use and will not update any tables that already exist, so if
you are unsure of what to do, you can always run mysql_install_db
.)
mysql_install_db
creates six tables (user
, db
,
host
, tables_priv
, columns_priv
, and func
) in the
mysql
database. A description of the initial privileges is given in
5.5.3 Setting Up the Initial MySQL Privileges. Briefly, these privileges allow the MySQL
root
user to do anything, and allow anybody to create or use databases
with a name of test
or starting with test_
.
If you don't set up the grant tables, the following error will appear in the log file when you start the server:
mysqld: Can't find file: 'host.frm' |
This may also happen with a binary MySQL distribution if you
don't start MySQL by executing exactly ./bin/mysqld_safe
.
See section mysqld_safe
.
You might need to run mysql_install_db
as root
. However,
if you prefer, you can run the MySQL server as an unprivileged
(non-root
) user, provided that the user can read and write files in
the database directory. Instructions for running MySQL as an
unprivileged user are given in Changing MySQL user.
If you have problems with mysql_install_db
, see
mysql_install_db
.
There are some alternatives to running the mysql_install_db
script as it is provided in the MySQL distribution:
mysql_install_db
before running it, to change
the initial privileges that are installed into the grant tables. This is
useful if you want to install MySQL on a lot of machines with the
same privileges. In this case you probably should need only to add a few
extra INSERT
statements to the mysql.user
and mysql.db
tables.
mysql_install_db
, then use mysql -u root mysql
to
connect to the grant tables as the MySQL root
user and issue
SQL statements to modify the grant tables directly.
mysql_install_db
.
For more information about these alternatives, see 5.5.3 Setting Up the Initial MySQL Privileges.
shell> cd mysql_installation_directory shell> bin/mysqld_safe & |
For versions of MySQL older than 4.0, substitute bin/safe_mysqld
for bin/mysqld_safe
in the final command.
If you have problems starting the server, see 2.4.2.3 Starting and Troubleshooting the MySQL Server.
mysqladmin
to verify that the server is running. The following
commands provide a simple test to check that the server is up and responding
to connections:
shell> BINDIR/mysqladmin version shell> BINDIR/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> BINDIR/mysqladmin version mysqladmin Ver 8.40 Distrib 4.0.18, for linux on i586 Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB This software comes with ABSOLUTELY NO WARRANTY. This is free software, and you are welcome to modify and redistribute it under the GPL license Server version 4.0.18-log Protocol version 10 Connection Localhost via Unix socket TCP port 3306 UNIX socket /tmp/mysql.sock Uptime: 16 sec Threads: 1 Questions: 9 Slow queries: 0 Opens: 7 Flush tables: 2 Open tables: 0 Queries per second avg: 0.000 Memory in use: 132K Max memory used: 16773K |
To see what else you can do with mysqladmin
,
invoke it with the --help
option.
shell> BINDIR/mysqladmin -u root shutdown |
mysqld_safe
or
by invoking mysqld
directly. For example:
shell> BINDIR/mysqld_safe --log & |
If mysqld_safe
fails, try running it from the MySQL
installation directory (if you are not already there). If that doesn't work,
see 2.4.2.3 Starting and Troubleshooting the MySQL Server.
shell> BINDIR/mysqlshow +-----------+ | Databases | +-----------+ | mysql | +-----------+ shell> BINDIR/mysqlshow mysql Database: mysql +--------------+ | Tables | +--------------+ | columns_priv | | db | | func | | host | | tables_priv | | user | +--------------+ shell> BINDIR/mysql -e "SELECT host,db,user FROM db" mysql +------+--------+------+ | host | db | user | +------+--------+------+ | % | test | | | % | test_% | | +------+--------+------+ |
There is also a benchmark suite in the `sql-bench' directory (under the MySQL installation directory) that you can use to compare how MySQL performs on different platforms. The benchmark suite is written in Perl. It uses the Perl DBI module to provide a database-independent interface to the various databases. The following additional Perl modules are required to run the benchmark suite:
DBI DBD::mysql Data::Dumper Data::ShowTable |
These modules can be obtained from CPAN http://www.cpan.org/. See section 2.7.1 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> run-all-tests |
If you don't have the `sql-bench' directory, you probably installed MySQL using RPM files other than the source RPM. (The source RPM includes the `sql-bench' benchmark directory.) In this case, you must first install the benchmark suite before you can use it. Beginning with MySQL Version 3.22, there are separate benchmark RPM files named `mysql-bench-VERSION-i386.rpm' that contain benchmark code and data.
If you have a source distribution, there are also tests in its `tests' subdirectory that you can run. For example, to run `auto_increment.tst', do this:
shell> BINDIR/mysql -vvf test < ./tests/auto_increment.tst |
The expected result of the test can be found in the `./tests/auto_increment.res' file.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |