PDA

View Full Version : Installing MySQL on Linux


llbbl
10-22-2004, 09:55 AM
Initial Installation
http://dev.mysql.com/doc/mysql/en/Linux-RPM.html

Post Installation (getting it working)
http://dev.mysql.com/doc/mysql/en/Unix_post-installation.html

# Change location into the top-level directory of your MySQL installation, represented here by BASEDIR:

shell> cd BASEDIR

BASEDIR is likely to be something like `/usr/local/mysql' or `/usr/local'. The following steps assume that you are located in this directory.
# If necessary, run the mysql_install_db program to set up the initial MySQL grant tables containing the privileges that determine how users are allowed to connect to the server. You'll need to do this if you used a distribution type that doesn't run the program for you. 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. To initialize the grant tables, use one of the following commands, depending on whether mysql_install_db is located in the bin or scripts directory:

shell> bin/mysql_install_db --user=mysql
shell> scripts/mysql_install_db --user=mysql

The mysql_install_db script creates the data directory, 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 accounts have no passwords initially. A description of their initial privileges is given in section 2.4.3 Securing the Initial MySQL Accounts. 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_. It is important to make sure that the database directories and files are owned by the mysql login account so that the server has read and write access to them when you run it later. To ensure this, the --user option should be used as shown if you run mysql_install_db as root. Otherwise, you should execute the script while logged in as mysql, in which case you can omit the --user option from the command. mysql_install_db creates several tables in the mysql database: user, db, host, tables_priv, columns_priv, func, and possibly others depending on your version of MySQL. If you don't want to have the test database, you can remove it with mysqladmin -u root drop test after starting the server. If you have problems with mysql_install_db, see section 2.4.2.1 Problems Running mysql_install_db. There are some alternatives to running the mysql_install_db script as it is provided in the MySQL distribution:

* If you want the initial privileges to be different from the standard defaults, you can modify mysql_install_db before you run it. However, a preferable technique is to use GRANT and REVOKE to change the privileges after the grant tables have been set up. In other words, you can run mysql_install_db, and then use mysql -u root mysql to connect to the server as the MySQL root user so that you can issue the GRANT and REVOKE statements. If you want to install MySQL on a lot of machines with the same privileges, you can put the GRANT and REVOKE statements in a file and execute the file as a script using mysql after running mysql_install_db. For example:

shell> bin/mysql_install_db --user=mysql
shell> bin/mysql -u root < your_script_file

By doing this, you can avoid having to issue the statements manually on each machine.
* It is possible to re-create the grant tables completely after they have already been created. You might want to do this if you're just learning how to use GRANT and REVOKE and have made so many modifications after running mysql_install_db that you want to wipe out the tables and start over. To re-create the grant tables, remove all the `.frm', `.MYI', and `.MYD' files in the directory containing the mysql database. (This is the directory named `mysql' under the data directory, which is listed as the datadir value when you run mysqld --help.) Then run the mysql_install_db script again. Note: For MySQL versions older than 3.22.10, you should not delete the `.frm' files. If you accidentally do this, you should copy them back into the `mysql' directory from your MySQL distribution before running mysql_install_db.
* You can start mysqld manually using the --skip-grant-tables option and add the privilege information yourself using mysql:

shell> bin/mysqld_safe --user=mysql --skip-grant-tables &
shell> bin/mysql mysql

From mysql, manually execute the SQL commands contained in mysql_install_db. Make sure that you run mysqladmin flush-privileges or mysqladmin reload afterward to tell the server to reload the grant tables. Note that by not using mysql_install_db, you not only have to populate the grant tables manually, you also have to create them first.

# Start the MySQL server:

shell> bin/mysqld_safe --user=mysql &

For versions of MySQL older than 4.0, substitute bin/safe_mysqld for bin/mysqld_safe in this command. It is important that the MySQL server be run using an unprivileged (non-root) login account. To ensure this, the --user option should be used as shown if you run mysql_safe as root. Otherwise, you should execute the script while logged in as mysql, in which case you can omit the --user option from the command. Further instructions for running MySQL as an unprivileged user are given in section A.3.2 How to Run MySQL as a Normal User. If you neglected to create the grant tables before proceeding to this step, the following message will appear in the error log file when you start the server:

mysqld: Can't find file: 'host.frm'

If you have other problems starting the server, see section 2.4.2.3 Starting and Troubleshooting the MySQL Server.
# 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 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.
# Verify that you can shut down the server:

shell> bin/mysqladmin -u root shutdown

# Verify that you can restart the server. Do this by using mysqld_safe or by invoking mysqld directly. For example:

shell> bin/mysqld_safe --user=mysql --log &

If mysqld_safe fails, see section 2.4.2.3 Starting and Troubleshooting the MySQL 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 |
+-----------+
| mysql |
| test |
+-----------+

shell> bin/mysqlshow mysql
Database: mysql
+--------------+
| Tables |
+--------------+
| columns_priv |
| db |
| func |
| host |
| tables_priv |
| 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 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, and some other additional Perl modules are required to run the benchmark suite. You must have the following modules installed:

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> perl 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 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', 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 MySQL accounts have a password, so you should assign passwords using the instructions in section 2.4.3 Securing the Initial MySQL Accounts.