Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Launch mySQL at system startup UNIX
The following tutorial explains how to get mySQL (via safe_mysqld) started at system boot. "It took some time, but it's working now."

Read the rest of this article if you'd like your mySQL server to launch when you start your machine.

[Editor's note: I haven't installed this yet myself, but I will, and I'll comment back if I have any problems]

Instructions

NOTE: The '%' is the prompt character; do not include it as part of the command!

You'll need to be doing all of this as root, so use your favorite method of becoming root...

First, create the startup directory and files:
% cd /Library/StartupItems
% mkdir SQL
% cd SQL
% touch SQL
% touch StartupParameters.plist
% pico SQL
and enter the following:
#!/bin/sh

. /etc/rc.common
##
# Start up SQL server
##
if [ "${SQLSERVER:=-NO-}" = "-YES-" ]; then
ConsoleMessage "Starting SQL Server"
/usr/local/mysql/share/mysql/mysql.server start
fi
Save the file and quit Pico. Now we'll edit the StartupParamters.plist:
% pico StartupParameters.plist
Enter the following text:
{
Description = "secure SQL server";
Provides = ("SQL");
Requires = ("Resolver");
OrderPreference = "None";
Messages =
{
start = "Starting SQL server";
stop = "Stopping SQL server";
};
}
Save the file and quit Pico. Now we'll set the correct permissions.
% chgrp wheel SQL
% chgrp wheel StartupParameters.plist
% chmod 755 SQL
The last step is to edit the host config file:
% pico /etc/hostconfig
and enter the following line:
SQLSERVER=-YES-
i've put it between WEBSERVER and APPLETALK_HOSTNAME. Save your changes, quit Pico, exit the terminal, and reboot. After reboot, view processviewer or top in terminal and you should see mysqld and sh (for safe_mysqld) running!

wow ... took me a day :). I used the SSH login thingies from stepwise as starting point

Gwyrrdin
    •    
  • Currently 4.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (1 vote cast)
 
[11,410 views]  

Launch mySQL at system startup | 11 comments | Create New Account
Click here to return to the 'Launch mySQL at system startup' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Nice one
Authored by: atl on Apr 12, '01 06:54:16AM
I had come to the same conclusion last night, except that I had nothing REQUIREd and had "Late" for my OrderPreference. Is it indeed the Resolver that MySQL requires? Also, since there are so many different MySQL instructions floating around, people trying this at home might want to verify the path to the mysql.server script. It's conceivable that you'll need to replace the path with:
/usr/local/share/mysql/mysql.server start
for example.

