It is a good idea to install and upgrade the required dependent libraries prior to installation, see Using Yum Update installation dependencies in CentOS
First, uninstall the system in the central some MySQL
First check to see if MySQL is installed in the system, and uninstall it first if installed.
#查看系统中是否有以rpm方式安装的mysql
[Root@localhost/]# Rpm-qa | Grep-i MySQL
# If you have some words, use the RPM-E command to uninstall them, such as:
[Root@localhost/]# rpm-e mysql-server-5.1.65-1.glibc23
# Check to see if there is a MySQL service in the system
[root@localhost/]# chkconfig--list | Grep-i MySQL
# If any, use the Chkconfig--del command to uninstall
[Root@localhost/]# chkconfig--del MySQL
# Find out if there are any MySQL files, and then use RM-RF to remove them
[Root@localhost/]# Whereis MySQL
# Find MySQL profile, open my.cnf file, search DataDir, and then delete the corresponding directory
[Root@localhost/]# Whereis my.cnf
# Delete my.cnf file at last
Second, download the source code and install
1. Download and extract MySQL
[Root@localhost downloads]# wget-c http://dev.mysql.com/get/Downloads/MySQL-5.1/mysql-5.1.65.tar.gz/from/http:// cdn.mysql.com/
[Root@localhost downloads]# tar xzvf mysql-5.1.65.tar.gz
2. Compile and install MySQL
[Root@localhost downloads]# CD mysql-5.1.65
[Root@localhost mysql-5.1.65]#./configure--prefix=/usr/local/mysql--with-charset=utf8--with-extra-charsets=all- -without-debug--enable-thread-safe-client--enable-assembler--with-client-ldflags=-all-static-- With-mysqld-ldflags=-all-static--with-big-tables--with-readline--with-ssl--with-embedded-server-- Enable-local-infile
[Root@localhost mysql-5.1.65]# make && make install
Where configure is used for configuration information, you can use the./configure--help to view the meaning of all parameters.
A few commonly used parameters:
--prefix=/usr/local/mysql # Specify the installation directory for the MySQL program
--with-charset=utf8 # Specifies the default encoding for the database
--with-extra-charsets=all # Specifies the encoding that the database supports, all means all, or you can use Gbk,gb2312,utf8 to specify the specific encoding
--without-debug # Remove debug mode, recommended enable, improve MySQL performance
--enable-thread-safe-client # To compile the client in a threaded fashion
--enable-assembler # Use the general operator of the assembler x86 to improve performance
--with-client-ldflags=-all-static # Compiles clients in a purely static manner, improving performance
--with-mysqld-ldflags=-all-static # to build the server in a pure static way, improve performance
--with-big-tables # By default MyISAM single table maximum support 2^32 bar data, this parameter can make this number (2^32) ^2
--with-readline # through the ReadLine, you can easily move above the command line, delete, copy, paste, search
--WITH-SSL # supports SSL connections
--with-embedded-server # compiled into embedded MySQL library (LIBMYSQLD.A)
--enable-local-infile # let MySQL support importing databases from local files
--without-innodb # Disables the InnoDB engine (mysql5.1.x does not support the InnoDB engine after the system defaults)
After--with-plugins=innobase # mysql5.1.x, you need to use this method to enable MySQL to support the InnoDB engine
--sysconfdir=/etc/# mysql configuration file store path, default to/etc
# The following options can be set directly in the MySQL configuration file
--with-tcp-port=3306 # Sets the port of the database, defaults to 3306
--with-unix-socket-path=/tmp/mysql.sock # Use UNIX socket links to improve performance, default to/tmp/mysql.sock
--localstatedir=/usr/local/mysql/database # Log, data file directory
PS: If you find that the installation of MySQL after the installation directory does not have files, you can see if the installation of the command is wrong. I just made && make install into made && install, and it took me an afternoon to figure out why.
3. Create MySQL-specific user name and user group
[Root@localhost mysql-5.1.65]# Groupadd MySQL
[Root@localhost mysql-5.1.65]# useradd-s/sbin/nologin-m-g MySQL MySQL
4. Set permissions and install the database
[Root@localhost mysql-5.1.65]# Cd/usr/local/mysql
# Set installation directory permissions to MySQL users and user groups
[Root@localhost mysql]# chown-r MySQL.
[Root@localhost mysql]# chgrp-r MySQL.
# Install Database
[Root@localhost mysql]# bin/mysql_install_db--user=mysql
[Root@localhost mysql]# chown-r root.
[root@localhost mysql]# Chown-r mysql var
5. Set the MySQL configuration file
# set up MySQL configuration file, you can choose according to the specific situation
[Root@localhost mysql]# CP share/mysql/my-medium.cnf/etc/my.cnf
# Replace the skip-locking in the configuration file with the Skip-external-locking
[Root@localhost mysql]# sed-i ' s/skip-locking/skip-external-locking/g '/etc/my.cnf
6. Start MySQL, set the database root password and set to boot
[Root@localhost mysql]# CP Share/mysql/mysql.server/etc/init.d/mysql
[Root@localhost mysql]# chmod +x/etc/init.d/mysql
[Root@localhost mysql]#/etc/init.d/mysql start
# set the MySQL root password
[root@localhost mysql]# bin/mysqladmin-uroot Password 123
# because there is a password in the action record, remove the operation record (optional)
[Root@localhost mysql]# History-c
[Root@localhost mysql]#/etc/init.d/mysql Restart
# set MySQL to boot (this step can be omitted if you use the following procedure to set up a service)
[Root@localhost mysql]# cat >>/etc/rc.local <<eof
>/etc/init.d/mysql Start
> EOF
7. Set MySQL as the service (optional)
# First guaranteed to execute the CP Share/mysql/mysql.server/etc/init.d/mysql
# Add MySQL for service
[Root@localhost mysql]# chkconfig--add MySQL
[Root@localhost mysql]# chkconfig--level 345 MySQL on
# start MySQL using the service
[root@localhost mysql]# service MySQL start
PS: I'm installing innodb support, but if I don't add--with-plugins=innobase to my configuration entry, I can't find what the author says "/usr/local/mysql/lib/mysql/plugin/ha_ innodb.so "file, I think it should be in the way of the non-source installation.
Third, start multiple MySQL instances
To run multiple instances, use the Bin/mysqld_multi program:
# Use the following command to view the instances of the configuration
[Root@localhost mysql]# Bin/mysqld_multi--example
[Mysqld_multi]
Mysqld =/usr/local/mysql/bin/mysqld_safe
Mysqladmin =/usr/local/mysql/bin/mysqladmin
user = Multi_admin
Password = My_password
[Mysqld2]
Socket =/tmp/mysql.sock2
Port = 3307
Pid-file =/usr/local/mysql/var2/hostname.pid2
DataDir =/usr/local/mysql/var2
Language =/usr/local/mysql/share/mysql/english
user = Unix_user1
[MYSQLD3]
Mysqld =/path/to/mysqld_safe
Ledir =/path/to/mysqld-binary/
Mysqladmin =/path/to/mysqladmin
Socket =/tmp/mysql.sock3
Port = 3308
Pid-file =/usr/local/mysql/var3/hostname.pid3
DataDir =/usr/local/mysql/var3
Language =/usr/local/mysql/share/mysql/swedish
user = Unix_user2
[Mysqld4]
Socket =/tmp/mysql.sock4
Port = 3309
Pid-file =/usr/local/mysql/var4/hostname.pid4
DataDir =/USR/LOCAL/MYSQL/VAR4
Language =/usr/local/mysql/share/mysql/estonia
user = Unix_user3
[Mysqld6]
Socket =/tmp/mysql.sock6
Port = 3311
Pid-file =/usr/local/mysql/var6/hostname.pid6
DataDir =/USR/LOCAL/MYSQL/VAR6
Language =/usr/local/mysql/share/mysql/japanese
user = Unix_user4
The configuration items in the first three lines under [mysqld3] in the example are superfluous and can be deleted.
First use [Mysqld_multi] to explain the need to run multiple instances of MySQL, and then the following [Mysqld2] ... [MYSQLD6] represents multiple instances in which configuration items are specified separately. MYSQLDN and mysqld The following options and meanings are the same.
1. Place the following configuration information on the last side of the my.conf:
[Mysqld_multi]
Mysqld =/usr/local/mysql/bin/mysqld_safe
Mysqladmin =/usr/local/mysql/bin/mysqladmin
[Mysqld2]
Socket =/tmp/mysql.sock2
Port = 3307
Pid-file =/usr/local/mysql/var2/hostname.pid2
DataDir =/usr/local/mysql/var2 # #数据库的数据文件
user = MySQL
[MYSQLD3]
Socket =/tmp/mysql.sock3
Port = 3308
Pid-file =/usr/local/mysql/var3/hostname.pid3
DataDir =/usr/local/mysql/var3 # #数据库的数据文件
user = MySQL
2. Initializing the database
# Create the directory where the database is located and set permissions that need to be consistent with the settings in the configuration file
[Root@localhost mysql]# Mkdir/usr/local/mysql/var2
[Root@localhost mysql]# Mkdir/usr/local/mysql/var3
# Set permissions
[Root@localhost mysql]# chown-r mysql/usr/local/mysql/var2
[Root@localhost mysql]# chown-r Mysql/usr/local/mysql/var3
# Create a database file
[Root@localhost mysql]# bin/mysql_install_db--user=mysql--datadir=/usr/local/mysql/var2
[Root@localhost mysql]# bin/mysql_install_db--user=mysql--datadir=/usr/local/mysql/var3
3. Start MySQL Instance
[Root@localhost mysql]# bin/mysqld_multi start 2
[Root@localhost mysql]# bin/mysqld_multi start 3
# View Run status
[Root@localhost mysql]# Bin/mysqld_multi
Reporting MySQL Servers
MySQL server from Group:mysqld2 is running
MySQL server from GROUP:MYSQLD3 is running
The following number corresponds to the number following the mysqld in the configuration file. In addition, Mysqld_multi also supports a startup/shutdown similar to this:
# startup option groups [Mysql8] and [MYSQLD10] to [Mysqld13],stop are similar
[Root@localhost mysql]# bin/mysqld_multi start 8,10-13
Note: If the warning:my_print_defaults command not found appears when it is started. Error, you need to add the bin directory under the MySQL installation directory to the environment variable:
[Root@localhost mysql]# Vim/etc/profile
# Add content at the end of the file
Export Path=/usr/local/mysql/bin: $PATH
[Root@localhost mysql]# Source/etc/profile
4. Set the password for database root
# If the current root password is empty, you can not add the-p argument
[root@localhost mysql]# bin/mysqladmin-h127.0.0.1-p3307-uroot-p Password 123
[root@localhost mysql]# bin/mysqladmin-h127.0.0.1-p3308-uroot-p Password 123
# Use the MySQL command test (must add-h127.0.0.1 parameter, otherwise will enter the default database)
[Root@localhost mysql]# Bin/mysql-h127.0.0.1-p3307-uroot-p
5. Set MySQL to boot
[Root@localhost mysql]# cat >>/etc/rc.local <<eof
>/usr/local/mysql/bin/mysqld_multi start 2-3
> EOF