LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-03-2003, 07:15 AM   #1
dark poet
LQ Newbie
 
Registered: Sep 2003
Location: Santo Domingo, Dominican Republic
Distribution: Debian Sarge...
Posts: 14

Rep: Reputation: 0
mysqld on startup...


i want to put mysqld on startup(/etc/init.d), but the question is: how do i add something or some daemon to start automatically at startup...?
 
Old 10-03-2003, 08:55 AM   #2
daveo
Member
 
Registered: Sep 2003
Location: Holland
Distribution: Gentoo 1.4, Slackware
Posts: 196

Rep: Reputation: 30
What distribution are you working with ? I saw something like: andros(debian based)

Do you have a rc.local file in your /etc/init.d/ map ?
 
Old 10-03-2003, 11:40 AM   #3
trickykid
LQ Guru
 
Registered: Jan 2001
Posts: 24,149

Rep: Reputation: 267Reputation: 267Reputation: 267
Usually by default you will have a file called mysql.server in your /usr/share/mysql directory you can use to start and stop the mysql server at startup.

The contents of this file is follows:
Code:
# The following variables are only set for letting mysql.server find things.
# If you want to affect other MySQL variables, you should make your changes
# in the /etc/my.cnf or other configuration files.

PATH=/sbin:/usr/sbin:/bin:/usr/bin
export PATH

# Set some defaults
datadir=/var/lib/mysql
basedir=
pid_file=
if test -z "$basedir"
then
  basedir=/usr
  bindir=/usr/bin
else
  bindir="$basedir/bin"
fi
if test -z "$pid_file"
then
  pid_file=$datadir/`/bin/hostname`.pid
