All questions about mysql reinstallation are here
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.
#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
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:
First Drive letter:/
Thencd 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
is actually
mysql service program, so running mysqld is running the mysql serviceAs 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
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 installCopy after login.\mysqld.exe --initialize-insecure --user=mysqlCopy after login
还不能登录需要手动启动服务
第一次使用mysql 可以通过mysql.exe -u root -p直接登录进去,如果数据库里没有内容则删除data文件夹(手动关闭mysql服务才可以删除)
然后重新手动启动服务,重新初始化数据库如何登录进(第一次不需要密码) 将下面的123456改成你想要的密码即可
修改root密码(需要在mysql的bin目录下操作,如果配置了环境变量就不需要在bin目录下)
.\mysqld.exe -u root -p
use mysql;
ALTER USER `root`@`localhost` IDENTIFIED BY '123456';
如果你只是想安装mysql那么上面已经安装完了
下面是忘记root密码,进入数据库修改的操作
第1步、关闭服务 也可以通过服务手动关闭(前面的截图),或者输入下面的命令
net stop mysql
第2步、(管理员身份)cd 到mysql主目录的bin目录下
.\mysqld.exe --console --skip-grant-tables --shared-memory
如图
需要另外开一个powershell窗口在bin目录下 按住Shift 鼠标右键会有一个在此处打开powershell窗口
然后登录进去(不需要输密码)直接回车即可登录进去
.\mysql.exe -u root -p
启用mysql数据库
use mysql;
这里的 authentication_string不是密码后面操作才是真正修改密码的
update user set authentication_string='' where user='root';
上面只是为了运行root无密码登录,因为前面通过--skip-grant-tables选项导致修改密码的sql : ALTER USER `root`@`localhost` IDENTIFIED BY '123456';不能修改密码
退出登录
quit
并且把那个执行命令带有 --skip-grant-tables 窗口关闭
然后启动mysql服务
net start mysql
按照正常的登录,不需要输root密码即可登录进去
.\mysql.exe -u root -p
use mysql;
修改root密码
ALTER USER `root`@`localhost` IDENTIFIED BY '123456';
在使用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
然通过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
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!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Big data structure processing skills: Chunking: Break down the data set and process it in chunks to reduce memory consumption. Generator: Generate data items one by one without loading the entire data set, suitable for unlimited data sets. Streaming: Read files or query results line by line, suitable for large files or remote data. External storage: For very large data sets, store the data in a database or NoSQL.

Backing up and restoring a MySQL database in PHP can be achieved by following these steps: Back up the database: Use the mysqldump command to dump the database into a SQL file. Restore database: Use the mysql command to restore the database from SQL files.

MySQL query performance can be optimized by building indexes that reduce lookup time from linear complexity to logarithmic complexity. Use PreparedStatements to prevent SQL injection and improve query performance. Limit query results and reduce the amount of data processed by the server. Optimize join queries, including using appropriate join types, creating indexes, and considering using subqueries. Analyze queries to identify bottlenecks; use caching to reduce database load; optimize PHP code to minimize overhead.

How to insert data into MySQL table? Connect to the database: Use mysqli to establish a connection to the database. Prepare the SQL query: Write an INSERT statement to specify the columns and values to be inserted. Execute query: Use the query() method to execute the insertion query. If successful, a confirmation message will be output.

To use MySQL stored procedures in PHP: Use PDO or the MySQLi extension to connect to a MySQL database. Prepare the statement to call the stored procedure. Execute the stored procedure. Process the result set (if the stored procedure returns results). Close the database connection.

Creating a MySQL table using PHP requires the following steps: Connect to the database. Create the database if it does not exist. Select a database. Create table. Execute the query. Close the connection.

One of the major changes introduced in MySQL 8.4 (the latest LTS release as of 2024) is that the "MySQL Native Password" plugin is no longer enabled by default. Further, MySQL 9.0 removes this plugin completely. This change affects PHP and other app

Oracle database and MySQL are both databases based on the relational model, but Oracle is superior in terms of compatibility, scalability, data types and security; while MySQL focuses on speed and flexibility and is more suitable for small to medium-sized data sets. . ① Oracle provides a wide range of data types, ② provides advanced security features, ③ is suitable for enterprise-level applications; ① MySQL supports NoSQL data types, ② has fewer security measures, and ③ is suitable for small to medium-sized applications.
