Linux - NewbieThis 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!
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
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:
# 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.
# Set some defaults
if test -z "$basedir"
if test -z "$pid_file"
case "$pid_file" in
/* ) ;;
* ) pid_file="$datadir/$pid_file" ;;
mode=$1 # start or stop
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/^[^=]*=//'` ;;
# Get arguments from the my.cnf file, groups [mysqld] and [mysql_server]
if test -x ./bin/my_print_defaults
elif test -x $bindir/my_print_defaults
elif test -x $bindir/mysql_print_defaults
# Try to find basedir in /etc/my.cnf
if test -r $conf
dirs=`sed -e "/$subpat/!d" -e 's//\1/' $conf`
for d in $dirs
d=`echo $d | sed -e 's/[ ]//g'`
if test -x "$d/bin/my_print_defaults"
if test -x "$d/bin/mysql_print_defaults"
# Hope it's in the PATH ... but I doubt it
test -z "$print_defaults" && print_defaults="my_print_defaults"
parse_arguments `$print_defaults $defaults mysqld mysql_server`
# Safeguard (relative paths, core dumps..)
case "$mode" in
# Start daemon
if test -x $bindir/safe_mysqld
# 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
echo "Can't execute $bindir/safe_mysqld"
# Stop daemon. We use a signal here to avoid having to know the
# root password.
if test -f "$pid_file"
echo "Killing mysqld with pid $mysqld_pid"
# mysqld should remove the pid_file when it exits, so wait for it.
while [ -s $pid_file -a "$flags" != aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ]
[ -z "$flags" ] && echo "Wait for mysqld to exit\c" || echo ".\c"
if [ -s $pid_file ]
then echo " gave up waiting!"
elif [ -n "$flags" ]
then echo " done"
# delete lock for RedHat / SuSE
if test -f /var/lock/subsys/mysql
echo "No mysqld pid file found. Looked for $pid_file."
echo "usage: $0 start|stop"
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:
# This will start the MySQL server daemon at startup.
if [ -x /etc/init.d/mysql.server ]; then
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 :
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.
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.
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...