• Home
  • DBA Scripts
    • Oracle Scripts
    • SQL Server Scripts
  • Knowledge Base
    • Oracle Database
    • MS SQL Server
    • MongoDB
    • MariaDB
  • Troubleshoot
    • Oracle Database Issues
    • SQL Server Issues
  • Interview Questions
    • AWS Interview Questions
    • Oracle DBA Interview Questions
    • SQL Server Interview Questions
  • Courses
    • Oracle Database
    • Oracle DBA L1
    • Oracle DBA L2
    • Oracle DBA L3
  • Home
  • DBA Scripts
    • Oracle Scripts
    • SQL Server Scripts
  • Knowledge Base
    • Oracle Database
    • MS SQL Server
    • MongoDB
    • MariaDB
  • Troubleshoot
    • Oracle Database Issues
    • SQL Server Issues
  • Interview Questions
    • AWS Interview Questions
    • Oracle DBA Interview Questions
    • SQL Server Interview Questions
  • Courses
    • Oracle Database
    • Oracle DBA L1
    • Oracle DBA L2
    • Oracle DBA L3
home/Knowledge Base/MySQL/Start and Stop MySQL using the systemctl
Popular Search:Oracle, SQL Server, MongoDB

Start and Stop MySQL using the systemctl

98 views 0 March 10, 2024 sandeep

How to start and stop mysql using the systemctl command.

**All the below steps are performed as the ROOT user

=> Below are the setting in the my.cnf file of this demo environment.

cat /etc/my.cnf

[mysqld]
basedir=/u01/mysql/base
datadir=/u01/mysql/data
log_error=/u01/mysql/logs/error.log
port=3306
socket=/u01/mysql/data/mysql.sock

1. Go to the MySQL base directory location and add basedir path and datadir path to the file mysql.server inside support-files directory.

cd /u01/mysql/base/support-files
vi mysql.server

basedir=/u01/mysql/base
datadir=/u01/mysql/data

2. Execute the file to check the status.

root@Server:/u01/mysql/base/support-files# ./mysql.server status
* MySQL running (7046)
root@Server:/u01/mysql/base/support-files# ./mysql.server stop
Shutting down MySQL
root@Server:/u01/mysql/base/support-files# ./mysql.server start
Starting MySQL
.Logging to '/u01/mysql/data/Server.err'.
...... *
root@Server:/u01/mysql/base/support-files# ./mysql.server stop
Shutting down MySQL

3. Copy mysql.server file to /etc/init.d directory and rename to mysql

root@Server:/u01/mysql/base/support-files# cp -r mysql.server /etc/init.d/
root@Server:/u01/mysql/base/support-files# cd /etc/init.d/
root@Server:/etc/init.d# mv mysql.server mysql

4. Check the status and start the mysql services.

root@Server:~# /etc/init.d/mysql status
○ mysql.service - LSB: start and stop MySQL
Loaded: loaded (/etc/init.d/mysql; generated)
Active: inactive (dead)
Docs: man:systemd-sysv-generator(8)
root@Server:~#
root@Server:~# /etc/init.d/mysql start
Starting mysql (via systemctl): mysql.service.
root@Server:~#
root@Server:~# /etc/init.d/mysql status
● mysql.service - LSB: start and stop MySQL
Loaded: loaded (/etc/init.d/mysql; generated)
Active: active (exited) since Fri 2024-03-08 15:29:07 NZDT; 3s ago
Docs: man:systemd-sysv-generator(8)
Process: 7426 ExecStart=/etc/init.d/mysql start (code=exited, status=0/SUCCESS)
CPU: 904ms

Mar 08 15:29:07 Server systemd[1]: Starting LSB: start and stop MySQL...
Mar 08 15:29:07 Server mysql[7426]: Starting MySQL
Mar 08 15:29:07 Server mysql[7426]: *
Mar 08 15:29:07 Server systemd[1]: Started LSB: start and stop MySQL.
Mar 08 15:29:07 Server mysql[7434]: 2024-03-08T02:29:07.885088Z mysqld_safe A mysqld process already exists
root@Server:~#

