On Centos5.8, use Shell scripts to install the mysql5.5.25 source code package with one click.

Source: Internet
Author: User
Recently, I have been studying mysql clusters and have to install and deploy at least two or more mysql databases. This is troublesome and time-consuming. Today I wrote a Shell script based on the Installation Steps, you only need to execute the following script to quickly install my

Recently, I have been studying mysql clusters and have to install and deploy at least two or more mysql databases. This is troublesome and time-consuming. Today I wrote a Shell script based on the Installation Steps, you only need to execute the following script to quickly install my

Recently, I have been studying mysql clusters. I have to install and deploy at least two or more mysql databases, which is troublesome and time-consuming. Today, I wrote a Shell script based on the Installation Steps, an American server, you only need to execute the following script to quickly install the mysql database. It is very convenient for beginners or those who want to learn the mysql cluster, that is, saving time and effort.

Description of the operating system and its mysql configuration file:
Linux: Centos5.8
Mysql: mysql-5.5.25tar.gz source package
Installation Directory:/usr/local/mysql/
Data Directory:/data/mysql/3306/data/
Binary log:/data/msyql/3306/binlog/
Relay log:/data/mysql/3306/relaylog/
Configuration File:/data/mysql/3306/my. cnf
Mysql. sock file:/data/mysql/3306/mysql. sock

The following is my one-click installation script for mysql database. If anything is wrong, please advise.
[Root @ DB148 sh] # cat mysql_install_new_version.sh
#! /Bin/bash
# Creation date: 2.6.2.6.16
# Author: Zhang Shifeng
# Mysql install directory and configuration files.
MYSQL_DIR = "/data/software"
DATA_DIR = "/data/mysql/3306/data"
BASE_DIR = "/usr/local/mysql"

Echo "please input mysql version :"
Read VERSION

Echo "Your mysql version is mysql-‑version.tar.gz"

If [-e "$ MYSQL_DIR/mysql-‑version.tar.gz"]
Then
Echo "Please waitting ..."
Sleep 3
# Install mysql package dependent.
Yum-y install gcc-c ++ gcc-g77 autoconf automake openssl zlib * fiex ** libxml *\
Ncurses-devel libmcrypt * libtool-ltdl-devel *&&
# Install cmake.
Echo "The system is be installed cmake, please waitting ..."
Sleep 3
Tar-zxvf $ MYSQL_DIR/cmake-2.8.8.tar.gz-C $ MYSQL_DIR &&
Cd $ MYSQL_DIR/cmake-2.8.8 &&
./Configure \
-- Prefix =/usr/local/cmake &&
Make & make install &&
# Creating mysql account and group.
/Usr/sbin/groupadd mysql &&
/Usr/sbin/useradd-s/sbin/nologin-g mysql-M mysql &&
# Install mysql.
Tar-zxvf $ MYSQL_DIR/mysql-‑version.tar.gz-C $ MYSQL_DIR
Cd $ MYSQL_DIR/mysql-$ VERSION
Echo "PATH = $ PATH:/usr/local/cmake/bin">/etc/profile & source/etc/profile
Cmake \
$ MYSQL_DIR/mysql-$ VERSION
-DCMAKE_INSTALL_PREFIX =/usr/local/mysql \
-DYSQL_TCP_PORT = 3306 \
-DMYSQL_DATADIR = $ DATA_DIR \
-DMYSQL_UNIX_ADDR =/data/mysql/3306/mysql. sock \
-DWITH_MYISAM_STORAGE_ENGINE = 1 \
-DWITH_INNOBASE_STORAGE_ENGINE = 1 \
-DDEFAULT_CHARSET = utf8 \
-DDEFAULT_COLLATION = utf8_general_ci \
-DEXTRA_CHARSETS = all \
-DWITH_DEBUG = 0
Make & make install &&

Mkdir-p $ DATA_DIR
Mkdir-p 'dirname $ DATA_DIR '/binlog
Mkdir-p 'dirname $ DATA_DIR '/relaylog
Cp $ MYSQL_DIR/mysql-$ VERSION/support-files/my-small.cnf.sh 'dirname $ DATA_DIR '/my. cnf
Cp $ MYSQL_DIR/mysql-$ VERSION/support-files/mysql. server. sh/etc/init. d/mysqld
Chmod + x/etc/init. d/mysqld
Sed-I's/^ basedir =/basedir = \/usr \/local \/mysql/'/etc/init. d/mysqld
Sed-I's/^ datadir =/datadir = \/data \/mysql \/3306/'/etc/init. d/mysqld
Sed-I's/'@ HOSTNAME @'/DB148/'/etc/init. d/mysqld
Sh/usr/local/mysql/scripts/mysql_install_db -- user = mysql -- basedir =/usr/local/mysql -- datadir = $ DATA_DIR &&
/Etc/init. d/mysqld start
Else
Echo "Your input mysql version is not in $ MYSQL_DIR"
Fi
Next we will test whether the script can be executed normally.

First, create the directory/data/software, and download the mysql-5.5.25.tar.gz and cmake source packages on the mysqlofficial website.

Next we will execute the mysql installation script, Hong Kong Space. here we need to manually enter the mysql version number 5.5.25, and then the script will be automatically installed to go out for ventilation, website space, and rest.

Finally, check whether the mysql database is installed. Check whether the mysql database startup files, ports, and data files are normal.

Summary: The above script has made a simple comment. The following describes the errors that may occur during the installation process.
1) echo "PATH = $ PATH: /usr/local/cmake/bin "> in the/etc/profile & source/etc/profile script, this line is used to modify environment variables, otherwise, when compiling and installing the mysql database, the system prompts that the cmake command cannot be found.
2) sed-I's/^ basedir =/basedir = \/usr \/local \/mysql/'/etc/init. d/mysqld and sed-I's/^ datadir =/datadir = \/data \/mysql \/3306/'/etc/init. d/mysqld scripts specify the installation directory and data directory of the mysql database in the mysql Startup File.
3) sed-I's/'@ HOSTNAME @'/DB148/'/etc/init. d/mysqld scripts replace '@ HOSTNAME @' with the mysql server host name. Otherwise, the following error is prompted when starting the database:/etc/init. d/mysqld: line 263: @ HOSTNAME @: command not found, but the database can be started normally.



This article is from the "simple dream Chaser" blog. Please keep this source

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.