The MySQL service failed to start and the service did not report any errors

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 服务无法启动。

服务没有报告任何错误。

insert image description here

  • Error 2: ERROR 2003 (HY000): Can't connect to MySQL server on 'localhost' (10061)
    insert image description here

The first is the solution to the failure to start MySQL normally

insert image description here

  1. 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)
    insert image description here

  2. Method 2: Clear the data file and install it (successfully)

    1. 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)insert image description here

    2. 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)insert image description here

    3. If the mysql service has been installed, you need to delete the service firstsc delete mysql insert image description here

    4. Install the MySQL servicemysqld --install mysqlinsert image description here

    5. Try to start the MySQL service again net start mysql(this time it works)insert image description here

Then there is the problem of database connection error

insert image description here

  1. 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
  1. Run cmd as an administrator to execute sc query mysqland sc delete mysqldelete the original installed [mysql] (executed separately)insert image description here
    insert image description here

  2. Empty the data folder in the MySQL directory again

  3. Run it under the bin folder of mysql mysqld --initialize-insecure, and wait for the operation to complete.insert image description here

  4. Continue to run mysqld.exe --install mysql --defaults-file=E:\mysql-8.0.18-winx64\my.ini(remember to change the address)insert image description here

  5. Then try to start the servicenet start mysqlinsert image description here

Guess you like

Origin blog.csdn.net/G18336319744/article/details/129761304