Today, when running the Bishe project, two errors occurred when using mysql, and I stumbled all day, so I will summarize the last useful method to prevent confusion next time
- Error 1: The mysql service failed to start normally, and the service did not report any errors.
mysql 服务正在启动 .
mysql 服务无法启动。
服务没有报告任何错误。
- Error 2: ERROR 2003 (HY000): Can't connect to MySQL server on 'localhost' (10061)
The first is the solution to the failure to start MySQL normally
-
Method 1: Try to manually start the MySQL service
Execute the services.msc command in the dos window , find MySQL after the service window pops up, and right-click to start it (I couldn’t start it at the time, and the startup will be interrupted after clicking Start, so it’s a pass for me)
-
Method 2: Clear the data file and install it (successfully)
-
Empty the data file in the MySQL directory (I backed up a copy first, then emptied the data directly instead of deleting the data and building the data folder)
-
Execute the command line in the bin directory
mysqld --initialize --console
(root@localhost: the following string is the initial login password of mysql, it is best to copy and keep it, you will use it later) -
If the mysql service has been installed, you need to delete the service first
sc delete mysql
-
Install the MySQL service
mysqld --install mysql
-
Try to start the MySQL service again
net start mysql
(this time it works)
-
Then there is the problem of database connection error
- Configure the my.ini file under the mysql file, refer to: (Remember to change the directory to your own)
[client]
# 设置mysql客户端默认字符集
default-character-set=utf8
[mysqld]
# 设置3306端口
port = 3306
# 设置mysql的安装目录
basedir ="E:\mysql-8.0.18-winx64"
# mysql数据存放目录
datadir ="E:\mysql-8.0.18-winx64\data"
# 允许最大连接数
max_connections=20
# 服务端使用的字符集默认为8比特编码的latin1字符集
character-set-server=utf8
# 创建新表时将使用的默认存储引擎
default-storage-engine=INNODB
-
Run cmd as an administrator to execute
sc query mysql
andsc delete mysql
delete the original installed [mysql] (executed separately)
-
Empty the data folder in the MySQL directory again
-
Run it under the bin folder of mysql
mysqld --initialize-insecure
, and wait for the operation to complete. -
Continue to run
mysqld.exe --install mysql --defaults-file=E:\mysql-8.0.18-winx64\my.ini
(remember to change the address) -
Then try to start the service
net start mysql