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!
Notices
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.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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
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.
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...
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.