Windows 64 bit MySQL 5.7 or above does not contain the data directory and my- default.ini and my.ini The solution to the problem that the file and service cannot be started and the method to change the initial password.
Download address of MySQL official website
Take version 5.7.20 as an example
First of all, after the installation package is decompressed, there is no data folder and my mentioned in the online tutorial- default.ini , as shown in the figure below
Please refer to the online tutorial for the configuration of environment variables. Generally, there is no problem. In other words, add the path of MySQL decompression package bin to the path of environment variable. My name is:
Pay attention to the following points:
（1）my- default.ini It doesn’t matter whether the file exists or not. The key is to create a new one in the root directory my.ini The contents are as follows:
[mysql] #Setting the default character set of MySQL client default-character-set=utf8 [mysqld] #Set 3306 port port = 3306 #Set MySQL installation directory basedir=D:\softnew\MYSQL\mysql-5.7.20-winx64 #Maximum number of connections allowed max_connections=200 #The character set used by the server is the 8-bit Latin1 character set by default character-set-server=utf8 #The default storage engine that will be used when creating a new table default-storage-engine=INNODB
You can copy and paste directly. You can mainly modify the path after basedir. Note that the path in the path is \ \ instead of\
(2) Please do not create your own data folder
Many online tutorials suggest that you create an empty data folder, and then my.ini Add a sentence to the document:
#Set the storage directory of MySQL database data datadir=D:\softnew\MYSQL\mysql-5.7.20-winx64\data
This will cause the service to fail to start. Do not add this sentence or create a new data folder by yourself. Just let MySQL automatically generate data
1）As an administratorOpen the CMD command window (open the CMD to run directly, error may be reported), and enter theUnder the bin directory of MySQL installation directory。 Then enter the command mysqld install to display success
2) Re enter: mysqld – initialize. There should be no prompt at this time
3) Re input: Net start MySQL display
Finally, the contents in the data folder should be displayed as follows:
Note: when you log in MySQL for the first time, you will be prompted to input the initial password, which is considered the security factor. The command: mysqld – initialize will generate the password randomly.
The initial password is in the data folder in the figure above xxx.err In the file, you can open it in Notepad and use the CTRL + F search function to find the following line of records:
[Note] A temporary password is generated for [email protected]: NZ+uhXPq1zN.
Where NZ + uhxpq1zn. Is the initial password
After entering, you can use the following command to change the password to root:
ALTER USER 'root'@'localhost' IDENTIFIED BY 'root';
Here is version 5.7.22, which is shown as follows:
Wonderful topic sharing:
Different versions of MySQL installation tutorial
Mysql5.7 installation tutorial
Mysql5.6 installation tutorial
Mysql8.0 installation tutorial
The above is the whole content of this article, I hope to help you in your study, and I hope you can support developeppaer more.