[MySQL]: Installation
Installing MySQL from RPM Packages on Linux
For non-RPM Linux distributions, you can install MySQL using a .tar.gz package.
MySQL-server-VERSION.glibc23.i386.rpm
The MySQL server. You need this unless you only want to connect to a MySQL server running on another machine.
MySQL-client-VERSION.glibc23.i386.rpm
The standard MySQL client programs. You probably always want to install this package to connect to the servers.
MySQL-devel-VERSION.glibc23.i386.rpm
The libraries and include files that are needed if you want to compile other MySQL clients, such as the Perl modules.
MySQL-shared-VERSION.glibc23.i386.rpm
This package contains the shared libraries (libmysqlclient.so*) that certain languages and applications need to dynamically load and use MySQL. It contains single-threaded and thread-safe libraries. If you install this package, do not install the MySQL-shared-compat package.
MySQL-shared-compat-VERSION.glibc23.i386.rpm
This package includes the shared libraries for MySQL 3.23, 4.0, and so on, up to the current release. It contains single-threaded and thread-safe libraries. Install this package instead of MySQL-shared if you have applications installed that are dynamically linked against older versions of MySQL but you want to upgrade to the current version without breaking the library dependencies.
Installing MySQL from a Standard Source Distribution
Directory | Contents of Directory |
bin | Client programs and scripts |
Var | Log files, databases |
docs | Manual in Info format |
man | Unix manual pages |
Include/mysql | Include (header) files |
Lib/mysql | Libraries |
Libexec | The mysqld server |
share/mysql
|
Miscellaneous support files, including error messages, sample configuration files, SQL for database installation |
sql-bench | Benchmarks |
# Preconfiguration setup
shell> groupadd mysql
shell> useradd -g mysql mysql
# Beginning of source-build specific instructions
shell> tar zxvf mysql-VERSION.tar.gz
shell> cd mysql-VERSION
shell> ./configure –prefix=/usr/local/mysql
shell> make
shell> make install
# End of source-build specific instructions
# Postinstallation setup
shell> cd /usr/local/mysql
shell> chown -R mysql .
shell> chgrp -R mysql .
shell> bin/mysql_install_db –user=mysql
shell> chown -R root .
shell> chown -R mysql var
# Next command is optional
shell> cp support-files/my-medium.cnf /etc/my.cnf
shell> bin/mysqld_safe –user=mysql &
# Next command is optional
shell> cp support-files/mysql.server /etc/init.d/mysql.server
Installing MySQL from Generic Binaries on Unix/Linux
Directory | Contents of Directory |
bin | Client programs and the mysqld server |
data | Log files, databases |
docs | Manual in Info format |
man | Unix manual pages |
include | Include (header) files |
Lib | Libraries |
scripts | mysql_install_db |
share | Miscellaneous support files, including error messages, sample configuration files, SQL for database installation |
sql-bench | Benchmarks |
shell> groupadd mysql
shell> useradd -r -g mysql mysql
shell> cd /usr/local
shell> tar zxvf /path/to/mysql-VERSION-OS.tar.gz
shell> ln -s full-path-to-mysql-VERSION-OS mysql
shell> cd mysql
shell> chown -R mysql .
shell> chgrp -R mysql .
shell> scripts/mysql_install_db –user=mysql
shell> chown -R root .
shell> chown -R mysql data
# Next command is optional
shell> cp support-files/my-medium.cnf /etc/my.cnf
shell> bin/mysqld_safe –user=mysql &
# Next command is optional
shell> cp support-files/mysql.server /etc/init.d/mysql.server
Setting Environment Variables
# vi .bash_profile
export MySQL_HOME=/usr/local/mysql
#PATH=$PATH:$HOME/bin
PATH=$PATH:$HOME/bin:$MySQL_HOME
export MYSQL_HOME=’localhost’
export USER=’localhost’ Only on Win and Netware
export MYSQL_PWD=’localhost’
- MySQL Installation related Programs
mysql_fix_privilege_tables is an older script that previously was used to uprade the system tables in the mysql database after a MySQL upgrade.
As of MySQL 5.0.19, mysql_fix_privilege_tables is superseded by mysql_upgrade, which should be used instead.
Before running mysql_fix_privilege_tables, make a backup of your mysql database.
On Unix or Unix-like systems, update the system tables by running the mysql_fix_privilege_tables script:
shell> mysql_fix_privilege_tables –password=XXX
mysql_install_db initializes the MySQL data directory and creates the system tables that it contains, if they do not exist.
shell> bin/mysql_install_db –user=mysql –basedir=/opt/mysql/mysql –datadir=/opt/mysql/mysql/data
bootstrap This option is used by the mysql_install_db script to create the MySQL privilege tables without having to start a full MySQL server
mysql_secure_installation
This program enables you to improve the security of your MySQL installation in the following ways:
- You can set a password for root
- You can remove root accounts that are accessible from outside the local host.
- You can remove anonymous-user accounts.
- You can remove the test database (which by default can be accessed by all users, even anonymous users)
shell> mysql_secure_installation
mysql_tzinfo_to_sql
The mysql_tzinfo_to_sql program loads the time zone tables in the mysql database. It is used on systems that have a zoneinfo database (the set of files describing time zones). Examples of such systems are Linux, FreeBSD, Solaris, and Mac OS X. One likely location for these files is the “/usr/share/zoneinfo” directory
shell> mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root mysql
MySQL Server and Server-Startup Programs:
mysqld — The MySQL Server
mysqld, also known as MySQL Server, is the main program that does most of the work in a MySQL installation. MySQL Server manages access to the MySQL data directory that contains databases and tables. The data directory is also the default location for other information such as log files and status files.
When MySQL server starts, it listens for network connections from client programs and manages access to databases on behalf of those clients.
The mysqld program has many options that can be specified at startup. For a complete list of options, run this command:
shell> mysqld –verbose –help
Command to start mysql
shell> mysqld –user=mysql // (–console)
MySQL Server also has a set of system variables that affect its operation as it runs. System variables can be set at server startup, and many of them can be changed at runtime to effect dynamic server reconfiguration. MySQL Server also has a set of status variables that provide information about its operation. You can monitor these status variables to access runtime performance characteristics.
mysqld_safe — MySQL Server Startup Script
mysqld_safe is the recommended way to start a mysqld server on Unix and NetWare. mysqld_safe adds some safety features such as restarting the server when an error occurs and logging runtime information to an error log file.
mysqld_safe reads all options from the [mysqld], [server], and [mysqld_safe] sections in option files.
The mysqld_safe script is written so that it normally can start a server that was installed from either a source or a binary distribution of MySQL, even though these types of distributions typically install the server in slightly different locations. (See Section 2.7, “Installation Layouts”.) mysqld_safe expects one of the following conditions to be true:
The server and databases can be found relative to the working directory (the directory from which mysqld_safe is invoked). For binary distributions, mysqld_safe looks under its working directory for bin and data directories. For source distributions, it looks for libexec and var directories. This condition should be met if you execute mysqld_safe from your MySQL installation directory (for example, /usr/local/mysql for a binary distribution).
If the server and databases cannot be found relative to the working directory, mysqld_safe attempts to locate them by absolute path names. Typical locations are /usr/local/libexec and /usr/local/var. The actual locations are determined from the values configured into the distribution at the time it was built. They should be correct if MySQL is installed in the location specified at configuration time.
–basedir=path
The path to the MySQL installation directory.
–help
Display a help message and exit
–defaults-extra-file=path
The name of an option file to be read in addition to the usual option files.
–log-error=file_name
Write the error log to the given file
–ledir=path
If mysqld_safe cannot find the server, use this option to indicate the path name to the directory where the server is located
–no-defaults
Do not read any option files. This must be the first option on the command line if it is used.
–defaults-file=file_name
The name of an option file to be read instead of the usual option files. This must be the first option on the command line if it is used.
–mysqld-version=suffix
This option is similar to the –mysqld option, but you specify only the suffix for the server program name. The basename is assumed to be mysqld. For example, if you use –mysqld- version=debug, mysqld_safe starts the mysqld-debug program in the ledir directory. If the argument to –mysqld-version is empty,mysqld_safe uses mysqld in the ledir directory.
–open-files-limit=count
The number of files that mysqld should be able to open. The option value is passed to ulimit -n. Note that you need to start mysqld_safe as root for this to work properly!
–pid-file=file_name
The path name of the process ID file.
–port=port_num
The port number that the server should use when listening for TCP/IP connections. The port number must be 1024 or higher unless the server is started by the root system user.
–socket=path
The Unix socket file that the server should use when listening for local connections.
mysql.server — MySQL Server Startup Script
MySQL distributions on Unix include a script named mysql.server . It can be used on systems such as Linux and Solaris that use System V-style run directories to start and stop system services. It is also used by the Mac OS X Startup Item for MySQL. mysql.server can be found in the support-files directory under your MySQL installation directory or in a MySQL source distribution.
–basedir=path
The path to the MySQL installation directory.
–datadir=path
The path to the MySQL data directory.
–pid-file=file_name
The path name of the file in which the server should write its process ID.
–service-startup-timeout=file_name
How long in seconds to wait for confirmation of server startup. If the server does not start within this time, mysql.server exits with an error. The default value is 900. A value of 0 means not to wait at all for startup. Negative values mean to wait forever (no timeout). This option was added in MySQL 5.1.17. Before that, a value of 900 is always used.
–use-mysqld_safe
Use mysqld_safe to start the server. This is the default.
–user=user_name
The login user name to use for running mysqld.
mysqld_multi ― Manage Multiple MySQL Servers