Avviare e arrestare MariaDB automaticamente
Se si esegue MariaDB in un ambiente server, è quasi sempre desiderabile che si avvii quando la macchina viene accesa, in modo che MariaDB funzioni quando funziona il server, e si arresti correttamente quando questo viene spento.
Il binario del server MariaDB si chiama mysqld
. Come gli altri binari di MariaDB, è chiamato così per preservare la compatibilità con il più diffuso MySQL.
Esiste la possibilità di avviare mysqld
in vari modi:
- Eseguire o invocare
mysqld
direttamente. Un esempio è meglio descritto in Eseguire MariaDB dalla directory dei sorgenti. - Eseguire lo script di avvio
mysqld_safe
. - Eseguire lo script di avvio
mysql.server
.
Lo script mysql.server
avvia mysqld
dopo aver selezionato la directory di installazione di MariaDB, e chiama mysqld_safe
. Aggiungendo una riga appropriata user
al gruppo [mysqld]
nel file my.cnf file si fa in modo che il server venga eseguito da quell'utente.
Se si ha installato MariaDB in un percorso non standard, potrebbe essere necessario modificare lo script mysql.server
perché funzioni correttamente.
mysql.server
lavora come init script standard in stile SysV. Pertanto è possibile utilizzarlo con gli argomenti start
e stop
in questo modo:
mysql.server start mysql.server stop
To configure MariaDB to start and stop automatically on Linux using the
mysql.server
script you need to add it to your
distribution's init system, usually by copying it to
/etc/init.d/
and then creating specially named symlinks
in the appropriate /etc/rcX.d/
directories (where 'X' is a
number between 0 and 6).
In the examples below we will follow the historical convention of renaming the
mysql.server
script to 'mysql
' when we
copy it to /etc/init.d/
.
The first step for most Linux distributions is to copy the
mysql.server
script to /etc/init.d/
and
make it executable:
cd /path/to/your/mariadb-version/support-files/
cp mysql.server /etc/init.d/mysql
chmod +x /etc/init.d/mysql
Now all that is needed is to create the specially-named symlinks. On both RPM and Debian-based Linux distributions there are tools which do this for you. Consult your distribution's documentation if neither of these work for you and follow their instructions for generating the symlinks or creating them manually.
On RPM-based distributions (like Fedora and CentOS), you use
chkconfig
:
chkconfig --add mysql
chkconfig --level 345 mysql on
On Debian-based distributions you use update-rc.d
:
update-rc.d mysql defaults
On FreeBSD, the location for startup scripts is
/usr/local/etc/rc.d/
and when you copy the
mysql.server
script there you should rename it so that it
matches the *.sh
pattern, like so:
cd /path/to/your/mariadb/support-files/
cp mysql.server /usr/local/etc/rc.d/mysql.server.sh
As stated above, consult your distribution's documentation for more information on starting services like MariaDB at system startup.
See mysqld startup options for information on
configuration options for mysqld
.