Mysql cannot start the service and other problems summary

1. Questions about configuration after installation

Display [System error occurred, access denied]

  1. After mysql is installed, run cmd and execute the [net start mysql] command and an error message appears: System error 5. access denied.
    Insert image description here
    Cause: The cmd.exe program is not run with administrator privileges
    Solution:
    Find the command prompt on your computer—>right-click—>Run as administrator

  2. Re-enter [net start mysql]
    Error report: [System error 2 occurred. The system can not find the file specified. 】
    Try to solve:
    [mysqld --remove]
    [mysqld --install]
    Insert image description here

Command Line Client crashes

  1. The window flashes away after double-clicking MySQL Command Line Client:
    Solution:
    1) View the program Does the default execution file exist
    2) Or is it because the MySQL service has not been started
  2. The MySQL Command Line Client back window crashes after entering the password:
    Solution: As an administrator Enter cmd, enter the command [net start mysql] to restart mysql, and then restart the MySQL Command Line Client.

2. The problem [MySQL service cannot be started] is displayed

After the installation and debugging, it has not been used for a while, and then the command prompt displays this [MySQL service cannot be started].
Insert image description here
Due to the reaction speed when starting from the command line, if it cannot be started, try starting mysql from the task manager.
Insert image description here
If it still doesn’t work, try the following methods:

Check if the port is occupied

Since the default port of mysql is 3306, you need to check whether there is a running process under this port number.
Method 1: Use cmd to enter the path of the installation directory bin, enter the command [netstat -ano], and find the PID value of the 3306 interface. As can be seen from the picture below, it is [8964]
Insert image description here
. Open the Task Manager -> Detailed information, find the corresponding mysql process according to the PID, and right-click to close it.
Insert image description here
Restart mysql, enter [net start mysql]

Method 2:
Check the usage of port 3306

  1. Open the command prompt and enter [netstat -aon|findstr "3306"]
    Insert image description here
    Note: 33060 is an extension of mysql8.0+ version port

  2. To forcefully terminate process 8964, enter [taskkill /F /pid 8964], and it will show successful termination.
    Insert image description here

Delete data file and initialize

This is the method I find most often tried.

If it is not the first installation and has been used before, you need to manually delete the data file in the mysql installation directory. My installation path is C:\Program Files\MySQL\MySQL Server 8.0\data
Open command prompt as administrator——

Note: There are three ways

(1) Execute [mysqld --initialize-insecure] (form a data folder in the installation directory, which will not be displayed or will be initializedemptyPassword)
Insert image description here
Note: When you enter the password later, just press Enter
Insert image description here
(2) [mysqld --initialize] (A new password will be formed after initialization, in the file ending with .err in the data file)
**root@localhost: The string after ** is the password after initialization

(3) [mysqld --initialize --console] (all initialization information will be displayed directly on the console)

—> Then restart mysql [net start mysql]
—> After successful startup [mysql -u root -p]
— > Enter the initialized password and enter mysql
—> Change the password,
[use mysql]
mysql>[ ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'your new password';

Note: An error may occur [ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corre]
Solution:
[flush privileges;]
[ALTER USER 'root'@'localhost' IDENTIFIED BY 'new password';]
Insert image description here
There is another small problem here. The initialization is not successful. After entering the command line, it is found that the startup is still unsuccessful. At this time, open the data file under .err The file at the end will show the error log
Insert image description here
When you see this line of content, you will find that it is actually a port problem. See the solution above for details.

Configure my.ini/.conf file

Check whether there is a configuration file in the installation path. If not, create one [my.ini] by hand
Insert image description here
Configure related properties:

[mysqld]
#设置北京时间
default-time_zone = '+8:00'
# 设置3306端口
port=3306
# 设置mysql的安装目录
basedir=D:\MySQLDB\mysql-8.0.22-winx64(这里需要改成你的数据库所在目录)
# 设置mysql数据库的数据的存放目录
datadir=D:\MySQLDB\mysql-8.0.22-winx64\data(这里需要改成你的数据库中data所在目录)
# 允许最大连接数
max_connections=200
# 允许连接失败的次数。这是为了防止有人从该主机试图攻击数据库系统
max_connect_errors=10
# 服务端使用的字符集默认为UTF8
character_set_server=utf8
# 创建新表时将使用的默认存储引擎
default-storage-engine=INNODB
# 默认使用“mysql_native_password”插件认证
default_authentication_plugin=mysql_native_password
# 解决无法写入空时间,解除严格限制模式
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
 
[mysql]
# 设置mysql客户端默认字符集
default-character-set=utf8
[client]
# 设置mysql客户端连接服务端时默认使用的端口
port=3306
default-character-set=utf8

Reinstall MySQL

Delete the existing mysql service and reinstall it.

Guess you like

Origin blog.csdn.net/weixin_42223850/article/details/129427124