Installation of MySQL automated O & M

Source: Internet
Author: User
Tags rpmbuild
MySQL is usually installed using RPM or source code. The advantage of RPM installation is fast and convenient. The disadvantage is that you cannot customize the installation directory. If you need to adjust the data file and Log File

MySQL is usually installed using RPM or source code. The advantage of RPM installation is fast and convenient. The disadvantage is that you cannot customize the installation directory. If you need to adjust the data file and Log File

MySQL is usually installed using RPM or source code.
RPM installation is fast and convenient. the disadvantage is that the installation directory cannot be customized. if you need to adjust the storage location of data files and log files, you also need to manually adjust the source code installation to customize the installation directory. The disadvantage is that the compilation time is long and the process is complex.

In fact, there is another way to customize the RPM package.
It is equivalent to using the source code to install a customized RPM package. One package can be used multiple times.
It can customize the path, automatically create an account during installation, automatically configure services, environment variables, and so on, and the installation process is fast and simple.
In large-scale deployment scenarios, the advantages are outstanding.
The disadvantage is that when creating an RPM package, you need to write the spec file defined by Red Hat. The learning curve of the spec file is steep.

The requirements are as follows:
1. Create a user mysql
2. database software installed in/home/mysql/mysql-5.6.14 directory
3. Store data files in the/data Directory
4. Configure the service and start it automatically

First, download rpmbuild
Yum install rpm-build-y
It is a tool used by Red Hat to pack RPM.
After the installation, restart the computer. The/root/rpmbuild directory contains the following folders:

The tool packaging process is roughly as follows,
Specify the spec packaging process.
Put the source code compressed package under the SOURCES directory,
Decompress the source code to the BUILD directory and execute the make command.
Put the result of make install in the BUILDROOT directory,
Finally, compile the compiled binary file under BUILDROOT into an RPM package.
In addition, you can specify the commands executed during the process, such as detaching and executing, before and after RPM installation.

First, download the source code package.

And copy it to the specified directory
/Root/rpmbuild/SOURCES/mysql-5.6.14.tar.gz

Install the dependent packages required for MySQL Compilation
Yum-y install make gcc-c ++ cmake bison-devel ncurses-devel

Write spec script
Vim mysql. spec

Name: MySQL
Version: 5.6.14
Release: 1% {? Dist}
Summary: MySQL-5.6.14 RPM

Group: applications/database
License: GPL
URL:
Source0: mysql-5.6.14.tar.gz
BuildRoot: % (mktemp-ud % {_ tmppath}/% {name}-% {version}-% {release}-XXXXXX)
BuildRequires: cmake

AutoReqProv: no
% Description
MySQL 5.6.14

% Define MYSQL_USER mysql
% Define MYSQL_GROUP mysql

% Prep
% Setup-n mysql-% {version}

% Build
Cmake \
-DCMAKE_INSTALL_PREFIX =/home/mysql/mysql-5.6.14 \
-DMYSQL_DATADIR =/data \
-DSYSCONFDIR =/etc \
-DWITH_MYISAM_STORAGE_ENGINE = 1 \
-DWITH_INNOBASE_STORAGE_ENGINE = 1 \
-DWITH_MEMORY_STORAGE_ENGINE = 1 \
-DWITH_READLINE = 1 \
-DMYSQL_UNIX_ADDR =/data/mysql. sock \
-DMYSQL_TCP_PORT = 3306 \
-DENABLED_LOCAL_INFILE = 1 \
-DWITH_PARTITION_STORAGE_ENGINE = 1 \
-DEXTRA_CHARSETS = all \
-DDEFAULT_CHARSET = utf8 \
-DDEFAULT_COLLATION = utf8_general_ci
Make-j 'cat/proc/cpuinfo | grep processor | wc-l'


% Install
Rm-rf % {buildroot}
Make install DESTDIR = % {buildroot}


% Pre
Mkdir-p/data
Useradd-m-s/bin/bash mysql
Chown-R mysql: mysql/data


% Post
/Home/mysql/mysql-5.6.14/scripts/mysql_install_db -- basedir =/home/mysql/mysql-5.6.14 -- datadir =/data -- user = mysql
Cp/home/mysql/mysql-5.6.14/support-files/mysql. server/etc/init. d/mysql
Chkconfig mysql on
Service mysql start
Echo "export PATH =.: $ PATH:/home/mysql/mysql-5.6.14/bin;">/home/mysql/. bashrc
Source/home/mysql/. bashrc

% Preun
Service mysql stop
Chkconfig -- del mysql
Userdel mysql
Rm-rf/home/mysql
Rm-rf/data
Rm-rf/etc/init. d/mysql

% Clean
Rm-rf % {buildroot}


% Files
% Defattr (-, % {MYSQL_USER}, % {MYSQL_GROUP })
% Attr (755, % {MYSQL_USER}, % {MYSQL_GROUP})/home/mysql/mysql-5.6.14 /*


% Changelog

Where
Source0: mysql-5.6.14.tar.gz
This compressed file needs to be placed in the specified directory (/root/rpmbuild/SOURCES)
During automatic decompression, the file will be found in the specified directory


AutoReqProv: no
This parameter must be set. Otherwise, the missing dependency package is displayed during installation.

% Setup-n mysql-% {version}
After extracting the source code package, you will go to the directory to execute build. By default, it is based on the directory that is spliced by % {name} and % {version.
Take MySQL as an example. The name written in spec is MySQL, and the version is 5.6.14.
Then it will go into the MySQL-5.6.14 directory,
But the directory after the source package is extracted is mysql-5.6.14 (lower case)
Therefore, use the-n parameter in the setup section to match the directory (that is, the default setting is not working and you need to match the directory yourself)

Make-j 'cat/proc/cpuinfo | grep processor | wc-l'
Check that the computer has several cores and then multi-thread Compilation

The script process is as follows:
First extract the source code package
% Prep
% Setup-n mysql-% {version}

Then execute the % build process and make the compilation.

Then execute % install
Install the compiled code once,
The directory it installs is/root/rpmbuild/BUILDROOT/MySQL-5.6.14-1.el6.i386/home/mysql/mysql-5.6.14/
Because the installation directory we specified is/home/mysql/mysql-5.6.14/, it is equivalent to installing it again in a sandbox.
It will pack the files installed in the sandbox into an RPM package.

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.