To manage a MySQL server, you can use the command-line client or a graphical user interface. Here, we’ll provide instructions for using the command-line client, which is commonly available on most systems as well as the graphical user interface on WIndows and macOS. Make sure you have the necessary permissions to perform these actions, as some commands may require root or administrator privileges such as sudo.
Starting MySQL Server:
To start the MySQL server, you need to execute the appropriate command based on your operating system.
On Linux (Ubuntu/Debian):
$sudo service mysql start
# or
$sudo systemctl start mysql
On Linux (CentOS/RHEL):
$sudo systemctl start mysqld
On Windows:
Open a Command Prompt or PowerShell with administrator privileges, then execute:
net start mysql
Alternatively open the Services App by typing “Services” on the Windows search bar. In the Services App, scroll down to the MySQL service on the list. Using your mouse, right-click on the item to access the context menu with the appropriate commands.
On macOS:
Open macOS system preferences and select the MySQL preference panel, and then execute “Start MySQL Server” on the appropriate instance.
Alternatively using the command-line interface:
$sudo mysql.server start
Stopping MySQL Server:
On Linux (Ubuntu/Debian):
$sudo service mysql stop
# or
$sudo systemctl stop mysql
On Linux (CentOS/RHEL):
$sudo systemctl start mysqld
On Windows:
Open a Command Prompt or PowerShell with administrator privileges, then execute:
net start mysql
Alternatively open the Services App by typing “Services” on the Windows search bar. In the Services App, scroll down to the MySQL service on the list. Using your mouse, right-click on the item to access the context menu with the appropriate commands.
On macOS:
Open macOS system preferences and select the MySQL preference panel, and then execute “Stop MySQL Server” on the appropriate instance.
Alternatively using the command-line interface:
$sudo mysql.server stop
Restarting MySQL Server:
On Linux (Ubuntu/Debian):
$sudo service mysql restart
# or
$sudo systemctl restart mysql
On Linux (CentOS/RHEL):
$sudo systemctl restart mysqld
On Windows:
Open a Command Prompt or PowerShell with administrator privileges, then execute:
net stop mysql
net start mysql
Alternatively open the Services App by typing “Services” on the Windows search bar. In the Services App, scroll down to the MySQL service on the list. Using your mouse, right-click on the item to access the context menu with the appropriate commands.
On macOS:
Open macOS system preferences and select the MySQL preference panel, and then execute “Restart MySQL Server” on the appropriate instance.
Alternatively using the command-line interface:
$sudo mysql.server restart
Checking MySQL Server Status:
On Linux (Ubuntu/Debian):
$sudo service mysql status
# or
$sudo systemctl status mysql
On Linux (CentOS/RHEL):
$sudo systemctl status mysqld
On Windows:
Open a Command Prompt or PowerShell with administrator privileges, then execute:
sc query mysql
Alternatively open the Services App by typing “Services” on the Windows search bar. In the Services App, scroll down to the MySQL service on the list and visually check the status.
On macOS:
Open macOS system preferences and select the MySQL preference panel, and then you can visually check the status of the appropriate instance.
Alternatively using the command-line interface:
$sudo mysql.server status
Alternatively for all systems you can use the MySQL command-line client to check the server status by opening a terminal or command prompt and running the the MySQL client:
$mysql -u your_username -p
Replace your_username with your MySQL username. Enter your MySQL password when prompted. Once logged in, you can check the server status by typing the command below to display the server’s uptime in seconds:
mysql> SHOW STATUS LIKE 'Uptime';
Found this article interesting? Follow Brightwhiz on Facebook, Twitter, and YouTube to read and watch more content we post.