[ Reply to This | # ]
Nice one (thanks:)
Authored by: Gwyrrdin on Apr 12, '01 06:08:26PM
well....I'm not to sure about the .plist "requires" issue. But I do know it works fine on three different OS X boxes which I work on.

For the correct path to mysql.server start, you can perform a:

% locate mysql.server


presuming you have once already ran:

 %   ./usr/libexec/locate.updatedb 

(as root)


Important! do NOT use safe_mysqld in the SQL startup shell script. This will cause your OS X box to hang at boot time.
I had to boot in single user mode to disable the startup script before I could boot my OS X box again. So it's very very important that you call the mysql.server script and not the safe_mysqld script.

Cheers

Gwyrrdin


[ Reply to This | # ]
Nice one (welcome:)
Authored by: atl on Apr 13, '01 02:22:11PM
I noticed that safe_mysqld caused a hang, too. I *suspect* (though I haven't tried it), that following it with an ampersand (e.g. safe_mysqld &) would make things happier. You can also make things safer by not running the mysqld as root. One way to do it is:
sudo -u mysql /usr/local/share/mysql/mysql.server start
...but it seems like a nasty way to do it. There is reference in the docs to changing the user by using /etc/my.cnf, but my initial experiments haven't yielded anything there.

[ Reply to This | # ]
safe_mysqld &
Authored by: ascorbic on Apr 13, '01 05:58:22PM

Actually, you SHOULD use safe_mysqld, because it runs in the background, and will restart mysqld if it stops for any reason. Others have noted correctly that an & after a shell command will make it run in the background. This is how my script looks:

#!/bin/sh

. /etc/rc.common

##
# Start up mysql server
##

if [ "${SQLSERVER:=-NO-}" = "-YES-" ]; then
ConsoleMessage "Starting MySQL server"
/usr/local/mysql/bin/safe_mysqld &
fi



[ Reply to This | # ]
safe_mysqld &
Authored by: Gwyrrdin on Apr 14, '01 03:27:39AM

Hello

Read mysql.server with pico and you'll find out that this script actually launches safe_mysqld.

Only in such a way that system boots up without any problems...
So I would recommend to use mysql.server start

regards

Gwyrrdin



[ Reply to This | # ]
safe_mysqld &
Authored by: ascorbic on Apr 14, '01 06:44:14AM

i stand corrected!



[ Reply to This | # ]
also
Authored by: sawks on Apr 14, '01 01:28:32PM

with the mysql installer i used, mysql.server needed to be chmod 755'd - this may be the case for others as well...

thanks for the startup script :)



[ Reply to This | # ]
Unix is fun
Authored by: Gwyrrdin on Apr 13, '01 05:37:41PM
Hi Well I've tried safe_mysqld from the command line with & added...but that also doesn't bring back your prompt in the current tty. Another hint which I got from a friend was to pipe the output, more or less like this:
 /usr/local/mysql/bin/safe_mysqld > /Users/username/mysql.log
but this didn't work for me either... I'm also working to let mysqld running under an user/group mysql....I read some in the mySQL manual, but that didn't work for me....but thanks for the hint about my.conf And maybe I'll have to go to my local bookshop for some unix system administration:) Take care Gwyrrdin

[ Reply to This | # ]
Unix is fun
Authored by: ascorbic on Apr 13, '01 06:09:00PM

Hit 'enter' again. You should be in the shell, but the message from mysqld sortof hides the command prompt.



[ Reply to This | # ]
Complete Startup properties
Authored by: skab on May 22, '01 12:34:17AM

Great tip!

Actually it's really simple, no need to "touch" something ;-). Just copy one of the StartupItem folders from /System/Library/StartupItems to /Library/StartupItems and change the file names, property file and the actual start script. I chose the Apache folder, since it's just another server.

The "Requires" part is quite important, since the startup items are called depending on their requirements. AppleShare needs Network, so it will be loaded after the item that "provides" (the other tag, see below) "Network". I change the MySQL user in my /etc/my.cnf file (simply add "user=mysql" below [mysqld], look in the mysql dir for some sample config files), so I must make sure that NetInfo is loaded before the MySQL server, since NetInfo actually creates the users/groups (/etc/passwd is actually a dummy file). Choosing "Resolver" for "Requires" is not quite the right thing, but it does the trick, since NetInfo and Resolver are provided by the same startup item. I was lazy and put some requirements in there to be safe, but I guess "NetInfo" is all that's needed. Play around with it, I'm too tired now ;-)

If you're from a non-English speaking country like me, the files in the Resources folder (see the other items in /System/Library/StartupItems for reference) are interesting, since you can translate the message on the startup box into your language. Use PropertyListEditor to play around with it, it's foolproof, it worked immediately when I tried it.

Have fun!

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist SYSTEM "file://localhost/System/Library/DTDs/PropertyList.dtd">
<plist version="0.9">
<dict>
<key>Description</key>
<string>MySQL server</string>
<key>Messages</key>
<dict>
<key>start</key>
<string>Starting MySQL server</string>
<key>stop</key>
<string>Stopping MySQL server</string>
</dict>
<key>OrderPreference</key>
<string>None</string>
<key>Provides</key>
<array>
<string>SQL Server</string>
</array>
<key>Requires</key>
<array>
<string>Disks</string>
<string>NetInfo</string>
<string>NIS</string>
<string>Resolver</string>
</array>
</dict>
</plist>



[ Reply to This | # ]
Errors??
Authored by: iacas on Dec 19, '01 11:34:45AM

I get these errors or output from the terminal:

Starting MySQL Server
/usr/local/mysql/support-files/mysql.server: command not found: @HOSTNAME@ [36]
/usr/local/mysql/support-files/mysql.server: command not found: my_print_defaults [94]
usage: /usr/local/mysql/support-files/mysql.server start|stop

My files as per this article are in the proper place, created as root and so on. I'm not sure what's going on, but any help is appreciated.



[ Reply to This | # ]