Compile and install MySQL based on Cmake in CentOS

Source: Internet
Author: User
Tags localhost mysql

Compile and install MySQL based on Cmake in CentOS

1.1 experiment environment

Operating System: CentOS6.7

Virtual Machine: VMware Workstation

Database System: mysql-5.6.15.tar.gz

1.2 tutorial background

Starting from MySQL, the compilation tool for MySQL source code installation starts from configure to cmake. The installation method is slightly different from that before MySQL. Here is a brief summary.

Code compilation and installation are the most error-prone and time-consuming. Sky recommends that you try to install it in multiple ways after learning one method.

Before installation, it is best to check for some basic software, such as make, GCC, Perl, libncurses5-dev, cmake-2.8.5, ncurses-devel, if not installed, use yum-y install gcc-c ++ make cmake bison ncurses-devel to install the complete command. Otherwise, an error is reported during compilation and installation.

1.3 install Cmake

# Go To The Source Code directory

[Root @ localhost src] # cd/usr/local/src

# Download the Installation File

[Root @ localhost src] # wgethttp: // wwwNaNake.org/files/v2.8/cmake-2.8.5.tar.gz

# Decompress

[Root @ localhost src] # tar zxvfcmake-2.8.5.tar.gz

# Installation

[Root @ localhost src] # cd cmake-2.8.5

[Root @ localhost src] #./bootstrap

[Root @ localhost src] # gmake

[Root @ localhost src] # gmake install

# Return the source code directory

Cd ../

1.4cmake Introduction

CMake is short for "cross platform make. It is a cross-platform installation (Compilation) tool. You can use simple statements to describe the installation (compilation process) of all platforms ). He can output a variety of makefiles or project files and test the C ++ features supported by the compiler, similar to automake in UNIX.

Compared with the configure syntax

The installation options are compared as follows:

1.5 install bison-2.5

# Download the Installation File

[Root @ localhost src] # wgethttp: // ftp.gnu.org/gnu/bison/bison-2.5.tar.gz

# Decompress

[Root @ localhost src] # tar zxvfbison-2.5.tar.gz

# Installation

[Root @ localhost src] # cd bson-2.5

[Root @ localhost src] #./configure

[Root @ localhost src] # make

[Root @ localhost src] # make install

# Return the source code directory

Cd ../

1.6Mysql Installation

# Create mysql users and groups

[Root @ localhost src] #/usr/sbin/groupaddmysql

[Root @ localhost src] #/usr/sbin/useradd-g mysql

[Root @ localhost src] # mkdir/usr/local/mysql # create a database directory

[Root @ localhost src] # mkdir/usr/local/mysql/data # create a database folder

# Put the source code in the directory/usr/local

# Decompress the package to the installation directory

[Root @ localhost src] # tar xvf mysql-5.5.27.tar.gz

[Root @ localhost src] # cd mysql-5.5.27

# Compile

[Root @ localhost mysql] # cmake \

-DCMAKE_INSTALL_PREFIX =/usr/local/mysql \
-DMYSQL_UNIX_ADDR =/usr/local/mysql/data/mysql. sock \
-DDEFAULT_CHARSET = utf8 \
-DDEFAULT_COLLATION = utf8_general_ci \
-DWITH_EXTRA_CHARSETS: STRING = utf8 \
-DWITH_MYISAM_STORAGE_ENGINE = 1 \
-DWITH_INNOBASE_STORAGE_ENGINE = 1 \
-DWITH_READLINE = 1 \
-DENABLED_LOCAL_INFILE = 1 \
-DMYSQL_DATADIR =/usr/local/mysql/data \

-DMYSQL_USER = mysql

# Installation

[Root @ localhost mysql] # make & makeinstall

1.7 link file 1.7.1 after installation

Ln-s/usr/local/mysql/lib/libmysqlclient. so.18/usr/lib64/

# If you do not execute this step, the following error may occur during running:

Errorwhileloadingsharedlibraries: libmysqlclient. so.18: cannotopen#dobjectfile: Nosuchfileordirectory

1.7.2 set the path environment variable

Vi/etc/profile

# Add at the end of profile

Export PATH = "/usr/local/mysql/bin: $ PATH"

# Save

Source/etc/profile

1.7.3 configuration parameter file

Cd support-files

Cp my-large.cnf/etc/my. cnf

# Edit my. cnf, add the following content, or modify the following on the original path:

Basedir =/usr/local/mysql

Datadir =/usr/local/mysql/data

Log-error =/usr/local/mysql/data/mysql_error.log

Pid-file =/usr/local/mysql/data/mysql. pid

Socket =/usr/local/mysql/data/mysql. socket // If yes, change the directory to the data directory of mysql, where/usr/local/mysql/data

1.7.4 Set permissions

[Root @ localhost mysql] # cd/usr/local/mysql

[Root @ localhost mysql] # chown-R mysql. # Add a space after mysql and modify the permission.

[Root @ localhost mysql] # chgrp-R mysql. # Add a space after mysql and modify the permission.

1.7.5mysql initial installation

Cd/usr/local/mysql/

[Root @ localhost mysql] # scripts/mysql_install_db \
-- Defaults-file =/etc/my. cnf \
-- Basedir =/usr/local/mysql \
-- User = mysql \

-- Force

If an error occurs like: 'Warning: The host' *** 'could not be looked up with resolveip'

Add the-force option during execution.

1.7.6 Modify permissions

# Change the ownership of the installation directory to root, and change the ownership of the data directory to your runningMysqld user

Cd/usr/local/mysql

[Root @ localhost mysql] # chown-R root. # add space after root.

[Root @ localhost mysql] # chown-R mysqldata

1.8 Configuration Service

# Configuration Service

Cd/usr/local/mysql/support-files

[Root @ localhost support-files] # cpmysql. server/etc/init. d/mysqld

[Root @ localhost support-files] # chmod + x/etc/init. d/mysqld

[Root @ localhost support-files] # chkconfig -- add mysqld # boot automatically

[Root @ localhost support-files] # chkconfig -- level 345 mysqld on

1.9 Start and Stop mysql

[Root @ localhost ~] # Service mysqldstart

Starting MySQL SUCCESS!

[Root @ localhost ~] # Service mysqld stop

Shutting down MySQL... SUCCESS!

1.10 set the Mysql user account password

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.

1) modify the root password

Run the command:/usr/local/mysql/bin/mysqladmin-u root-p old password new password or use root to log on to the database

# Mysql-u root

Run after Logon

Mysql> set password for 'root' @ 'hostname' = password ('new password ');

Or execute

Mysql> update mysql. user setpassword = password ('new password ')

-> Where user = 'root' and host = 'hostname ';

If you do not know the hostname, run select host, user from mysql. user where user = 'root' first'

2) Delete Anonymous Users

Run

Mysql> delete from mysql. user where user = ''; delete records with empty user names

Mysql> delete from mysql. user where password = ''; delete records with empty passwords

3) after modifying the user permissions, execute

Mysql> flush privileges;

Because after MySQL is started, all user permissions are loaded to the memory, but some permission update operations are not refreshed to the memory, so that they will only take effect the next time they are started. If you directly update mysql. user to change the password; flush privileges forces MySQL to reload the permission, so that the modification will take effect immediately.

Summary: IT technologies are updated quickly. If you want to be an O & M expert, there are too many things to learn. For example, the above example is only an upgraded version. For O & M technicians, it will take several hours to study.
Attachment download: http://sky9896.blog.51cto.com/2330653/1682948

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.