Home >Database >Mysql Tutorial >mysql start stop

mysql start stop

王林
王林Original
2023-05-12 11:53:062251browse

MySQL is a commonly used open source relational database system. It provides flexibility and customizable features, and is easy to install and manage. Whether you are using MySQL on a personal computer or in a production environment, once you encounter MySQL not running properly or problems occur, you need to start or shut down it. Let's take a look at how to start or shut down MySQL.

Start MySQL

MySQL can be started through the command line or graphically. This article introduces starting MySQL through the command line.

1. Check whether MySQL has been installed

Before starting MySQL, you need to check whether MySQL has been installed and confirm its installation path. If you installed MySQL on a Windows operating system, you can press the Windows R key to open the "Run" dialog box, enter the services.msc command, and click the "OK" button. Check in the "Services" list to see if the MySQL service is installed.

If you installed MySQL on a Linux operating system, you need to use the following command to check whether MySQL has been installed:

$ mysql -v

If it is not installed, you need to install MySQL first. For the installation method, please refer to Official documentation.

2. Start the MySQL service

There are two ways to start the MySQL service:

  • In the Windows operating system, use net Command, as shown below:

    net start mysql
  • In Linux operating system, use the following command:

    sudo /etc/init.d/mysql start

or

sudo service mysql start

If your MySQL configuration file path is different, you need to specify the corresponding configuration file path:

mysql.server start --defaults-file=/path/to/my.cnf

After successfully starting the MySQL service, you can use the following command to verify whether it is running normally:

mysql -u root -p

If If the message prompts "Welcome to the MySQL monitor", it means that the MySQL service has been started successfully.

Close MySQL

When you do not need to use MySQL, you can shut down the service to release system resources. There are two ways to shut down MySQL:

1. Use the mysqladmin tool

MySQL comes with a mysqladmin tool that can be used to manage the MySQL service. Use the following command to shut down the MySQL service:

mysqladmin -uroot shutdown

Use the command online:

mysqladmin -h hostname -uroot -p shutdown

If the MySQL service has stopped, the following message will be prompted:

mysqladmin: connect to server at 'localhost' failed
error: 'Can't connect to local MySQL server through socket 
'/tmp/mysql.sock' (2)'
Check that mysqld is running and that the socket: '/tmp/mysql.sock' exists!

In this case, the MySQL service has stopped stop.

2. Use system commands

In the Windows operating system, you can use the net command to stop the MySQL service, as shown below:

net stop MySQL

In In the Linux operating system, you can use the following command to stop the MySQL service:

sudo /etc/init.d/mysql stop

or

sudo service mysql stop

If your MySQL configuration file path is different, you need to specify the corresponding configuration file path:

mysql.server stop --defaults-file=/path/to/my.cnf

Summary

Through the introduction of this article, we learned how to start or shut down the MySQL service. There are many ways to start and shut down MySQL. You can choose the method that suits you according to the actual situation. At the same time, you also need to pay attention to whether the MySQL configuration file path is correct to ensure that the MySQL service can be started or shut down normally.

The above is the detailed content of mysql start stop. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn