Home > Database > Mysql Tutorial > All questions about mysql reinstallation are here

All questions about mysql reinstallation are here

WBOY
Release: 2021-12-20 17:41:13
forward
3344 people have browsed it

This article brings you knowledge about mysql reinstallation. I believe many people have encountered the need to reinstall mysql. What should I do if I forget the root password? How should different systems be operated? Let's take a look at the problems encountered when reinstalling mysql and how to solve them. I hope it will be helpful to everyone.

All questions about mysql reinstallation are here

#I encountered a problem recently and reinstalled the system, but fortunately the mysql installation directory was not installed on the system disk.

So how to retrieve the previous data in mysql?

To make a long story short, let me tell you the whole story. Increased knowledge

Have you ever installed mysql under Linux and forgotten the mysql root password? (Or under Windows)

Have you ever configured jdk environment variables?

Haha~ I believe many friends have had the same experience as me.

Are you going crazy when you find that you can’t log in with your password? Installing a mysql has gone through many hardships, and some friends even failed to install it properly because of database problems ~ _~! As a result, subsequent installations failed. I even reinstalled the system later.

Then the following will be the answer to all your questions:

Take the mysql8.0 Windows environment as an example:

If you do not select a path when you install it Then mysql is installed on the C drive by default. If you have specified the installation path

then find where mysql is installed

If you have installed Mysql before

then check first Check whether there is a mysql service for this computer in the service ==>Management==>Services and Applications==>Services As shown below

Uninstall the mysql service, if there are redundant services You can use

sc.exe delete service name to delete useless services. After deletion, you need to restart the computer

sc.exe delete MySql
Copy after login

You can also use the service properties to find the location of the service mysqld.exe remove (this kind The method may not be effective, if there is a problem with the path,)

If the original file is still there, you can delete the service through mysqld.exe remove under this path

Let’s do an experiment, Experience how to configure the decompressed version (green) mysql. It needs to be executed under a Windows that has not installed mysql. You can use VMware Virtualization means installing a Windows environment. Downloads for Windows can be found in my installation operating system. https://msdn.itelleyou.cn/ has images of ed2k links for all Windows systems. Just download them

First step, go to the mysql official website to download a zip package of a free installation version of MySQL

https://dev.mysql.com/downloads/mysql/

Then decompress, go to the decompressed directory and check the above files

The second step is to install the service and initialize mysql

Run the powerShell window as an administrator through Windows logo

##Switch to the decompression directory:

Corresponding command

First Drive letter:/

Then

cd to the decompressed directory

Of course you can also hold down Shift and right-click the mouse and there will be a powershell window

As shown below

Official start

Installation service This

mysqld

is actually

mysql service program, so running mysqld is running the mysql service

.\mysqld.exe install
Copy after login
If it prompts that mysql has been installed, find the mysql service in the service, start the mysql service, or remove through mysql.exe To remove the service, you must first stop itInitialize

.\mysqld.exe --initialize-insecure --user=mysql
Copy after login
As shown above, you will get the data folder, which stores the database information. After deletion, the database is no longer there, and you need to re-operate

还不能登录需要手动启动服务

第一次使用mysql 可以通过mysql.exe -u root -p直接登录进去,如果数据库里没有内容则删除data文件夹(手动关闭mysql服务才可以删除)

然后重新手动启动服务,重新初始化数据库如何登录进(第一次不需要密码) 将下面的123456改成你想要的密码即可

修改root密码(需要在mysql的bin目录下操作,如果配置了环境变量就不需要在bin目录下)

.\mysqld.exe -u root -p
Copy after login
use mysql;
Copy after login
Copy after login
Copy after login
ALTER USER `root`@`localhost` IDENTIFIED BY '123456';
Copy after login
Copy after login

如果你只是想安装mysql那么上面已经安装完了

下面是忘记root密码,进入数据库修改的操作

第1步、关闭服务 也可以通过服务手动关闭(前面的截图),或者输入下面的命令

net stop mysql
Copy after login

第2步、(管理员身份)cd 到mysql主目录的bin目录下

.\mysqld.exe --console --skip-grant-tables --shared-memory
Copy after login

如图

需要另外开一个powershell窗口在bin目录下 按住Shift 鼠标右键会有一个在此处打开powershell窗口

然后登录进去(不需要输密码)直接回车即可登录进去

 .\mysql.exe -u root -p
Copy after login
Copy after login

启用mysql数据库

use mysql;
Copy after login
Copy after login
Copy after login

这里的 authentication_string不是密码后面操作才是真正修改密码的

update user set authentication_string='' where user='root';
Copy after login

上面只是为了运行root无密码登录,因为前面通过--skip-grant-tables选项导致修改密码的sql : ALTER USER `root`@`localhost` IDENTIFIED BY '123456';不能修改密码

退出登录

quit
Copy after login

并且把那个执行命令带有 --skip-grant-tables 窗口关闭

然后启动mysql服务

net start mysql
Copy after login

按照正常的登录,不需要输root密码即可登录进去

 .\mysql.exe -u root -p
Copy after login
Copy after login
use mysql;
Copy after login
Copy after login
Copy after login

修改root密码

ALTER USER `root`@`localhost` IDENTIFIED BY '123456';
Copy after login
Copy after login

在使用mysql的过程中是否有疑问?mysql的数据源到底放在了哪里?下面解答

mysql的数据源实际就在data文件夹内,我们进行一个实验尝试一下

使用目的:

证明mysql的数据源在data文件夹下,并且可以通过指定数据源路径,直接使用mysql找到原来的数据。即使现在电脑上没有安装mysql,然后通过复制原来mysql安装目录,来继续使用原来的mysql数据库和数据;

实验部分:

为了实验有效果我们创建一个数据库,这里干脆叫demo(如果你本身有数据库那么更好直接下面实验)

下面的使用即使没有安装过mysql数据库,也可以操作,只需mysql的主目录即可(数据data文件夹下)

第一步、关闭mysql服务 net stop mysql

第二步、新建my.ini文本文件,用来指定mysql位置和数据源位置

将mysql主目录下的data文件夹复制 到D:/盘根目录下 需要关闭服务才可以移动,否则会提示后台占用!

新建 my.ini 文本文件(干脆放在D:\mysql-8.0.18-winx64 即放在主目录下,5.5以前有这个文件后面都没有了)

写入如下的代码,指定数据库的主目录,数据源路径 以及端口

[mysqld]
basedir = D:\mysql-8.0.18-winx64
datadir = D:\data
port =3306
Copy after login

然通过mysqld启动mysql服务如下图

此时其实也可以通过第三方工具链接mysql 例如Navicat

下面通过命令连接,需要另开一个窗口

可以看到这里连上了mysql并且是原先的数据库!!

反例测试 一、

关闭前面所以powershell窗口

在前面的基础上 将my.ini删除,这样mysqld就找不到数据源,看下它提示了什么错误

这里因为没有my.ini告诉mysqld程序mysql主目录在那以及数据源在那,导致执行失败

现在通过.\mysql.exe -u root -p肯定连接不上因为mysql服务都没有启动起来

Counter example test two,

Delete the datadir of my.ini, as shown below

##Then try the same as before

A bunch of errors were reported at this time. Please check the error prompts for specific errors. Then you only need to modify them according to the error prompts.

For example, the first ERROR prompt The error message file cannot be found

The error-message file only needs to be specified in the configuration file to find the correct location

[Recommended:

mysql video tutorial]

The above is the detailed content of All questions about mysql reinstallation are here. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:csdn.net
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template