[Solution] After uninstalling mysql, installing a different version causes mysqld to fail to start

Solve data conflicts between different versions of mysql

1. Background

It is also a coincidence to say that when I installed mysql5.7 version, I misread it and installed it as mysql8.0 version. Ever since, I thought that 8.0, um, is bigger than 5.7, so it must be more advanced! Actually, it's quite different.

In fact, I think it is a very normal thing to look away (trying to defend yourself), as shown in the picture:

image-20230710140459424

Ok, back to the topic. After installing 8.0, there is actually no difference in operating the database. But there is indeed a big difference in the phenomenon of configuration. For example, after I configured the password-free login of my.cnf, I could not see the process of the corresponding server. This is because the security protection of version 8.0 is better than that of version 5.7.

If you are using version 5.7, once your database is configured with a password-free login configuration, the following results are likely to appear:

image-20230717194230978

(Borrowing what a boss in the wechat address book personally experienced...)

So, why do I need to change to 5.7 after configuring 8.0? As a novice, it must be for the convenience of learning. Even if the above situation occurs, I have no important data to lose. So, I followed the normal method of uninstalling the unnecessary environment, and cleaned up the previous mysql (I thought it was uninstalled), and when I started, something unexpected happened to me...

MySQL environment configuration_

2. Problems that arise

When I reinstalled the mysql5.7 version and tried to start it (at this time, the sound came to my mind: Yuanshen, start!), and this happened:

image-20230717194807911

Oh, failed to start.... ***


At this point, GPT must be used.

image-20230717194934370

Look one by one:

  1. The first is the configuration problem. What can be wrong with the mysql I just installed? ? ? However, it is definitely not the reason.
  2. authority? How is it possible, pass.
  3. Port conflict. emm, after thinking about it for a while, it is indeed possible. As a result, I checked netstat -tuln | grep 3306, (mysqld defaults to 3306), and this is not the problem. Pass.
  4. Resource constraints? This is even more outrageous, impossible, absolutely impossible.
  5. Four are gone, let me see the log. Damn, how can I understand... Pass.

Well, the conclusion is that ChatGPT's answer makes me very unsatisfied.

So, I asked the real boss:

3. The cause of the problem

This happens because when mysql is uninstalled, although the configuration and everything are uninstalled together with mysql itself, the mysql directory in the /var/lib path still exists, and this directory has been uninstalled 8.0's data directory. At this time, if you installed the mysql5.7 version of the database like me, it will also generate a mysql directory at startup. At this time, the name of the mysql directory already exists, and the data format inside is naturally different due to different versions. It cannot be overwritten and cannot be replaced. So there was a situation where the initial startup failed.

image-20230717195932725

4. Solutions

In fact, you only need to change the name of the previous mysql directory to another name, or delete it, so that the newly generated mysql directory does not conflict with it, and you can solve it.

image-20230717200134244

Guess you like

Origin blog.csdn.net/NEFUT/article/details/131773929