else
  case "$pid_file" in
    /* ) ;;
    * )  pid_file="$datadir/$pid_file" ;;
  esac
fi

mode=$1    # start or stop

parse_arguments() {
  for arg do
    case "$arg" in
      --basedir=*)  basedir=`echo "$arg" | sed -e 's/^[^=]*=//'` ;;
      --datadir=*)  datadir=`echo "$arg" | sed -e 's/^[^=]*=//'` ;;
      --pid-file=*) pid_file=`echo "$arg" | sed -e 's/^[^=]*=//'` ;;
    esac
  done
}

# Get arguments from the my.cnf file, groups [mysqld] and [mysql_server]
if test -x ./bin/my_print_defaults
then
  print_defaults="./bin/my_print_defaults"
elif test -x $bindir/my_print_defaults
then
  print_defaults="$bindir/my_print_defaults"
elif test -x $bindir/mysql_print_defaults
then
  print_defaults="$bindir/mysql_print_defaults"
else
  # Try to find basedir in /etc/my.cnf
  conf=/etc/my.cnf
  print_defaults=
  if test -r $conf
  then
    subpat='^[^=]*basedir[^=]*=\(.*\)$'
    dirs=`sed -e "/$subpat/!d" -e 's//\1/' $conf`
    for d in $dirs
    do
      d=`echo $d | sed -e 's/[  ]//g'`
      if test -x "$d/bin/my_print_defaults"
      then
        print_defaults="$d/bin/my_print_defaults"
        break
      fi
      if test -x "$d/bin/mysql_print_defaults"
      then
        print_defaults="$d/bin/mysql_print_defaults"

        print_defaults="$d/bin/mysql_print_defaults"
        break
      fi
    done
  fi

  # Hope it's in the PATH ... but I doubt it
  test -z "$print_defaults" && print_defaults="my_print_defaults"
fi

parse_arguments `$print_defaults $defaults mysqld mysql_server`

# Safeguard (relative paths, core dumps..)
cd $basedir

case "$mode" in
  'start')
    # Start daemon

    if test -x $bindir/safe_mysqld
    then
      # Give extra arguments to mysqld with the my.cnf file. This script may
      # be overwritten at next upgrade.
      $bindir/safe_mysqld --datadir=$datadir --pid-file=$pid_file &
      # Make lock for RedHat / SuSE
      if test -w /var/lock/subsys
      then
        touch /var/lock/subsys/mysql
      fi
    else
      echo "Can't execute $bindir/safe_mysqld"
    fi
    ;;

  'stop')
    # Stop daemon. We use a signal here to avoid having to know the    
    # root password.
    if test -f "$pid_file"
    then
      mysqld_pid=`cat $pid_file`
      echo "Killing mysqld with pid $mysqld_pid"
      kill $mysqld_pid
      # mysqld should remove the pid_file when it exits, so wait for it.

      sleep 1
      while [ -s $pid_file -a "$flags" != aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ]
      do
        [ -z "$flags" ] && echo "Wait for mysqld to exit\c" || echo ".\c"
        flags=a$flags
        sleep 1
      done
      if [ -s $pid_file ]
         then echo " gave up waiting!"
      elif [ -n "$flags" ]
         then echo " done"
      fi
      # delete lock for RedHat / SuSE
      if test -f /var/lock/subsys/mysql
      then
        rm /var/lock/subsys/mysql
      fi
    else
      echo "No mysqld pid file found. Looked for $pid_file."
    fi
    ;;

  *)
    # usage
    echo "usage: $0 start|stop"
    exit 1
    ;;
esac
Place that file in your /etc/init.d directory where you have all your other scripts. Then you can edit the script that you use to startup with, like your specific runlevel script and add this to it:

Code:
# This will start the MySQL server daemon at startup.
#
if [ -x /etc/init.d/mysql.server ]; then
  . /etc/init.d/mysql.server
fi
Hope that helps any.

Last edited by trickykid; 10-03-2003 at 11:41 AM.
 
Old 10-03-2003, 05:11 PM   #4
mrPhantastik
LQ Newbie
 
Registered: Aug 2003
Posts: 17

Rep: Reputation: 0
Whoa, let's keep it simple here
most distros of redhat have a setup prog u can use to select which things to run at startup.

simply at any command prompt as ROOT use :
command# setup

or if in the gui use the services found in the system settings..

plus it helps if mysql is installed
 
Old 10-03-2003, 05:35 PM   #5
trickykid
LQ Guru
 
Registered: Jan 2001
Posts: 24,149

Rep: Reputation: 267Reputation: 267Reputation: 267
Quote:
Originally posted by mrPhantastik
Whoa, let's keep it simple here
most distros of redhat have a setup prog u can use to select which things to run at startup.

simply at any command prompt as ROOT use :
command# setup

or if in the gui use the services found in the system settings..

plus it helps if mysql is installed
Simple eh? Redhat doesn't usually have this service enabled to my knowledge in "setup"!

The way I described is how mysql tells you how to do this. This is their script from mysql. Its not really that hard, but I do believe mine is the most proper and correct way, at least by mysql's standards.

Looks daunting, but really in the end really easy and simple enough.
 
Old 10-04-2003, 05:33 AM   #6
daveo
Member
 
Registered: Sep 2003
Location: Holland
Distribution: Gentoo 1.4, Slackware
Posts: 196

Rep: Reputation: 30
Correct me if i'm wrong here, but can't we just do it by:

chkconfig --add mysqld

under redhat ?
 
Old 10-04-2003, 10:55 AM   #7
trickykid
LQ Guru
 
Registered: Jan 2001
Posts: 24,149

Rep: Reputation: 267Reputation: 267Reputation: 267
Quote:
Originally posted by daveo
Correct me if i'm wrong here, but can't we just do it by:

chkconfig --add mysqld

under redhat ?
Yah, probably but did all you that suggest doing it the Redhat way notice the person asking isn't using Redhat? That's why I told him non-distro specific way and the way that mysql tells you to perform this.

Regards.
 
Old 10-04-2003, 11:21 PM   #8
dark poet
LQ Newbie
 
Registered: Sep 2003
Location: Santo Domingo, Dominican Republic
Distribution: Debian Sarge...
Posts: 14

Original Poster
Rep: Reputation: 0
yeah, i`m not using red hat...as trickykid said, i asked for a non-distro espeficic way...

i wanted to know if i can do it like this:

i put the script to start in the run-level i want to...in this case rc5..

# cd /etc/rc5.d
# ln -s /etc/init.d/mysql S20mysql

and that`s all, right?

i put to boot automatically when i run in level 5, and the name S20mysql(S is for start, and K is for kill, that`s why i put S)(the 20 is the position in which it loads itself at startup, something like that...) i need to read more about it...

ok, comments please???
 
Old 10-05-2003, 12:16 AM   #9
trickykid
LQ Guru
 
Registered: Jan 2001
Posts: 24,149

Rep: Reputation: 267Reputation: 267Reputation: 267
I see no problems with doing it that way.... go for it.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
how can i start mysqld? yenonn Slackware 6 11-28-2003 09:32 PM
mysqld ended.. xdrainox Slackware 9 10-02-2003 04:26 PM
mysqld fails on startup wiseraptor Linux - Newbie 0 02-07-2003 03:42 PM
Startup & MySQL (mysqld) raypen Slackware 1 08-28-2002 04:15 PM
Mysqld cinnix Linux - General 4 07-08-2001 01:42 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:10 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration