MySQL has two installation methods: source code package installation and Binary Package installation. These two methods have their own characteristics: two-pack installation requires no compilation, and different binary files and package formats have been optimized and compiled for different platforms, which is easy to install; the source code package must be configured and compiled before installation. You can optimize the package based on your host environment, select the best configuration value, and make installation and customization more flexible. The following describes the two installation methods.
3.1 source code package installation
3.1.1 Add users and groups running Mysql in linux
/Usr/sbin/groupadd mysql
/Usr/sbin/useradd-d/var/lib/mysql-s/sbin/nologin-g mysql
3.1.2 download MySQL software of the latest stable release (GA)
Visit the MySQL website http://dev.mysql.com/downloads/download the latest stable version of mysqlsource code package. This document uses version 5.0.51 and downloads it using the following command in linux:
Wget http://mysql.mirror.kangaroot.ne... mysql-5.0.51.tar.gz
3.1.3 decompress the downloaded source code package
First, create a working directory (the recommended directory is/usr/local/src/MySQL ):
Mkdir-P/usr/local/src/MySQL
Move the downloaded source code package to the working directory:
Music mysql-5.0.51.tar.gz/usr/local/src/MySQL
Go to the working directory and run the tar command to decompress the source package:
CD/usr/local/src/MySQL
Tar zxvf mysql-5.0.51.tar.gz
After the command is executed, a new subdirectory mysql-5.0.51 is generated under the current working directory, which is the MySQL source code file.
3.1.4 configure the MAKEFILE file
Go to the MySQL source code directory:
Cd mysql-5.0.51
Run the following command to view the configurable options:
./Configure -- help
The configuration command format used in this article is as follows:
CC = gcc CFLAGS = "-O3" CXX = gcc CXXFLAGS = "-O3-felide-constructors-fno-exceptions-fno-rtti ". /configure -- prefix =/usr/local/mysql -- enable-thread-safe-client -- enable-Handler -- with-big-tables -- with-client-ldflags =-all-static -- with-mysqld-ldflags =-all-static -- with-charset = utf8 -- with-collation = utf8_general_ci -- with-extra-charsets = complex
Description of configuration options:
The name of the CC: C compiler (used to run configure). The example in this article is gcc.
CFLAGS: C compiler flag (used to run configure). In this example,-O3 is used to specify the optimization level as 3.
CXX: name of the C ++ Compiler (used to run configure). The example in this article is gcc.
CXXFLAGS: C ++ compiler flag (used to run configure)
-- Prefix: Specifies the installation directory. This example is/usr/local/mysql.
-- Localstatedir: Specifies the default database file storage directory, which is the var directory under the installation directory by default.
-- Enable-thread-safe-client: Compile the MySQL client library of thread security edition.
-- Enable-aggreger: The Assembly version of some character functions.
-- With-client-ldflags: client Link parameter. In this example, the mysql client is statically compiled
-- With-mysqld-ldflags: server-side Link parameter. In this example, the static compilation mysql server is specified.
-- With-big-tables: supports tables larger than 4g rows on 32-bit platforms
-- With-charset: Specifies the default character set. Mysql uses the latin1 (cp1252) Character Set by default. You can use this option to change it. The character sets can be big5, cp1251, cp1257, czech, danish, dec8, dos, euc_kr, gb2312, gbk, german1, hebrew, hp8, hungarian, koi8_ru, expires, latin1, latin2, and, swe7, tis620, ujis, usa7, or win1251ukr.
-- With-collation: Specifies the default proofreading rule. Mysql uses the latin1_swedish_ci proofreading rule by default. You can use this option to change it.
-- With-extra-charsets: the character set to be supported by the server. There are three possible values: A series of Character Set names with space intervals; complex, including all character sets that cannot be dynamically loaded; all, include all character sets in binary. This example is complex.
Note: to change the character set and collation, use the -- with-charset and -- with-collation options at the same time. The collation must be a valid Collation for character sets. (Use the show collation statement in mysql to determine which verification rule is used for each character set ).
3.1.5 compile source code
Run the following command to compile the source code:
Make
3.1.6 Installation
Run the following command to install mysql to the target path:
Make install
3.1.7 copy the default global startup parameter configuration file to the/etc directory.
Source installation needs to manually copy the configuration file, the configuration template is located in the support-Files directory of the source tree, there are my-small.cnf, my-medium.cnf, my-large.cnf, my-huge.cnf four, select a directory similar to your environment, copy it to the/etc directory, and make appropriate modifications. For more information about the MySQL configuration file, see the author's other articles or MySQL official documents.
In this example, select the my-medium.cnf and run the following command to copy it to the/etc directory:
CP./support-files/my-medium.cnf/etc/My. CNF
3.1.8 initialize authorization table
Run the following command to initialize the authorization table:
./Scripts/mysql_install_db -- user = MySQL
3.1.9 change the owner and permissions of the MySQL DATA DIRECTORY
The default database file storage directory is the VaR directory under the installation directory. You can use the -- localstatedir parameter to specify different directories when running the configure command. This example uses the default location.
Chown-r mysql. MySQL/usr/local/MySQL/var
Chmod-r 700/usr/local/MySQL/var
3.1.10 Configure Automatic startup Service Control script
Run the following command to copy the startup script to the Resource Directory:
CP./support-files/MySQL. Server/etc/rc. d/init. d/mysqld
Execute the following command to add the mysqld service control script execution permission:
Chmod + x/etc/rc. d/init. d/mysqld
Run the following command to add the mysqld service to the System Service:
Chkconfig -- add mysqld
Run the following command to check whether the mysqld service has taken effect:
Chkconfig -- list mysqld
Command output is similar to the following result:
Mysqld 0ff 1ff 2n 3N 4N 5N 6ff
It indicates that the mysqld service has taken effect and is automatically started at the 2, 3, 4, and 5 running levels as the system starts. In the future, you can use the service command to control the start and stop of MySQL.
Start the mysqld service:
Service mysqld start
Stop the mysqld service:
Service mysqld stop
Run the following command to disable automatic startup:
Chkconfig mysqld off
Run the following command to change the running level of auto-start to 3 or 5:
Chkconfig -- level 35 mysqld on
3.1.11 Add the bin directory of mysql to the path environment variable
Edit the/etc/profile file:
Vi/etc/profile
Add the following two lines at the end of the file:
PATH = $ PATH:/usr/local/mysql/bin
Export PATH
Run the following command to make the changes take effect:
./Etc/profile
3.2 Binary Package Installation
3.2.1 install from the installation media
The Mysql Binary Package is already included in the installation media of CentOS 5. You can install the following three rpm packages directly from the installation media:
Mysql-5.0.22-2.1.0.1.i386.rpm
Mysql-devel-5.0.22-2.1.0.1.i386.rpm
Mysql-server-5.0.22-2.1.0.1.i386.rpm
Different versions have different file names.
Run the following command to install:
Rpm-iUvh mysql-5.0.22-2.1.0.1.i386.rpm
Rpm-iUvh mysql-devel-5.0.22-2.1.0.1.i386.rpm
Rpm-iUvh mysql-server-5.0.22-2.1.0.1.i386.rpm
3.2.2 Install through yum
If the machine you installed can connect to the Internet at this time, I suggest using the yum command to simplify the installation process:
Yum install mysql-server mysql-devel mysql
Yum will automatically search for the latest Binary Package of the software you specified from the centos image site, check the dependency between the software packages, and automatically install the software packages it depends on when installing the software.
3.2.3 download the latest stable version of Binary Package installation from the mysql website
The binary package version installed through CentOS or yum lags behind the version released on the mysql developer website. You can download and install the latest stable version of mysql from the mysql website.
Visit the MySQL website http://dev.mysql.com/downloads/download the latest stable release version of the corresponding hardware platform mysql. This document uses Red Hat Enterprise Linux 5 rpm (x86) 5.0.45. You need to download several RPM packages for server, client, headers and libraries, share libraries/shared compatibility libraries, and other packages as needed.
Download the following command in Linux:
Wget http://mysql.mirrors.pair.com/Do... 45-0.rhel5.i386.rpm
Wget http://mysql.mirrors.pair.com/Do... 45-0.rhel5.i386.rpm
Wget http://mysql.mirrors.pair.com/Do... 45-0.rhel5.i386.rpm
Wget http://mysql.mirrors.pair.com/Do... 45-0.rhel5.i386.rpm
Wget http://mysql.mirrors.pair.com/Do... 45-0.rhel5.i386.rpm
Run the following command to install:
Rpm-iUvh MySQL-server-community-5.0.45-0.rhel5.i386.rpm
Rpm-iUvh MySQL-client-community-5.0.45-0.rhel5.i386.rpm
Rpm-iUvh MySQL-devel-community-5.0.45-0.rhel5.i386.rpm
Rpm-iUvh MySQL-shared-community-5.0.45-0.rhel5.i386.rpm
Rpm-iUvh MySQL-shared-compat-5.0.45-0.rhel5.i386.rpm
4. MySQL Configuration
4.1 directory structure
4.1.1 install the directory structure using the source code package
When installing the source code package, the following directory structure is usually created in the directory specified by the -- prefix option of the configure command in section 3.1.4, except for the special directories:
./Bin # MySQL user executable file directory
./Include/MySQL # MySQL C header file directory
./INFO # MySQL information file directory
./Lib/MySQL # MySQL library file directory
./Libexec # mysql daemon program directory
./Man # mysql online help document directory
./Mysql-test # mysql test program directory
./Share/mysql # mysql public file directory, including character set, configuration file template, startup script, and SQL file Initialization
./SQL-scripts # mysql stress testing program directory
/Etc/My. CNF # MySQL configuration file
/Etc/rc. d/init. d/mysqld # mysqld service startup script
4.1.2 install the directory structure using the RPM Binary Package
Use the default directory structure of the system software for Binary Package installation:
/Usr/bin # MySQL user executable file directory
/Usr/libexec # MySQL daemon program directory
/Usr/lib/MySQL # MySQL library file directory
/Usr/lib64/mysql # if it is a 64-bit system, the mysql 64-bit library file directory
/Usr/share/doc # mysql document directory
/Usr/share/info # mysql information file directory
/Usr/share/man # mysql online help document directory
/Usr/share/mysql # mysql Character Set Directory
/Usr/include/mysql # mysql C header file directory
/Var/log # mysqld service log file directory
/Var/run/mysqld # mysqld service running status directory
/Var/lib/MySQL # Mysql Data File directory
/Etc/My. CNF # MySQL configuration file
/Etc/rc. d/init. d/mysqld # mysqld service startup script
4.2 configuration file
In Linux, the configuration parameter file of MySQL is my. CNF. Generally, you can find this file in the following order:/etc directory, MySQL installation directory, and MySQL data directory. The configuration template is located in the support-Files directory of the source tree, there are my-small.cnf, my-medium.cnf, my-large.cnf, my-huge.cnf four, for more information about the MySQL configuration file, see the author's other articles or MySQL official documentation.
4.3 start the mysqld service
Run the following command to start MYSQL:
Service mysqld start
4.3 set up a mysql account
After mysql is installed, two accounts are generated by default: one is root, and no password is set. You can log on to mysql from the local machine; the other is an anonymous account, with no account name or password. you can log on from the local machine, all connections without user names are assumed to be this account. This setting poses a security risk. You can change it according to the following steps.
Connect to the mysql server as a root account:
Mysql-u root
If you cannot find the mysql file, try to use the absolute path, as shown in the following example:
/Usr/local/mysql/bin/mysql-u root
After the command is successfully executed, enter the mysql Command Prompt:
Mysql>
(The following commands are all executed at the mysql command prompt)
Change the current database to MySQL:
Use MySQL
Set the password of the root account used to log on from the local host:
Set password for root @ localhost = PASSWORD ('your password ');
Or:
Update user SET Password = PASSWORD ('your password') where user = 'root' and host = 'localhost ';
Delete an anonymous account:
Delete from user where user = '';
Delete an account with a blank password:
Delete from user where Password = '';
Delete accounts that allow non-localhost login:
Delete from user where host <> 'localhost ';
Run the following command to make the change take effect:
Flush privileges;
Run the following command to exit mysql command line:
Quit
Or:
/Q
5. Conclusion
So far, Mysql is basically installed. I hope this article will be helpful to beginners.
This article from the CSDN blog, reproduced please indicate the source: http://blog.csdn.net/xiamizy/archive/2008/01/30/2072525.aspx
Linux (non RPM packages) downloads
# Newuser # Add a user and group named "MySQL" as prompted. You can also use sysinstall to add
# Vi/etc/group # Add a MySQL user to the wheel group (usually ", MySQL" is added to the root). The reason is described later.
# Tar zxvf mysql-5.1.31-linux-686-glibc23.tar.gz
# Mv mysql-5.1.31-linux-686-glibc23/usr/local/MySQL # I installed under/usr/local/MySQL
# Cd/usr/local/MySQL
# Chown-r MySQL.
# Chgrp-r MySQL.
# Su Simon # this step is important. I didn't mention install-binary in MySQL. I tried it for n times. Otherwise, you have to run it as root, that is, when executing scripts/mysql_install_db,-user = MySQL is not specified, or the following step cannot be passed, and no error message is displayed. I have been stuck here for a long time.
$ Scripts/mysql_install_db-user = MySQL # Some warnings may appear here, mainly because of DNS. You can add the-force parameter or add a host name to/etc/hosts.
$ Exit # Because I used Su before, you can change it back to root because you need to start the service.
# Chown-r root.
# Chown-r MySQL.
# Cp support-files/my-xxx.cnf/etc/My. CNF # Use the MySQL configuration file as required
# Support-files/MySQL. server start # If you have added a MySQL user to the wheel group, there should be no problem here, because MySQL needs to add a sock under/tmp, however, the user "MySQL" does not have the write permission for this directory, so we need to make "MySQL" a member of whell.
# Bin/mysqladmin-uroot password 'enter your root password'
Okay, basically done
Verify MySQL run:
# Netstat-Al # Check 3306. If it is started, it indicates it is successful.
# Bin/MySQL-uroot-P # Try to log on. It should be okay.