码迷,mamicode.com
首页 > 数据库 > 详细

mysql5.5 免编译安装及脚本启动报错深入

时间:2016-05-26 14:51:58      阅读:1088      评论:0      收藏:0      [点我收藏+]

标签:mysql启动报错 脚本分析

Mysql安装环境简介:

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

Mysql安装目录:/opt/mysql

Mysql数据目录:/data/mysql


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

[root@mysql1 src]# df -h

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、安装错误

[root@mysql1 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

[root@mysql1 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=  为空时,启动会报错。

[root@mysql1 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).

[root@mysql1 src]#vi /etc/init.d/mysqld

 

4、启动报错3

也是basedir和datadir都没指定

[root@mysql1 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=<path-to-mysql-installation-directory>

# - 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学习笔记” 博客,转载请与作者联系!

mysql5.5 免编译安装及脚本启动报错深入

标签:mysql启动报错 脚本分析

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!