MySQL startup script under BSD/Linux

MySQL startup script under BSD/Linux

To create a startup script for MySQL on a BSD or Linux system, you can use the systemd or init.d initialization system, depending on your system.

Here are the steps to create a MySQL startup script using systemd:

  1. Create a new systemd service file. To create a new systemd service file for MySQL, you will need to create a new file in the /etc/systemd/system directory. The name of the file should be mysql.service.

  2. Edit the MySQL service file. Open the mysql.service file in a text editor and add the following content:

refer to:‮tual‬turi.com
[Unit]
Description=MySQL Server
After=network.target

[Service]
User=mysql
Group=mysql
ExecStart=/usr/local/mysql/bin/mysqld
ExecReload=/usr/local/mysql/bin/mysqladmin reload
ExecStop=/usr/local/mysql/bin/mysqladmin shutdown
PrivateTmp=true

[Install]
WantedBy=multi-user.target

Make sure to replace the ExecStart, ExecReload, and ExecStop paths with the paths to the MySQL daemon, mysqladmin utility, and the MySQL data directory on your system.

  1. Enable the MySQL service. To enable the MySQL service, you can use the systemctl command:
systemctl enable mysql

This will enable the MySQL service to start automatically at boot time.

  1. Start the MySQL service. To start the MySQL service, you can use the systemctl command:
systemctl start mysql

This will start the MySQL service.

To create a MySQL startup script using init.d, you will need to follow a similar process. First, create a new script in the /etc/init.d directory and add the necessary commands to start, stop, and restart the MySQL server. Then, use the update-rc.d command to enable the script to start automatically at boot time.

Regardless of which initialization system you use, you should be able to create a startup script for MySQL easily. The startup script will allow you to start, stop, and restart the MySQL server automatically as needed.

Created Time:2017-10-30 10:17:51  Author:lautturi