Compile and install MySQL 5.6.16 under CentOS6.5

Source: Internet
Author: User

Compile and install MySQL 5.6.16 under CentOS6.5
I. Preparations before MySQL compilation and Installation

Install the tools and libraries required for compiling source code

[SQL] view plaincopy
  1. Yuminstallgccgcc-c ++ ncurses-develperl
Install cmake, download the source code from the http://www.cmake.org and compile and install [SQL] view plaincopy
  1. Wgethttp: // www.cmake.org/files/v2.8/cmake-2.8.10.2.tar.gz
  2. Tar-xzvfcmake-2.8.10.2.tar.gz
  3. Cdcmake-2.8.10.2
  4. ./Bootstrap; make; makeinstall
  5. Cd ~
2. Set MySQL users and groups

New mysql user group

[SQL] view plaincopy
  1. Groupaddmysql
New mysql user [SQL] view plaincopy
  1. Useradd-r-gmysqlmysql
3. Create a directory required by MySQL

Create a mysql installation directory

[SQL] view plaincopy
  1. Mkdir-p/usr/local/mysql
Create a mysql database data file directory [SQL] view plaincopy
  1. Mkdir-p/data/mysqldb
4. Download and decompress the MySQL source package

Download the source code from http://dev.mysql.com/downloads/mysql/and decompress mysql-5.6.16.tar.gz

[SQL] view plaincopy
  1. Wgethttp: // dev.mysql.com/downloads/mysql/mysql-5.6.16.tar.gz
  2. Tar-zxv-fmysql-5.6.16.tar.gz
  3. Cdmysql-5.6.16
V. Compile and install MySQL

From mysql 5.5, mysql source code installation began to use cmake, and the source code compilation configuration script was set.

-DCMAKE_INSTALL_PREFIX = dir_name: Set the mysql installation directory-DMYSQL_UNIX_ADDR = file_name to set the listening socket path, which must be an absolute path name. The default is/tmp/mysql. sock-DDEFAULT_CHARSET = charset_name to set the server's character set.
By default, MySQL uses the latin1 (CP1252 Western Europe) Character Set. The cmake/character_sets.cmake file contains a list of allowed character set names. -DDEFAULT_COLLATION = collation_name: Set the server's sorting rules. -DWITH_INNOBASE_STORAGE_ENGINE = 1
-DWITH_ARCHIVE_STORAGE_ENGINE = 1
-DWITH_BLACKHOLE_STORAGE_ENGINE = 1
-DWITH_PERFSCHEMA_STORAGE_ENGINE = 1 storage engine option:

MyISAM, MERGE, MEMORY, and CSV engines are compiled to the server by default and do not need to be explicitly installed.

Statically compile a storage engine to the server and use-DWITH_engine_STORAGE_ENGINE = 1

Available storage engine values include ARCHIVE, BLACKHOLE, EXAMPLE, FEDERATED, INNOBASE (InnoDB), PARTITION (partitioning support), and PERFSCHEMA (Performance Schema) -DMYSQL_DATADIR = dir_name: Set the mysql database file directory-DMYSQL_TCP_PORT = port_num to set the mysql server listening port. The default value is 3306-DENABLE_DOWNLOADS = bool. Whether to download the optional files. For example, if this option is enabled (set to 1), cmake downloads the test suite used by Google to run unit tests.

Set compilation Parameters

[SQL] view plaincopy
  1. Cmake \
  2. -DCMAKE_INSTALL_PREFIX =/usr/local/mysql \
  3. -DMYSQL_UNIX_ADDR =/usr/local/mysql. sock \
  4. -DDEFAULT_CHARSET = utf8 \
  5. -DDEFAULT_COLLATION = utf8_general_ci \
  6. -DWITH_INNOBASE_STORAGE_ENGINE = 1 \
  7. -DWITH_ARCHIVE_STORAGE_ENGINE = 1 \
  8. -DWITH_BLACKHOLE_STORAGE_ENGINE = 1 \
  9. -DMYSQL_DATADIR =/data/mysqldb \
  10. -DMYSQL_TCP_PORT = 3306 \
  11. -DENABLE_DOWNLOADS = 1
Note: delete the [SQL] view plaincopy file cmakecache.txt after reconfiguring the configuration.
  1. RmCMakeCache.txt
Compile the source code [SQL] view plaincopy
  1. Make
Install [SQL] view plaincopy
  1. Makeinstall
6. Modify the directory owner and group of mysql

Modify the mysql installation directory

[SQL] view plaincopy
  1. Cd/usr/local/mysql
  2. Chown-Rmysql: mysql.
Modify the mysql database file directory
[SQL] view plaincopy
  1. Cd/data/mysqldb
  2. Chown-Rmysql: mysql.
VII. initialize mysql database [SQL] view plaincopy
  1. Cd/usr/local/mysql
  2. Scripts/mysql_install_db -- user = mysql -- datadir =/data/mysqldb
8. Copy the mysql service startup configuration file [SQL] view plaincopy
  1. Cp/usr/local/mysql/support-files/my-default.cnf/etc/my. cnf
Note: If the/etc/my. cnf file exists, it will be overwritten.

IX. Copy the mysql Service Startup Script and add the PATH [SQL] view plaincopy
  1. Cpsupport-files/mysql. server/etc/init. d/mysqld
  2. Vim/etc/profile
  3. <Spanstyle = "color: # FF6666;"> PATH =/usr/local/mysql/bin:/usr/local/mysql/lib: $ PATH </span>
  4. <Spanstyle = "color: # FF6666;"> exportPATH </span>
  5. Source/etc/profile
10. Start the mysql service and add it to auto-start (this step is optional and you can start it yourself later)

Servicemysqldstart
Chkconfig -- level35mysqldon

11. Check whether the mysql service starts [SQL] view plaincopy
  1. Netstat-tulnp | grep3306
  2. Mysql-uroot-p
The password is blank. If you can log on to the land, the installation is successful. 12. Modify the MySQL user root password [SQL] view plaincopy
  1. Mysqladmin-urootpassword '123'
Note: You can also run the Security Settings script to modify the root password of a MySQL user, disable root remote connection, and remove the test database and anonymous users.
[SQL] view plaincopy
  1. /Usr/local/mysql/bin/mysql_secure_installation
13. Possible errors [SQL] view plaincopy
  1. Problem:
  2. StartingMySQL .. TheserverquitwithoutupdatingPIDfile ([FAILED]/mysql/Server03.mylinux.com. pid ).
  3. Solution:
  4. Modify datadir in/etc/my. cnf to point to the correct mysql database file directory
[SQL] view plaincopy
  1. Problem:
  2. ERROR2002 (HY000): Can 'tconnecttolocalmysqlserverthroughsocket '/tmp/mysql. sock' (2)
  3. Solution:
  4. Create a new link or add the-S parameter to mysql to point out the location of mysql. sock.
  5. Ln-s/usr/local/mysql/data/mysql. sock/tmp/mysql. sock
  6. /Usr/local/mysql/bin/mysql-uroot-S/usr/local/mysql/data/mysql. sock

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.