mysql源码安装启动脚本_mysql5.5 免编译安装及脚本启动报错深入

Mysql安装环境简介:

最近在做MHA。已经安装完毕heartbeat和drbd,现在准备安装Mysql。

Mysql安装目录:/opt/mysql

Mysql数据目录:/data/mysql

备注:/data目录实际是drbd需要同步到备节点的磁盘分区

Filesystem     Size  Used Avail Use% Mounted on

/dev/sda2      9.5G  2.0G  7.1G 22% /

tmpfs          932M     0  932M  0% /dev/shm

/dev/sda1      190M   58M  123M 32% /boot

/dev/drbd0       19G 832M   17G   5% /data

一、Mysql免编译安装(大家可以直接复制在命令行执行或保存至shell脚本)

#1、解压配置

yum install -y libaio-devel

cd /usr/local/src

[ ! -f mysql-5.5.49-linux2.6-x86_64.tar.gz] && \

wget http://mirrors.sohu.com/mysql/MySQL-5.5/mysql-5.5.49-linux2.6-x86_64.tar.gz

tar zxf mysql-5.5.49-linux2.6-x86_64.tar.gz

mkdir /opt/

mv mysql-5.5.49-linux2.6-x86_64/opt/mysql-5.5.49

ln -s /opt/mysql-5.5.49  /opt/mysql

#2、创建用户

if ! id mysql;then

useradd mysql -s /sbin/nologin -M

fi

#可以减写:! id mysql && useradd mysql -s /sbin/nologin -M ####

#还有一种脱裤子放屁的做法。

#groupadd mysql

#useradd -g mysql-M mysql

#用useradd mysql时就会创建mysql组,搞不懂为什么还先添加组

#3、初始化数据库,单实例启动

/opt/mysql/scripts/mysql_install_db --datadir=/data/mysql --basedir=/opt/mysql --user=mysql

cp /etc/my.cnf  /etc/my.cnf.ori

grep -Ev "#|^$" /opt/mysql/support-files/my-innodb-heavy-4G.cnf  > /etc/my.cnf

cp /opt/mysql/support-files/mysql.server /etc/init.d/mysqld

chkconfig mysqld on

#chmod +x /etc/init.d/mysqld (默认已有x权限)

#4、添加环境变量

echo "PATH=/opt/mysql/bin:$PATH" >> /etc/profile

. /etc/profile

#4、修改/etc/my.cnf或/etc/init.d/mysqld (暂时不修改,让脚本启动报错)

basedir=/opt/mysql

datadir=/data/mysql

***************************************************************************************

1、安装错误

[[email protected] src]#/opt/mysql/scripts/mysql_install_db --datadir=/data/mysql --basedir=/opt/mysql--user=mysql

Installing MySQL system tables...

/opt/mysql/bin/mysqld: errorwhile loading shared libraries: libaio.so.1: cannot open shared object file: Nosuch file or directory

解决:yum install -y libaio-devel

2、启动报错1:没指定basedir和datadir

[[email protected] src]#service mysqld start

/etc/init.d/mysqld: line 256: my_print_defaults: command notfound

/etc/init.d/mysqld: line 276: cd: /usr/local/mysql: No suchfile or directory

Starting MySQL ERROR!Couldn‘t find MySQL server (/usr/local/mysql/bin/mysqld_safe)

3、启动报错2

如果指定了basedir=/opt/mysql,但datadir=  为空时,启动会报错。

[[email protected] src]#service mysqld restart

ERROR! MySQL server PID file could not befound!

Starting MySQL.ERROR! The server quit without updating PID file (/opt/mysql/data/mysql1.pid).

[[email protected] src]#vi /etc/init.d/mysqld

4、启动报错3

也是basedir和datadir都没指定

[[email protected] src]#service mysqld restart

/etc/init.d/mysqld:line 256: my_print_defaults: command not found

/etc/init.d/mysqld:line 256: my_print_defaults: command not found

ERROR! MySQL server PID file could not befound!

/etc/init.d/mysqld:line 256: my_print_defaults: command not found

/etc/init.d/mysqld:line 276: cd: /usr/local/mysql: No such file or directory

Starting MySQLERROR! Couldn‘t find MySQL server (/usr/local/mysql/bin/mysqld_safe)

***********************************************************************************

前几天解决了生产环境的脚本报错的问题,现把报错原理分析总结下:

请看下面/etc/init.d/mysqld的启动脚本加粗部分解释。

# If you install MySQL on some other placesthan /usr/local/mysql, then you

# have to do one of the following things for thisscript to work:

#

# - Run thisscript from within the MySQL installation directory

# - Create a/etc/my.cnf file with the following information:

#  [mysqld]

#  basedir=

# - Add the aboveto any other configuration file (for example ~/.my.ini)

#   and copy my_print_defaults to /usr/bin

# - Add the pathto the mysql-installation-directory to the basedir variable

#   below.

#

# If you want toaffect other MySQL variables, you should make your changes

# in the/etc/my.cnf, ~/.my.cnf or other MySQL configuration files.

# If you changebase dir, you must also change datadir. These may get

# If you changebase dir, you must also change datadir. These may get

# overwritten bysettings in the MySQL configuration files.

basedir=

datadir=

# Default value,in seconds, afterwhich the script should timeout waiting

# for serverstart.

# Value here isoverriden by value in my.cnf.

# 0 means don‘twait at all

# Negative numbersmean to wait indefinitely

service_startup_timeout=900

# Lock directoryfor RedHat / SuSE.

lockdir=‘/var/lock/subsys‘

lock_file_path="$lockdir/mysql"

# The followingvariables are only set for letting mysql.server find things.

# Set somedefaults

mysqld_pid_file_path=

if test -z "$basedir"

then

basedir=/usr/local/mysql

bindir=/usr/local/mysql/bin

if test -z"$datadir"

then

datadir=/usr/local/mysql/data

fi

sbindir=/usr/local/mysql/bin

libexecdir=/usr/local/mysql/bin

else

bindir="$basedir/bin"

if test -z"$datadir"

else

bindir="$basedir/bin"

if test -z"$datadir"

then

datadir="$basedir/data"

fi

sbindir="$basedir/sbin"

libexecdir="$basedir/libexec"

fi

翻译:

1、如果basedir没有指定mysql安装路径,启动脚本就会以/usr/local/mysql做为安装路径启动。所以mysql没有安装在/usr/local下,启动必失败

2、如果basedir=/opt/mysql指定了mysql安装路径,并且mysql安装的路径是在/opt/mysql情况下。但datadir= 为空时,启动脚本会将$basedir/data(即/opt/mysql/data)做为mysql的数据目录。平时我们习惯将data目录放在/data/mysql下。此时启动会报错:

Starting MySQL. ERROR! The server quit without updatingPID file (/opt/mysql/data/mysql1.pid).

3、总结:用/etc/init.d/mysql启动时,最好在/etc/init.d/mysqld里设置basedir和datadir的值。或者在/etc/my.cnf 里[mysqld]下添加

[mysqld]

#port           = 3306

socket          = /tmp/mysql.sock

basedir=/opt/mysql

datadir=/data/mysql

不知道有没说明白。 建议大家再看看mysql启动脚本的文件。

心得:最近mysql遇到不少问题,庆幸大部分出错都能通过日志在百度上搜索出来。说明mysql使用的火热程度及大家的分享精神

本文出自 “Linux学习笔记” 博客,转载请与作者联系!

原文:http://genxin.blog.51cto.com/665191/1783419

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值