Red hat Enterprise5再手工用rpm包装的mysql4.0,装完以后mysql不能通过service mysql start启动,只能通过/usr/share/mysql/mysql.server start启动,cp /usr/share/mysql/mysql.server /etc/init.d/mysql后可以用service mysql start,但是setup中添加自启动项无效,/etc/rc.local中加/usr/shar/mysql/mysql.server start或/usr/bin/mysqld_safe &均无效,手工可以启动mysql,程序就是自己启不来,很郁闷,怀疑是环境变量设置问题,哪位遇到过类似的问题........期待。

解决方案 »

  1.   

    日志:
     /var/lib/mysql/localhost.localdomain.err100525 14:51:07  mysqld started
    100525 14:51:07  mysqld ended调用了,但是直接就ended了!
      

  2.   

    # Example mysql config file for medium systems.
    #
    # This is for a system with little memory (32M - 64M) where MySQL plays
    # a important part and systems up to 128M very MySQL is used together with
    # other programs (like a web server)
    #
    # You can copy this file to
    # /etc/my.cnf to set global options,
    # mysql-data-dir/my.cnf to set server-specific options (in this
    # installation this directory is /usr/local/hsltest/var) or
    # ~/.my.cnf to set user-specific options.
    #
    # One can in this file use all long options that the program supports.
    # If you want to know which options a program support, run the program
    # with --help option.# The following options will be passed to all MySQL clients
    [client]
    #password = your_password
    port = 3306
    socket = /tmp/mysql.sock# Here follows entries for some specific programs# The MySQL server
    [mysqld]
    port = 3306
    socket = /tmp/mysql.sock
    skip-locking
    key_buffer = 16M
    max_allowed_packet = 1M
    table_cache = 64
    sort_buffer_size = 512K
    net_buffer_length = 8K
    myisam_sort_buffer_size = 8M# Don't listen on a TCP/IP port at all. This can be a security enhancement,
    # if all processes that need to connect to mysqld run on the same host.
    # All interaction with mysqld must be made via Unix sockets or named pipes.
    # Note that using this option without enabling named pipes on Windows
    # (via the "enable-named-pipe" option) will render mysqld useless!

    #skip-networking# Replication Master Server (default)
    # binary logging is required for replication
    log-bin# required unique id between 1 and 2^32 - 1
    # defaults to 1 if master-host is not set
    # but will not function as a master if omitted
    server-id = 2# Replication Slave (comment out master section to use this)
    #
    # To configure this host as a replication slave, you can choose between
    # two methods :
    #
    # 1) Use the CHANGE MASTER TO command (fully described in our manual) -
    #    the syntax is:
    #
    #    CHANGE MASTER TO MASTER_HOST=<host>, MASTER_PORT=<port>,
    #    MASTER_USER=<user>, MASTER_PASSWORD=<password> ;
    #
    #    where you replace <host>, <user>, <password> by quoted strings and
    #    <port> by the master's port number (3306 by default).
    #
    #    Example:
    #
    #    CHANGE MASTER TO MASTER_HOST='125.564.12.1', MASTER_PORT=3306,
    #    MASTER_USER='joe', MASTER_PASSWORD='secret';
    #
    # OR
    #
    # 2) Set the variables below. However, in case you choose this method, then
    #    start replication for the first time (even unsuccessfully, for example
    #    if you mistyped the password in master-password and the slave fails to
    #    connect), the slave will create a master.info file, and any later
    #    change in this file to the variables' values below will be ignored and
    #    overridden by the content of the master.info file, unless you shutdown
    #    the slave server, delete master.info and restart the slaver server.
    #    For that reason, you may want to leave the lines below untouched
    #    (commented) and instead use CHANGE MASTER TO (see above)
    #
    # required unique id between 2 and 2^32 - 1
    # (and different from the master)
    # defaults to 2 if master-host is set
    # but will not function as a slave if omitted
    #server-id       = 2
    #
    # The replication master for this slave - required
    #master-host     =   66.88.0.185
    #
    # The username the slave will use for authentication when connecting
    # to the master - required
    #master-user     =   root
    #
    # The password the slave will authenticate with when connecting to
    # the master - required
    #master-password =   ""
    #
    # The port the master is listening on.
    # optional - defaults to 3306
    #master-port     =  3306
    #replicate-do-db=bbb
    #master-connect-retry=1000
    #
    # binary logging - not required for slaves, but recommended
    #log-bin# Point the following paths to different dedicated disks
    #tmpdir = /tmp/
    #log-update  = /path-to-dedicated-directory/hostname# Uncomment the following if you are using BDB tables
    #bdb_cache_size = 4M
    #bdb_max_lock = 10000# Uncomment the following if you are using InnoDB tables
    #innodb_data_home_dir = /usr/local/hsltest/var/
    #innodb_data_file_path = ibdata1:10M:autoextend
    #innodb_log_group_home_dir = /usr/local/hsltest/var/
    #innodb_log_arch_dir = /usr/local/hsltest/var/
    # You can set .._buffer_pool_size up to 50 - 80 %
    # of RAM but beware of setting memory usage too high
    #innodb_buffer_pool_size = 16M
    #innodb_additional_mem_pool_size = 2M
    # Set .._log_file_size to 25 % of buffer pool size
    #innodb_log_file_size = 5M
    #innodb_log_buffer_size = 8M
    #innodb_flush_log_at_trx_commit = 1
    #innodb_lock_wait_timeout = 50[mysqldump]
    quick
    max_allowed_packet = 16M[mysql]
    no-auto-rehash
    # Remove the next comment character if you are not familiar with SQL
    #safe-updates[isamchk]
    key_buffer = 20M
    sort_buffer_size = 20M
    read_buffer = 2M
    write_buffer = 2M[myisamchk]
    key_buffer = 20M
    sort_buffer_size = 20M
    read_buffer = 2M
    write_buffer = 2M[mysqlhotcopy]
    interactive-timeout没有改东西!
      

  3.   

    看看/etc/init.d/mysql下的mysql启动脚本。分析一下,或者看看它是怎么执行启动的,跟你的命令行肯定不一样。
      

  4.   

    检查你的  mysql start 脚本。
      

  5.   

    mysql start 就是执行的/usr/bin/mysqld_safe脚本,看过脚本了,没看出问题,脚本如下,加了一些打印
    #!/bin/sh
    # Copyright Abandoned 1996 TCX DataKonsult AB & Monty Program KB & Detron HB
    # This file is public domain and comes with NO WARRANTY of any kind
    #
    # scripts to start the MySQL daemon and restart it if it dies unexpectedly
    #
    # This should be executed in the MySQL base directory if you are using a
    # binary installation that has other paths than you are using.
    #
    # mysql.server works by first doing a cd to the base directory and from there
    # executing mysqld_safeecho "1111111111111111111111111111111"KILL_MYSQLD=1;trap '' 1 2 3 15 # we shouldn't let anyone kill usumask 007defaults=
    case "$1" in
        --no-defaults|--defaults-file=*|--defaults-extra-file=*)
          defaults="$1"; shift
          ;;
    esacparse_arguments() {
      # We only need to pass arguments through to the server if we don't
      # handle them here.  So, we collect unrecognized options (passed on
      # the command line) into the args variable.
      pick_args=
      if test "$1" = PICK-ARGS-FROM-ARGV
      then
        pick_args=1
        shift
      fi  for arg do
        case "$arg" in
          --skip-kill-mysqld*)
            KILL_MYSQLD=0;
            ;;
          # these get passed explicitly to mysqld
          --basedir=*) MY_BASEDIR_VERSION=`echo "$arg" | sed -e "s;--basedir=;;"` ;;
          --datadir=*) DATADIR=`echo "$arg" | sed -e "s;--datadir=;;"` ;;
          --pid-file=*) pid_file=`echo "$arg" | sed -e "s;--pid-file=;;"` ;;
          --user=*)
            if test $SET_USER -eq 0
            then
              user=`echo "$arg" | sed -e "s;--[^=]*=;;"`
            fi
            SET_USER=1
            ;;      # these two might have been set in a [mysqld_safe] section of my.cnf
          # they are added to mysqld command line to override settings from my.cnf
          --socket=*)  mysql_unix_port=`echo "$arg" | sed -e "s;--socket=;;"` ;;
          --port=*)    mysql_tcp_port=`echo "$arg" | sed -e "s;--port=;;"` ;;      # mysqld_safe-specific options - must be set in my.cnf ([mysqld_safe])!
          --ledir=*)   ledir=`echo "$arg" | sed -e "s;--ledir=;;"` ;;
          # err-log should be removed in 5.0
          --err-log=*) err_log=`echo "$arg" | sed -e "s;--err-log=;;"` ;;
          --log-error=*) err_log=`echo "$arg" | sed -e "s;--log-error=;;"` ;;
          # QQ The --open-files should be removed in 5.0
          --open-files=*) open_files=`echo "$arg" | sed -e "s;--open-files=;;"` ;;
          --open-files-limit=*) open_files=`echo "$arg" | sed -e "s;--open-files-limit=;;"` ;;
          --core-file-size=*) core_file_size=`echo "$arg" | sed -e "s;--core-file-size=;;"` ;;
          --timezone=*) TZ=`echo "$arg" | sed -e "s;--timezone=;;"` ; export TZ; ;;
          --mysqld=*)   MYSQLD=`echo "$arg" | sed -e "s;--mysqld=;;"` ;;
          --mysqld-version=*)
    tmp=`echo "$arg" | sed -e "s;--mysqld-version=;;"`
    if test -n "$tmp"
    then
      MYSQLD="mysqld-$tmp"
    else
      MYSQLD="mysqld"
    fi
    ;;
          --nice=*) niceness=`echo "$arg" | sed -e "s;--nice=;;"` ;;
          *)
            if test -n "$pick_args"
            then
              # This sed command makes sure that any special chars are quoted,
              # so the arg gets passed exactly to the server.
              args="$args "`echo "$arg" | sed -e 's,\([^a-zA-Z0-9_.-]\),\\\\\1,g'`
            fi
            ;;
        esac
      done
    }
    MY_PWD=`pwd`
    # Check if we are starting this relative (for the binary release)
    if test -d $MY_PWD/data/mysql -a -f ./share/mysql/english/errmsg.sys -a \
     -x ./bin/mysqld
    then
      MY_BASEDIR_VERSION=$MY_PWD # Where bin, share and data are
      ledir=$MY_BASEDIR_VERSION/bin # Where mysqld is
      DATADIR=$MY_BASEDIR_VERSION/data
      if test -z "$defaults"
      then
        defaults="--defaults-extra-file=$MY_BASEDIR_VERSION/data/my.cnf"
      fi
    # Check if this is a 'moved install directory'
    elif test -f ./var/mysql/db.frm -a -f ./share/mysql/english/errmsg.sys -a \
     -x ./libexec/mysqld
    then
      MY_BASEDIR_VERSION=$MY_PWD # Where libexec, share and var are
      ledir=$MY_BASEDIR_VERSION/libexec # Where mysqld is
      DATADIR=$MY_BASEDIR_VERSION/var
    else
      MY_BASEDIR_VERSION=/
      DATADIR=/var/lib/mysql
      ledir=/usr/sbin
    fiuser=mysql
    niceness=0# Use the mysqld-max binary by default if the user doesn't specify a binary
    if test -x $ledir/mysqld-max
    then
      MYSQLD=mysqld-max
    else
      MYSQLD=mysqld
    fi
    # these rely on $DATADIR by default, so we'll set them later on
    #pid_file=
    pid_file="/var/lib/mysql/localhost.localdomain.pid"
    err_log=# Get first arguments from the my.cnf file, groups [mysqld] and [mysqld_safe]
    # and then merge with the command line arguments
    if test -x ./bin/my_print_defaults
    then
      print_defaults="./bin/my_print_defaults"
    elif test -x /usr/bin/my_print_defaults
    then
      print_defaults="/usr/bin/my_print_defaults"
    elif test -x /usr/bin/mysql_print_defaults
    then
      print_defaults="/usr/bin/mysql_print_defaults"
    else
      print_defaults="my_print_defaults"
    fiargs=
    SET_USER=2
    parse_arguments `$print_defaults --loose-verbose $defaults mysqld server`
    if test $SET_USER -eq 2
    then
      SET_USER=0
    fi
    parse_arguments `$print_defaults --loose-verbose $defaults mysqld_safe safe_mysqld`
    parse_arguments PICK-ARGS-FROM-ARGV "$@"
    safe_mysql_unix_port=${mysql_unix_port:-${MYSQL_UNIX_PORT:-/var/lib/mysql/mysql.sock}}echo "ffffffffffffffffffffff"
    if test ! -x $ledir/$MYSQLD
    then
      echo "The file $ledir/$MYSQLD doesn't exist or is not executable"
      echo "Please do a cd to the mysql installation directory and restart"
      echo "this script from there as follows:"
      echo "./bin/mysqld_safe".
      echo "See http://dev.mysql.com/doc/mysql/en/mysqld_safe.html for more"
      echo "information"
      exit 1
    fiif test -z "$pid_file"
    then
      pid_file=$DATADIR/`/bin/hostname`.pid
    else
      case "$pid_file" in
        /* ) ;;
        * )  pid_file="$DATADIR/$pid_file" ;;
      esac
    fi
    test -z "$err_log"  && err_log=$DATADIR/`/bin/hostname`.errif test -n "$mysql_unix_port"
    then
      args="--socket=$mysql_unix_port $args"
    fi
    if test -n "$mysql_tcp_port"
    then
      args="--port=$mysql_tcp_port $args"
    fiif test $niceness -eq 0
    then
      NOHUP_NICENESS="nohup"
    else
      NOHUP_NICENESS="nohup nice -$niceness"
    fi
      

  6.   


    # Using nice with no args to get the niceness level is GNU-specific.
    # This check could be extended for other operating systems (e.g.,
    # BSD could use "nohup sh -c 'ps -o nice -p $$' | tail -1").
    # But, it also seems that GNU nohup is the only one which messes
    # with the priority, so this is okay.
    if nohup nice > /dev/null 2>&1
    then
        normal_niceness=`nice`
        nohup_niceness=`nohup nice`    numeric_nice_values=1
        for val in $normal_niceness $nohup_niceness
        do
            case "$val" in
                -[0-9] | -[0-9][0-9] | -[0-9][0-9][0-9] | \
                 [0-9] |  [0-9][0-9] |  [0-9][0-9][0-9] )
                    ;;
                * )
                    numeric_nice_values=0 ;;
            esac
        done    if test $numeric_nice_values -eq 1
        then
            nice_value_diff=`expr $nohup_niceness - $normal_niceness`
            if test $? -eq 0 && test $nice_value_diff -gt 0 && \
                nice --$nice_value_diff echo testing > /dev/null 2>&1
            then
                # nohup increases the priority (bad), and we are permitted
                # to lower the priority with respect to the value the user
                # might have been given
                niceness=`expr $niceness - $nice_value_diff`
                NOHUP_NICENESS="nice -$niceness nohup"
            fi
        fi
    else
        if nohup echo testing > /dev/null 2>&1
        then
            :
        else
            # nohup doesn't work on this system
            NOHUP_NICENESS=""
        fi
    fiUSER_OPTION=""
    if test -w / -o "$USER" = "root"
    then
      if test "$user" != "root" -o $SET_USER = 1
      then
        USER_OPTION="--user=$user"
      fi
      # If we are root, change the err log to the right user.
      touch $err_log; chown $user $err_log
      if test -n "$open_files"
      then
        ulimit -n $open_files
        args="--open-files-limit=$open_files $args"
      fi
      if test -n "$core_file_size"
      then
        ulimit -c $core_file_size
      fi
    fi#
    # If there exists an old pid file, check if the daemon is already running
    # Note: The switches to 'ps' may depend on your operating systemecho "aaaa:$pid_file">>$err_logif test -f $pid_file
    then
      PID=`cat $pid_file`
      if /bin/kill -0 $PID > /dev/null 2> /dev/null
      then
        if /bin/ps p $PID | grep mysqld > /dev/null
        then    # The pid contains a mysqld process
          echo "A mysqld process already exists"
          echo "A mysqld process already exists at " `date` >> $err_log
          exit 1
        fi
      fiecho "#bbbbbbb:$pid_file">>$err_log  rm -f $pid_file
      if test -f $pid_file
      then
        echo "Fatal error: Can't remove the pid file: $pid_file"
        echo "Fatal error: Can't remove the pid file: $pid_file at " `date` >> $err_log
        echo "Please remove it manually and start $0 again">>$err_log
        echo "mysqld daemon not started">>$err_log
        exit 1
      fi
    fiecho "cccccccccc:$pid_file">>$err_log
    #
    # Uncomment the following lines if you want all tables to be automatically
    # checked and repaired during startup. You should add sensible key_buffer
    # and sort_buffer values to my.cnf to improve check performance or require
    # less disk space.
    # Alternatively, you can start mysqld with the "myisam-recover" option. See
    # the manual for details.
    #
    # echo "Checking tables in $DATADIR"
    # $MY_BASEDIR_VERSION/bin/myisamchk --silent --force --fast --medium-check $DATADIR/*/*.MYI
    # $MY_BASEDIR_VERSION/bin/isamchk --silent --force $DATADIR/*/*.ISMecho "Starting $MYSQLD daemon with databases from $DATADIR">>$err_log# Does this work on all systems?
    #if type ulimit | grep "shell builtin" > /dev/null
    #then
    #  ulimit -n 256 > /dev/null 2>&1 # Fix for BSD and FreeBSD systems
    #fi######################
    cmd="$NOHUP_NICENESS"
    for i in  "$ledir/$MYSQLD" "$defaults" "--basedir=$MY_BASEDIR_VERSION" \
      "--datadir=$DATADIR" "$USER_OPTION"
    do
      cmd="$cmd "`shell_quote_string "$i"`
    done
    cmd="$cmd $args"
     
    # Avoid 'nohup: ignoring input' warning
    test -n "$NOHUP_NICENESS" && cmd="$cmd < /dev/null"
     
    log_notice "Starting $MYSQLD daemon with databases from $DATADIR"
     
    #Ok£¬½øºóδú£¡
     
    echo "$cmd">>$err_log/
    #############################$ledir="/usr/bin"
    echo "`date +'%y%m%d %H:%M:%S  mysqld started-------------'`" >> $err_log
    while true
    do
      echo "##+++++++++++++++++##">>$err_log
      rm -f $safe_mysql_unix_port $pid_file # Some extra safety  echo "cccccccc:$cmd==========:$MYSQLD">>$err_log  if test -z "$args"
      then
        $NOHUP_NICENESS $ledir/$MYSQLD $defaults --basedir=$MY_BASEDIR_VERSION --datadir=$DATADIR $USER_OPTION --pid-file=$pid_file --skip-locking >> $err_log 2>&1
      else
        eval "$NOHUP_NICENESS $ledir/$MYSQLD $defaults --basedir=$MY_BASEDIR_VERSION --datadir=$DATADIR $USER_OPTION --pid-file=$pid_file --skip-locking $args >> $err_log 2>&1"
      fi
      
     
      echo "**************$NOHUP_NICENESS--led:$ledir/$MYSQOLD--default:$defaults---base:$MY_BASEDIR_VERSION---data:$DATADIR---us:$USER_OPTION">>$err_log
      if test ! -f $pid_file # This is removed if normal shutdown
      then
        break
      fi
      echo "-----+++++++++++++++">>$err_log  if test true -a $KILL_MYSQLD -eq 1
      then
        # Test if one process was hanging.
        # This is only a fix for Linux (running as base 3 mysqld processes)
        # but should work for the rest of the servers.
        # The only thing is ps x => redhat 5 gives warnings when using ps -x.
        # kill -9 is used or the process won't react on the kill.
        numofproces=`ps xa | grep -v "grep" | grep -c $ledir/$MYSQLD`
        echo -e "\nNumber of processes running now: $numofproces" | tee -a $err_log
        I=1
        while test "$I" -le "$numofproces"
        do 
          PROC=`ps xa | grep $ledir/$MYSQLD | grep -v "grep" | sed -n '$p'` 
    for T in $PROC
    do
      break
    done
    #    echo "TEST $I - $T **"
    if kill -9 $t
    then
      echo "$MYSQLD process hanging, pid $T - killed" | tee -a $err_log
    else 
      break
    fi
    I=`expr $I + 1`
        done
      fi
      echo "`date +'%y%m%d %H:%M:%S'`  mysqld restarted" | tee -a $err_log
    doneecho "`date +'%y%m%d %H:%M:%S'`  mysqld ended" | tee -a $err_log
    echo "" | tee -a $err_log
    都是默认配置,没有改动。
    现在发现as5中mysql的pid是/var/run/mysqld/mysqld.pid,而mysql4是/var/lib/myql/localhost.localdomain.pidpid文件是不是有区别?