Introduction to Mat Wright

Mat Wright is a Zend Certified Engineer and qualified designer available for freelance web development + consultation work.

Tuesday, May 10, 2011

How to start mysql server

A common question I get asked by clients running a local  LAMP server such as XAMMP for Linux or Zend Server is "how to start the MySQL server ?".

Over the last couple of years I've worked on a number of desktop/network PHP applications including Intranets, Database Administration Software and even a PHP driven barcode scanning application for a bricks and mortar commercial business. Such applications are usually hosted within the businesses office buildings and for one reason or another clients switch off and reboot their system from time to time and I nearly always get a call saying everything is up and running except MySQL.

Depending on the operating system and distribution it is possible to configure MySQL to automatically start-up after a reboot, for example on Fedora based distributions chkconfig can be used,  however by default it has to be done manually, so here's how to do it:

Starting MySQL server on Linux:
1. Open up a shell prompt and login as root.

$ su
Password :

2a. Use the following command on Fedora/Centos servers.

# /etc/init.d/mysqld start

2b. Use the following command on Debian/Ubuntu servers.
# /etc/init.d/mysql start

And that's all there is to it!

There are various other ways of doing this if your system supports the service command (Redhat Linux):
# service mysqld start

How do I stop/restart MySql ?

Using the same method as above you can stop/restart your MySQL server like thus:

Use the following commands on Fedora/Centos servers.
# /etc/init.d/mysqld restart
# /etc/init.d/mysqld stop

Use the following commands on Debian/Ubuntu servers.
# /etc/init.d/mysql restart
# /etc/init.d/mysql stop

If you need to reboot regularly for some reason you should consider using chkservice as mentioned previously.

1 comment:

  1. I thought that it would be hard to do this, but was completely wrong, just few codes and your work is done completely in few minutes.