0

We are currently using MySQL 5.7.20 on CentOS and are using zip installation. Since it is a zip installation we do not have service created in /etc/init.d/.

Is there any other method for auto-startup and auto-shutdown as we usually do with service.

We can startup using /etc/rc.local but what about if we want to do auto-shutdown or service status? any sample service script

Please suggest.

Thanks.

3

SHUTDOWN

MySQL 5.7 now features the SHUTDOWN command, which requiresthe SHUTDOWN privilege.

SHUTDOWN METHOD #1: Within mysql client

mysql> SHUTDOWN;

SHUTDOWN METHOD #2: From OS using mysql client

MYSQL_HOST=127.0.0.1
MYSQL_USER=root
MYSQL_PASS=rootpassword
MYSQL_CONN="-h${MYSQL_HOST} -u${MYSQL_USER} -p${MYSQL_PASS} -P3306 --protocol=tcp"
mysql ${MYSQL_CONN} -ANe"SHUTDONW"

SHUTDOWN METHOD #3: Using mysqladmin

This can be done with any MySQL 5.x version

MYSQL_HOST=127.0.0.1
MYSQL_USER=root
MYSQL_PASS=rootpassword
MYSQL_CONN="-h${MYSQL_HOST} -u${MYSQL_USER} -p${MYSQL_PASS} -P3306 --protocol=tcp"
mysqladmin ${MYSQL_CONN} shutdown

STATUS

You can use mysqladmin

For example, to see if mysqld is alive, run this:

MYSQL_HOST=127.0.0.1
MYSQL_USER=root
MYSQL_PASS=rootpassword
MYSQL_CONN="-h${MYSQL_HOST} -u${MYSQL_USER} -p${MYSQL_PASS} -P3306 --protocol=tcp"
mysqladmin ${MYSQL_CONN} ping 2>/dev/null | grep "mysqld is alive"

You can also do one of the following:

mysqladmin ${MYSQL_CONN} status
mysqladmin ${MYSQL_CONN} variables
mysqladmin ${MYSQL_CONN} uptime
mysqladmin ${MYSQL_CONN} processlist

AUTO START

Make sure you have chkconfig mysqld on or chkconfig mysql on enabled

There are no mysql utility programs to auto-startup except for mysqld_safe, which is launched by the mysqld (or mysql) service. This is usually issued by sudo service mysqld start (MySQL 5.7) or sudo service mysql start.

If you would like to attempt to write a custom mysqld_safe script, please see my old posts for ideas

  • Thank you so much and great answer as always, you are the king of MySQL.. – Nawaz Sohail Feb 9 '18 at 6:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.