How to compile and install MySQL database in CentOS

Source: Internet
Author: User
Overview: in CentOS6.4, MySQL installed through yum is version 5.1, so I want to install the higher version 5.6.14 through the source code. Body: 1: uninstall the command below the old version of the application to check whether MySQLServerrpm-qa is installed | if grepmysql is installed, uninstall the rpm-emysql // common deletion mode through the command below. Overview:

In CentOS6.4, MySQL installed through yum is version 5.1, so I want to install a higher version of 5.6.14 through the source code.

Body: I. uninstall the old version

Run the following command to check whether MySQL Server is installed.


Rpm-qa | grep Mysql

If yes, uninstall it through the order below.


Rpm-e mysql // common deletion mode
Rpm-e -- nodeps mysql // strong deletion mode. if the system prompts that other files are attached when the command above the application is deleted, use this command to forcibly delete the files.

II. install MySQL Install the packages required for compiling code
Yum-y install make gcc-c ++ cmake bison-devel ncurses-devel

MySQL 5.6.14
Wget http://cdn.mysql.com/Downloads/MySQL-5.6/mysql-5.6.14.tar.gz
Tar xvf mysql-5.6.14.tar.gz
Cd mysql-5.6.14

Compile and install
Cmake-DCMAKE_INSTALL_PREFIX =/usr/local/mysql-DMYSQL_DATADIR =/usr/local/mysql/data-DSYSCONFDIR =/etc-region = 1-region = 1-region = 1-DWITH_READLINE = 1-DMYSQL_UNIX_ADDR =/var/lib/mysql. sock-DMYSQL_TCP_PORT = 3306-DENABLED_LOCAL_INFILE = 1-character = 1-DEXTRA_CHARSETS = all-DDEFAULT_CHARSET = utf8-DDEFAULT_COLLATION = utf8_general_ci
Make & make install

For compilation parameters, see http://dev.mysql.com/doc/refman/5.5/en/source-configuration-options.html.

The entire process takes 30 minutes ...... Long waiting

III. device MySQL Set permissions

Run the following command to check whether mysql users and user groups exist.


Cat/etc/passwd view user list
Cat/etc/group View user group list

Create if no


Groupadd mysql
Useradd-g mysql

Correct/usr/local/mysql permissions


Chown-R mysql: mysql/usr/local/mysql

Correct/usr/local/mysql permissions

Device Initialization

Enter the installation path


Cd/usr/local/mysql

Enter the installation path, perform the initialization device script, and create the database and table that comes with the system.


Scripts/mysql_install_db -- basedir =/usr/local/mysql -- datadir =/usr/local/mysql/data -- user = mysql

Note: When starting MySQL services, it will follow the inevitable order to search my. cnf, which is first found in the/etc directory. if it cannot be found, it will search for "$ basedir/my. cnf ", in this example/usr/local/mysql/my. cnf, which is the default position of the new MySQL device file! Note: After the minimal installation of the CentOS Operating system is completed, there will be a my in the/etc directory. cnf. you need to rename this file to another name, such as/etc/my. cnf. bak. Otherwise, the file will interfere with the correct MySQL device installed in the source code, resulting in a failure to start.

Start MySQL

Add services, copy the scripts to the init. d Directory, and set startup


Cp support-files/mysql. server/etc/init. d/mysql
Chkconfig mysql on
Service mysql start -- start MySQL

Device User

After MySQL is started successfully, the root user has no password by default. we need to set the root password.

Before setting, we need to set the PATH first, or we cannot directly call mysql

Correct the/etc/profile file and add it at the end of the file


PATH =/usr/local/mysql/bin: ¥ PATH
Export PATH

Close the file and run the following command to make the device take effect immediately.


Source/etc/profile

Now, we can enter mysql directly in the terminal.

Perform the following order to correct the root code


Mysql-uroot
Mysql> set password = PASSWORD ("" 123456 "");

If you want to set up a root user, you can get a long-distance interview and perform


Mysql> grant all privileges on *. * TO "" root "" @ "172.16. %" "identified by" "password" "with grant option;

The red password indicates the password of the root user during long-distance interviews. it may not match the local password.

Device firewall

Port 3306 of the firewall is not enabled by default. to receive packets over long distances, you must enable this port.

Open/etc/sysconfig/Iptables

In "-a input? M state -- state NEW? M tcp? P? Dport 22? JACCEPT ", add below:


-A input m state -- state NEW m tcp p dport 3306 j ACCEPT

Save and close the file, run the following command in the terminal, and refresh the firewall device:


Service iptables restart


& #160;


OK. All devices are complete. you can meet your MySQL instance ~


We must work hard to learn from each other. There are three words: one name, and the other name. The other name must be vigorous and painstaking. -- Mao Zedong

Related Article

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.