Generally, you start the mysqld server in one of these ways:
Invoke mysqld directly. This works on any platform.
Run the MySQL server as a Windows service. The service can be set to start the server automatically when Windows starts, or as a manual service that you start on request. For instructions, see Section 2.3.11, “Starting MySQL as a Windows Service”.
Invoke mysqld_safe, which tries to determine the proper options for mysqld and then runs it with those options. This script is used on Unix and Unix-like systems. See Section 4.3.2, “mysqld_safe — MySQL Server Startup Script”.
Invoke mysql.server. This script is
used primarily at system startup and shutdown on systems
that use System V-style run directories, where it usually
is installed under the name mysql
. The
mysql.server script starts the server
by invoking mysqld_safe. See
Section 4.3.3, “mysql.server — MySQL Server Startup Script”.
On Mac OS X, install a separate MySQL Startup Item package to enable the automatic startup of MySQL on system startup. The Startup Item starts the server by invoking mysql.server. See Section 2.5, “Installing MySQL on Mac OS X”, for details.
The mysqld_safe and mysql.server scripts and the Mac OS X Startup Item can be used to start the server manually, or automatically at system startup time. mysql.server and the Startup Item also can be used to stop the server.
To start or stop the server manually using the
mysql.server script, invoke it with
start
or stop
arguments:
shell>mysql.server start
shell>mysql.server stop
Before mysql.server starts the server, it
changes location to the MySQL installation directory, and then
invokes mysqld_safe. If you want the server
to run as some specific user, add an appropriate
user
option to the
[mysqld]
group of the
/etc/my.cnf
option file, as shown later
in this section. (It is possible that you will need to edit
mysql.server if you've installed a binary
distribution of MySQL in a nonstandard location. Modify it to
change location into the proper directory before it runs
mysqld_safe. If you do this, your modified
version of mysql.server may be overwritten
if you upgrade MySQL in the future, so you should make a copy
of your edited version that you can reinstall.)
mysql.server stop stops the server by sending a signal to it. You can also stop the server manually by executing mysqladmin shutdown.
To start and stop MySQL automatically on your server, you need
to add start and stop commands to the appropriate places in
your /etc/rc*
files.
If you use the Linux server RPM package
(MySQL-server-
),
the mysql.server script is installed in the
VERSION
.rpm/etc/init.d
directory with the name
mysql
. You need not install it manually.
See Section 2.4, “Installing MySQL from RPM Packages on Linux”, for more information on the
Linux RPM packages.
Some vendors provide RPM packages that install a startup script under a different name such as mysqld.
If you install MySQL from a source distribution or using a
binary distribution format that does not install
mysql.server automatically, you can install
it manually. The script can be found in the
support-files
directory under the MySQL
installation directory or in a MySQL source tree.
To install mysql.server manually, copy it
to the /etc/init.d
directory with the
name mysql, and then make it executable. Do
this by changing location into the appropriate directory where
mysql.server is located and executing these
commands:
shell>cp mysql.server /etc/init.d/mysql
shell>chmod +x /etc/init.d/mysql
Older Red Hat systems use the
/etc/rc.d/init.d
directory rather than
/etc/init.d
. Adjust the preceding
commands accordingly. Alternatively, first create
/etc/init.d
as a symbolic link that
points to /etc/rc.d/init.d
:
shell>cd /etc
shell>ln -s rc.d/init.d .
After installing the script, the commands needed to activate
it to run at system startup depend on your operating system.
On Linux, you can use chkconfig
:
shell> chkconfig --add mysql
On some Linux systems, the following command also seems to be necessary to fully enable the mysql script:
shell> chkconfig --level 345 mysql on
On FreeBSD, startup scripts generally should go in
/usr/local/etc/rc.d/
. The
rc(8)
manual page states that scripts in
this directory are executed only if their basename matches the
*.sh
shell file name pattern. Any other
files or directories present within the directory are silently
ignored. In other words, on FreeBSD, you should install the
mysql.server
script as
/usr/local/etc/rc.d/mysql.server.sh
to
enable automatic startup.
As an alternative to the preceding setup, some operating
systems also use /etc/rc.local
or
/etc/init.d/boot.local
to start
additional services on startup. To start up MySQL using this
method, you could append a command like the one following to
the appropriate startup file:
/bin/sh -c 'cd /usr/local/mysql; ./bin/mysqld_safe --user=mysql &'
For other systems, consult your operating system documentation to see how to install startup scripts.
You can add options for mysql.server in a
global /etc/my.cnf
file. A typical
/etc/my.cnf
file might look like this:
[mysqld] datadir=/usr/local/mysql/var socket=/var/tmp/mysql.sock port=3306 user=mysql [mysql.server] basedir=/usr/local/mysql
The mysql.server script supports the
following options: basedir
,
datadir
, and pid-file
. If
specified, they must be placed in an
option file, not on the command line.
mysql.server supports only
start
and stop
as
command-line arguments.
The following table shows which option groups the server and each startup script read from option files.
Script | Option Groups |
mysqld |
[mysqld] , [server] ,
[mysqld-
|
mysqld_safe |
[mysqld] , [server] ,
[mysqld_safe]
|
mysql.server |
[mysqld] , [mysql.server] ,
[server]
|
[mysqld-
means that groups with names like
major_version
][mysqld-5.1]
and
[mysqld-5.4]
are read by
servers having versions 5.1.x,
5.4.x, and so forth. This feature can be used to
specify options that can be read only by servers within a
given release series.
For backward compatibility, mysql.server
also reads the [mysql_server]
group and
mysqld_safe also reads the
[safe_mysqld]
group. However, you should
update your option files to use the
[mysql.server]
and
[mysqld_safe]
groups instead when using
MySQL 5.4.
User Comments
Remember that on FreeBSD or any *nix system that supports running scripts from /usr/local/etc/rc.d
you should do for security purposes:
#chmod 100 *
Running Mandrake Linux 9.1/MySQL 4.x: Following the instructions for auto-start didn't work. Drove me crazy until I created the startup symbolic link in the rc5.d instead of rc3.d.
If you need to boot without graphics or just level 3, then put the symbolic link to mysql.server in rc3.d
Slackware 8 MySQL 4 autostart instructions:
I installed MySQL 4.0.18 on Slackware v8. The "auto-start" instructions don't seem to apply to Slackware. I ended up adding this to my /etc/rc.d/rc.M:
# Start MySQL server:
if [ -x /etc/rc.d/rc.mysql ]; then
. /etc/rc.d/rc.mysql start
fi
then I added this to /etc/rc.d/rc.K above the #Kill all processes line:
# Shut down the MySQL database server
if [ -x /etc/rc.d/rc.mysql ]; then
. /etc/rc.d/rc.mysql stop
fi
Then I created the /etc/rc.d/rc.mysql script:
#!/bin/sh
#
# Start the MySQL database server
#
case "$1" in
'start')
/usr/local/mysql/support-files/mysql.server start ;;
'stop')
/usr/local/mysql/support-files/mysql.server stop ;;
'restart')
/usr/local/mysql/support-files/mysql.server restart ;;
*)
echo "usage $0 start|stop|restart" ;;
esac
That got me going and seems to work fine. If there's a real pro out there who knows a nicer/more correct way please let me know at cuculi54986@yahoo.com -- Jon Reed
Do not rely on READ LOCK.
Mysql 4.0.15, linux.
I have a connection holding a READ LOCK, and another connection trying to insert lots of records per second.
The READ LOCK stalls the inserting connection very well, but if I then stop the mysql process, a few inserts still make it after all!
I think this happens because the mysql server is multi-threaded : the thread that belongs to the connection holding the READ LOCK is stopped earlier than the thread that is trying to do the database updates. Sometimes 0 updates make it through the closing door, sometimes a couple of hundred, so it is just a matter of (bad) luck.
I run a linux 2.6 server with only MySQL running (P4 3.2Ghz / 2GB) and sometimes (mainly when the server has run for a little time ,when it has reached an uptime of...30 minutes to few days), it becomes impossible to stop it with the right signal, or with mysqladmin (mysqladmin shutdown, or mysql.server stop). Mysql.server says it gaves up waiting and mysqladmin freeze too. nothing helpful in the error log, and finally i have to send a KILL signal to stop it. I've got this problem with all mysql 4 & 4.1 versions...
So to avoid a reboot failure (if the mysql.server script doesn't stop mysqld), it's better to add a kill command (which send SIGKILL to mysqld) in the mysql.server script after the waiting loop.
On Slackware 10, just copy mysql.server to /etc/rc.d and rename it to rc.mysqld
cp /usr/local/mysql/support-files/mysql.server /etc/rc.d/rc.mysqld
On FreeBSD 5.x according to the mysql-server.sh file installed automatically with the ports collection for 4.1.16, you have to add the line in your rc.conf to have automatic startup for mysqld:
mysql_enable="YES"
Don't know if this helps but I had to make the connect during post port installation to get mine to always come up without manual intervention.
En FreeBsd para arrancar mysql después de instalarlo
editar el archivo /etc/rc.conf y agregar las siguiente linea mysql_enable="YES"
y después en la consola terminal ejecutas el siguiente comando /usr/local/etc/rc.d/mysql-server.sh start,
si lo haces todo en este orden no tendrás problemas para iniciar el servidor.
Si no agregas la linea en el rc.conf y ejecutas el siguiente comando /usr/local/etc/rc.d/mysql-server.sh start
te marcara el siguiente error Connect to server at 'localhost' failed error: 'Can't connect to local MySQL server through socket '/temp/mysql.sock' exists!
Saludos
Add your own comment.