Windows 10 uninstall and reinstall MySQL8 (retain data)

Windows 10 uninstall and reinstall MySQL8 (retain data)


Background: When using github to download the project, I did not pay attention to the name of the database as mysql, which caused the data in the project to exist in the mysql database, destroying the original mysql table structure, causing the database to fail to start, and 10061 errors always occurred, and the mysql server could not be connected .
Solution: Log in to mysql through mysql password-free login, dump the sql file, save the data, and then reinstall mysql.

Dump database data

1. Enter the bin directory of the mysql installation folder:
insert image description here
2. Enter

>mysqld --console --skip-grant-tables

insert image description here
3. Reopen a cmdwindow 4. Go back to the directory
in step 1 5. Enterbin

>mysql -uroot -p

6. No need to enter a password, just press Enter to log in. mysql
7. Open the Navicat tool, create a new connection
insert image description here
, click the database to be dumped, right-click to dump the SQL file, structure and data , and then save the sql file.

Uninstall MySQL

Reference: https://jingyan.baidu.com/article/425e69e61a1b64be15fc1604.html .
1. Enter the cmd control terminal
2. Enter mysql -uroot -p
3. Enter the password, press Enter to display the mysql version information in the computer
4. Enter the control panel to uninstall Program
insert image description here
Uninstall the software starting with MySQL (I don’t know why there is no one in my program...)
The reference link looks like this:
insert image description here
5. Delete the previously installed mysql folder
6. Enter the registry editor (you can Enter directly in the search field regedit)
7. Enter HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\Eventlog\Application, and delete the contents of the folder beginning with MySQL. There are related content in the ControlSet002 folder insert image description here
in the link experience , but I don’t have this folder. If there is, the operation is the same as ControlSet001 , delete the content in the folder beginning with MySQL under the corresponding folder. 8. Enter HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\ Services\Eventlog\Application\MySQL, delete the content in the folder beginning with MySQL. After deleting the Mysql file in the registry, restart.

insert image description here

Reinstall MySQL (my version is 8.0.21)

1. Enter the MySQL official website: https://dev.mysql.com/downloads/mysql/8.0.html .
insert image description here
insert image description here
2. Decompress to the relevant directory (my decompression directory is D:\mysql-8 )
insert image description here
. After decompression, there are the following directories: 3. Create a new data folder and a my.ini configuration file
insert image description here
in the current directory . My my.ini configuration file content:
insert image description here

insert image description here

[mysqld]
#设置3306端口
port=3306
#设置mysql的安装目录
basedir=D:\mysql-8\mysql-8.0.21-winx64
#设置mysql数据库的数据的存放目录
datadir=D:\mysql-8\mysql-8.0.21![](https://img-blog.csdnimg.cn/20210203134800365.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3Byb2JsZW1SZWNvcmQ=,size_16,color_FFFFFF,t_70)
-winx64\data
#允许最大连接数
max_connections=200
#允许连接失败的次数。这是为了防止有人从该主机试图攻击数据库系统
max_connect_errors=10
#服务端使用的字符集默认为UTF8
character-set-server=utf8
#创建新表时将使用的默认存储引擎
default-storage-engine=INNODB
#默认使用"mysql_native_password"插件认证
default_authentication_plugin=mysql_native_password
[mysql]
#设置mysql客户端默认字符集
default-character-set=utf8
[client]
#设置mysql客户端连接服务端时默认使用的端口
port=3306
default-character-set=utf8

4. Edit the environment variable and add it
insert image description here
insert image description here
to the path

> %MYSQL_HOME%\bin

insert image description here
Then directly confirm to exit.
5. Run cmd
as an administrator 6. Enter the bin directory of the mysql installation package, and then initialize the database

> mysqld --initialize --console

insert image description here
7. Installation service:

> mysqld --instal

Normally it looks like this:
insert image description here

insert image description here
After Baidu, I found that my MySQL was not deleted.
Solution:
Run the cmd console as an administrator, and execute in sequence:

> sc query mysql
> sc delete mysql

insert image description here
Re-run:

> mysqld --install
> net start mysql

insert image description here
Enter MySQL : mysql -u root -p, and enter the initial password recorded in step 6 to successfully log in to MySQL.

Modify the MySQL login password : (for example, change the password to 123456)

> ALTER USER root@localhost IDENTIFIED  BY '123456'; 

Guess you like

Origin blog.csdn.net/problemRecord/article/details/113601485