Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am very weak on unix shell scripting. Is there a way to create Unix shell script which will start on server boot time only, and will execute the following commands in order:

# cd /mysql
# ./bin/safe_mysqld --user=root &
# ./support-files/mysql.server start

The longer story... On a HP-UX server I've installed Mysql. However the client wanted the server to be installed in /mysql instead in /usr/local/mysql/ which is the standard location. During the last week I've been struggling to set the mysql daemon to start automatically on server boot time.

I don't know what is the problem, but so far the only way to start the server is by using the above commands.

UPDATE: 07.02.12 15:23

This is a short output from the server boot when it starts the processes:

Start MySQL Server .................................................. OK

However after i enter ps -ef I can easily tell that it is not started:

# ps -ef | grep -i mysql
    root  3074  3056  0 15:26:53 pts/0     0:00 grep -i mysql

And this is how it should look like when i start the process:

# cd mysql
# ./bin/safe_mysqld --user=root &
[1]     3123
# Starting mysqld daemon with databases from /mysql/data
# ./support-files/mysql.server start
Starting MySQL
# ps -ef | grep -i mysql
    root  3139  3123  0 15:27:19 pts/0     0:00 /mysql/bin/mysqld --basedir=/mysql --datadir=/mysql/data --u
    root  3123  3056  0 15:27:19 pts/0     0:00 /bin/sh ./bin/safe_mysqld --user=root
    root  3171  3056  0 15:27:59 pts/0     0:00 grep -i mysql

Now I think that it is more clear why I want to create a shell startup script and actually FORCE the starting of the process with those commands.

share|improve this question

The binary needs to know the location of the my.cnf file at startup (a default will be compiled in). You didn't say what path prefix you used when building mysql. In turn the my.cnf file defines the locations of the data files.

It would be a good idea to use a proper SysV init script to manage the server. In addition to solving the problem of startnig the server at boot, you'll also get a clean shutdown when the system is halted, you can configure sensible behaviour for different runlevels and stop/start the mysql server alone in a managed way. And if you set it up correctly it will play nicely with SAM.

There's an example here (note that the location of my.cnf is passed as an argument to safe_mysqld). This should be in /sbin/init.d with appropriate (symbolic) links in /sbin/rcX.d (where X is the relevant runlevel). The process is described here.

share|improve this answer
Thanks for the explanation.. I'll review the articles you have provided and post an update :) – Spirit Feb 7 '12 at 13:08
I also have to note that on while booting the server is giving a positive message when starting the mysql server: Start MySQL Server .................................................. OK however when i try to locate the mysql process using ps -ef the process is NOT there.. – Spirit Feb 7 '12 at 13:26
Which process? mysqld? mysql.server? mysqld_safe? (not sure what mysql.server actually is, but it looks as if you're trying to start it up twice). I presume you;d already checked to see if it was running listening on the filesystem / network socket? If so, then check your logs. – symcbean Feb 7 '12 at 17:13
What you just said now it is possible.. maybe I should check with other similar servers that are already in production and see if there are any differences with the mysql process – Spirit Feb 7 '12 at 22:08

I think the cleanest thing, if this is an option for you, is to recompile MySQL.

In the source directory (extract from tarball):

./configure --prefix=/mysql
make && sudo make install
share|improve this answer
I don't thing that's an option.. There are already critical DB files in /mysql/data/. Every other configuration on the server is complete so I just have to set Mysql to start on server boot time and that's it. – Spirit Feb 7 '12 at 13:52

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.