[Problem Solved] The mysql database startup time service starts and then stops. Some services will automatically stop when not in use by other services or programs

1. Problem description

In Computer Management-Services, find the corresponding mysql service and right-click to start it, the following situation occurs


Two, the solution process

Mysql version: 5.7

1. Back up mysql data files

Find the data directory under the directory where you installed mysql. My directory path is: C:\Program Files\MySQL\MySQL Server 5.7\data, and back up the database table name and idata1 file in it, as follows:

  • Such as blog, mybatis file: contains the table structure
  • ibdata1: innodb table space, which should store the data content of your database table

2. Delete service

This step is to delete the original service. First, use the following service to find the mysql service name you defined before:

Explanation : The above picture is just to demonstrate where to find it. My previous service name was mysql57, and I will operate according to this service name below! ! !

Enter the command (cmd started as an administrator) under the bin directory path of your mysql installation directory:mysqld --remove mysql57

Remove is followed by your service name! ! ! The following line of text appears to indicate that it has been successfully deleted.


3. Empty the data directory and initialize

Find the mysql installation directory and clear the data directory; if there is no data folder, create a data folder yourself

Or enter the command in cmd in the bin directory: mysqld --initialize-insecure --user=mysqlinitialize

A configuration error is reported below, but it does not affect, let's continue with the following steps.


4. Re-register the mysql service

Enter the command in the cmd of the bin path: mysqld --install mysql, the following prompt will appear indicating that the registration service is successful

Note : mysql after install is the service name I registered, you can also set another name.


5. Start the service

Or enter the command in the bin directory: net start mysql, mysql after start is the name of the service you just registered

At this point we have successfully started ! ! ! What I want to say here is that the password is empty at this time, and your original database and tables have been cleared, so you need to back up the database and tables before, see other instructions below.


other instructions

backup instructions

We will re-copy the previous backup file directory to the data directory. In addition to the following file directories, there is also an idata1 file , which is very important! ! !

Note : Copy the idata1 file to the data directory, and the data file will appear to be in use. We can enter in the cmd command: net stop mysql(mysql is the service name) or go to Computer Management-Service to close it manually, and then copy it again up.

password setting

After we cleared the data directory and re-registered the mysql service, the password was also reset to empty, so we first use the command to enter mysql: , mysql -u root -pas follows:

Use the following command to set the login password:set password for root@localhost = password('123456');

Where root is the user name, '' is the password you want to set, press Enter to modify successfully! ! !


reference article

[1] When the MySQL service is started, it is displayed that the MySQL service on the local computer starts and then stops. Certain services are in. . .

[2] After the mysql service on the local computer starts and stops, some services will automatically stop when they are not used by other services or programs


I am Changlu, thank you for reading, please point out if you have any questions, and correct them if there are mistakes.
Welcome to pay attention to my official account: Long Road Java, which will contain other materials such as software installation, including some video tutorials and learning path sharing.
You can also join the group: 891507813 We can discuss and study
together

Guess you like

Origin blog.csdn.net/cl939974883/article/details/112604223