5. Stop and start the MySQL services using the systemctl command

root@Server:~# systemctl start mysql
root@Server:~#
root@Server:~# systemctl status mysql
● mysql.service - LSB: start and stop MySQL
Loaded: loaded (/etc/init.d/mysql; generated)
Active: active (running) since Sun 2024-03-10 16:25:45 NZDT; 6s ago
Docs: man:systemd-sysv-generator(8)
Process: 60214 ExecStart=/etc/init.d/mysql start (code=exited, status=0/SUCCESS)
Tasks: 40 (limit: 6967)
Memory: 461.3M
CPU: 13.370s
CGroup: /system.slice/mysql.service
├─60228 /bin/sh /u01/mysql/base/bin/mysqld_safe --datadir=/u01/mysql/data --pid-file=/u01/mysql/data/MySQLServer.pid
└─60408 /u01/mysql/base/bin/mysqld --basedir=/u01/mysql/base --datadir=/u01/mysql/data --plugin-dir=/u01/mysql/base/lib/plugin --user=mysql --lo>

Mar 10 16:25:34 MySQLServer systemd[1]: Starting LSB: start and stop MySQL...
Mar 10 16:25:34 MySQLServer mysql[60214]: Starting MySQL
Mar 10 16:25:45 MySQLServer mysql[60214]: .......... *
Mar 10 16:25:45 MySQLServer systemd[1]: Started LSB: start and stop MySQL.
lines 1-16/16 (END)
root@Server:~#
Tags:MySQL

Was this helpful?

Yes  No
Related Articles
  • Configure Master Slave Replication in MySQL
  • Purge Old Logs in MySQL
  • Type of Logs in MySQL
  • Install and Remove Plugin into MySQL
  • MySQL user Management
  • Install MySQL in Linux / Ubuntu
Leave A Comment Cancel reply

MySQL
  • Start and Stop MySQL using the systemctl
  • Configure Master Slave Replication in MySQL
  • Purge Old Logs in MySQL
  • Type of Logs in MySQL
  • Install and Remove Plugin into MySQL
  • MySQL user Management
View All 6  
Popular Articles
  • Upgrade Oracle Database from 11.2.0.3 to 12.1.0.2
  • Upgrading MariaDB on Windows
  • Oracle DBA Basic Interview Questions Part A
  • Purging Oracle Sysaux Tablespace
  • Client – Server Architecture
KB Categories
  • Oracle Database
    • Oracle RAC
    • Oracle ASM
    • Oracle GoldenGate
    • Oracle Tuning
    • Oracle 11g Database
    • Oracle Database Upgrade
    • Oracle 12c Database
    • ALL KB Oracle
    • Oracle 18c Database
    • Oracle Standby Database
  • MongoDB
  • MS SQL Server
  • MySQL
  • Interview Questions
    • AWS Interview Questions
    • Oracle DBA Interview Questions
    • SQL Server Interview Questions
  • MariaDB
Database Organization

Database Organization (DB ORG) is knowledge base for DBA to learn and execute the fundamental of different databases under one website. DB ORG is a non-profit initiative. ORACLE, MS SQL Server, MongoDB, MariaDB, Couchbase

Join Our Community
  • KnowledgeBase
  • Documentation
  • Troubleshoot
  • FAQ
Information Links
  • About DBOrg
  • Licenses
  • Terms
  • Privacy Policy
Contact Us
    DB ORG - Database Administration,
    Knowledge Base for DBA
    Mail: support@databaseorg.com
    WhatsApp: (+91) 9306440957
    Monday to Friday: EST - 11:30 AM to 06:30 PM (IST - 9:00 PM to 4:00 AM)
  • © 2023 Database Organization - DB ORG. All Rights Reserved.

Popular Search:Oracle, SQL Server, MongoDB

WhatsApp DB Org