mysql服务无法启动,ERROR 2003 (HY000): Can't connect to MySQL server on 'localhost' (10061)解决办法

时间:2022-01-24 00:22:08

很长时间没有用数据库了,之前在电脑上安装了mysql,但是许久不用,最近用起来却是问题多多,提示无法启动服务器, 却没有报任何错误。使用net start mysql 启动服务提示如下图:mysql服务无法启动,ERROR 2003 (HY000): Can't connect to MySQL server on 'localhost' (10061)解决办法
使用mysql –console命令查看错误信息。如下:

D:\Program Files (x86)\mysql\bin>mysqld –console
2018-01-27T07:04:33.136066Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use –explicit_defaults_for_timestamp server option (see documentation for more details).
2018-01-27T07:04:33.136066Z 0 [Warning] ‘NO_ZERO_DATE’, ‘NO_ZERO_IN_DATE’ and ‘ERROR_FOR_DIVISION_BY_ZERO’ sql modes should be used with strict mode. They will be merged with strict mode in a future release.
2018-01-27T07:04:33.136066Z 0 [Warning] ‘NO_AUTO_CREATE_USER’ sql mode was not set.
2018-01-27T07:04:33.136566Z 0 [Note] –secure-file-priv is set to NULL. Operations related to importing and exporting data are disabled
2018-01-27T07:04:33.137072Z 0 [Note] mysqld (mysqld 5.7.16) starting as process 8304 …
2018-01-27T07:04:33.153080Z 0 [Note] InnoDB: Mutexes and rw_locks use Windows interlocked functions
2018-01-27T07:04:33.155586Z 0 [Note] InnoDB: Uses event mutexes
2018-01-27T07:04:33.158582Z 0 [Note] InnoDB: _mm_lfence() and _mm_sfence() are used for memory barrier
2018-01-27T07:04:33.162091Z 0 [Note] InnoDB: Compressed tables use zlib 1.2.3
2018-01-27T07:04:33.166087Z 0 [Note] InnoDB: Number of pools: 1
2018-01-27T07:04:33.168093Z 0 [Note] InnoDB: Not using CPU crc32 instructions
2018-01-27T07:04:33.178617Z 0 [Note] InnoDB: Initializing buffer pool, total size = 128M, instances = 1, chunk size = 128M
2018-01-27T07:04:33.196880Z 0 [Note] InnoDB: Completed initialization of buffer pool
2018-01-27T07:04:33.301294Z 0 [Note] InnoDB: Highest supported file format is Barracuda.
2018-01-27T07:04:33.398212Z 0 [Note] InnoDB: Creating shared tablespace for temporary tables
2018-01-27T07:04:33.400215Z 0 [Note] InnoDB: Setting file ‘.\ibtmp1’ size to 12 MB. Physically writing the file full; Please wait …
2018-01-27T07:04:33.762696Z 0 [Note] InnoDB: File ‘.\ibtmp1’ size is now 12 MB.
2018-01-27T07:04:33.768670Z 0 [Note] InnoDB: 96 redo rollback segment(s) found. 96 redo rollback segment(s) are active.
2018-01-27T07:04:33.769649Z 0 [Note] InnoDB: 32 non-redo rollback segment(s) are active.
2018-01-27T07:04:33.776647Z 0 [Note] InnoDB: Waiting for purge to start
2018-01-27T07:04:33.863016Z 0 [Note] InnoDB: 5.7.16 started; log sequence number 1210037
2018-01-27T07:04:33.871522Z 0 [Note] Plugin ‘FEDERATED’ is disabled.
2018-01-27T07:04:33.872524Z 0 [Note] InnoDB: Loading buffer pool(s) from D:\Program Files (x86)\mysql\data\ib_buffer_pool
mysqld: Table ‘mysql.plugin’ doesn’t exist
2018-01-27T07:04:33.879708Z 0 [ERROR] Can’t open the mysql.plugin table. Please run mysql_upgrade to create it.
2018-01-27T07:04:33.883719Z 0 [Warning] Gtid table is not ready to be used. Table ‘mysql.gtid_executed’ cannot be opened.
2018-01-27T07:04:33.884219Z 0 [Note] InnoDB: Buffer pool(s) load completed at 180127 15:04:33
2018-01-27T07:04:33.884716Z 0 [Warning] Failed to set up SSL because of the following SSL library error: SSL context is not usable without certificate and private key
2018-01-27T07:04:33.891085Z 0 [Note] Server hostname (bind-address): ‘127.0.0.1’; port: 3306
2018-01-27T07:04:33.896110Z 0 [Note] - ‘127.0.0.1’ resolves to ‘127.0.0.1’;
2018-01-27T07:04:33.899095Z 0 [Note] Server socket created on IP: ‘127.0.0.1’.
2018-01-27T07:04:33.901596Z 0 [Warning] Failed to open optimizer cost constant tables

2018-01-27T07:04:33.932264Z 0 [ERROR] Fatal error: Can’t open and lock privilege tables: Table ‘mysql.user’ doesn’t exist
2018-01-27T07:04:33.934266Z 0 [ERROR] Aborting

2018-01-27T07:04:33.936266Z 0 [Note] Binlog end
2018-01-27T07:04:33.938769Z 0 [Note] Shutting down plugin ‘ngram’
2018-01-27T07:04:33.941273Z 0 [Note] Shutting down plugin ‘partition’
2018-01-27T07:04:33.944295Z 0 [Note] Shutting down plugin ‘BLACKHOLE’
2018-01-27T07:04:33.947699Z 0 [Note] Shutting down plugin ‘ARCHIVE’
2018-01-27T07:04:33.952246Z 0 [Note] Shutting down plugin ‘PERFORMANCE_SCHEMA’
2018-01-27T07:04:33.957152Z 0 [Note] Shutting down plugin ‘MRG_MYISAM’
2018-01-27T07:04:33.959657Z 0 [Note] Shutting down plugin ‘MyISAM’
2018-01-27T07:04:33.961655Z 0 [Note] Shutting down plugin ‘INNODB_SYS_VIRTUAL’
2018-01-27T07:04:33.963653Z 0 [Note] Shutting down plugin ‘INNODB_SYS_DATAFILES’
2018-01-27T07:04:33.967396Z 0 [Note] Shutting down plugin ‘INNODB_SYS_TABLESPACES’
2018-01-27T07:04:33.969398Z 0 [Note] Shutting down plugin ‘INNODB_SYS_FOREIGN_COLS’
2018-01-27T07:04:33.972404Z 0 [Note] Shutting down plugin ‘INNODB_SYS_FOREIGN’
2018-01-27T07:04:33.974905Z 0 [Note] Shutting down plugin ‘INNODB_SYS_FIELDS’
2018-01-27T07:04:33.978926Z 0 [Note] Shutting down plugin ‘INNODB_SYS_COLUMNS’
2018-01-27T07:04:33.980927Z 0 [Note] Shutting down plugin ‘INNODB_SYS_INDEXES’
2018-01-27T07:04:33.983910Z 0 [Note] Shutting down plugin ‘INNODB_SYS_TABLESTATS’
2018-01-27T07:04:33.985910Z 0 [Note] Shutting down plugin ‘INNODB_SYS_TABLES’
2018-01-27T07:04:33.990736Z 0 [Note] Shutting down plugin ‘INNODB_FT_INDEX_TABLE’
2018-01-27T07:04:33.992949Z 0 [Note] Shutting down plugin ‘INNODB_FT_INDEX_CACHE’
2018-01-27T07:04:33.995451Z 0 [Note] Shutting down plugin ‘INNODB_FT_CONFIG’
2018-01-27T07:04:33.997966Z 0 [Note] Shutting down plugin ‘INNODB_FT_BEING_DELETED’
2018-01-27T07:04:34.001545Z 0 [Note] Shutting down plugin ‘INNODB_FT_DELETED’
2018-01-27T07:04:34.003521Z 0 [Note] Shutting down plugin ‘INNODB_FT_DEFAULT_STOPWORD’
2018-01-27T07:04:34.007029Z 0 [Note] Shutting down plugin ‘INNODB_METRICS’
2018-01-27T07:04:34.010030Z 0 [Note] Shutting down plugin ‘INNODB_TEMP_TABLE_INFO’
2018-01-27T07:04:34.013049Z 0 [Note] Shutting down plugin ‘INNODB_BUFFER_POOL_STATS’
2018-01-27T07:04:34.015051Z 0 [Note] Shutting down plugin ‘INNODB_BUFFER_PAGE_LRU’
2018-01-27T07:04:34.017940Z 0 [Note] Shutting down plugin ‘INNODB_BUFFER_PAGE’
2018-01-27T07:04:34.019978Z 0 [Note] Shutting down plugin ‘INNODB_CMP_PER_INDEX_RESET’
2018-01-27T07:04:34.024836Z 0 [Note] Shutting down plugin ‘INNODB_CMP_PER_INDEX’
2018-01-27T07:04:34.026841Z 0 [Note] Shutting down plugin ‘INNODB_CMPMEM_RESET’
2018-01-27T07:04:34.029461Z 0 [Note] Shutting down plugin ‘INNODB_CMPMEM’
2018-01-27T07:04:34.031472Z 0 [Note] Shutting down plugin ‘INNODB_CMP_RESET’
2018-01-27T07:04:34.034970Z 0 [Note] Shutting down plugin ‘INNODB_CMP’
2018-01-27T07:04:34.036992Z 0 [Note] Shutting down plugin ‘INNODB_LOCK_WAITS’
2018-01-27T07:04:34.040473Z 0 [Note] Shutting down plugin ‘INNODB_LOCKS’
2018-01-27T07:04:34.045402Z 0 [Note] Shutting down plugin ‘INNODB_TRX’
2018-01-27T07:04:34.047893Z 0 [Note] Shutting down plugin ‘InnoDB’
2018-01-27T07:04:34.050219Z 0 [Note] InnoDB: FTS optimize thread exiting.
2018-01-27T07:04:34.052437Z 0 [Note] InnoDB: Starting shutdown…
2018-01-27T07:04:34.157460Z 0 [Note] InnoDB: Dumping buffer pool(s) to D:\Program Files (x86)\mysql\data\ib_buffer_pool
2018-01-27T07:04:34.162963Z 0 [Note] InnoDB: Buffer pool(s) dump completed at 180127 15:04:34
2018-01-27T07:04:35.213788Z 0 [Note] InnoDB: Shutdown completed; log sequence number 1210056
2018-01-27T07:04:35.215789Z 0 [Note] InnoDB: Removed temporary tablespace data file: “ibtmp1”
2018-01-27T07:04:35.220130Z 0 [Note] Shutting down plugin ‘MEMORY’
2018-01-27T07:04:35.224125Z 0 [Note] Shutting down plugin ‘CSV’
2018-01-27T07:04:35.229127Z 0 [Note] Shutting down plugin ‘sha256_password’
2018-01-27T07:04:35.232630Z 0 [Note] Shutting down plugin ‘mysql_native_password’
2018-01-27T07:04:35.240522Z 0 [Note] Shutting down plugin ‘binlog’
2018-01-27T07:04:35.246009Z 0 [Note] mysqld: Shutdown complete
经过一天的查找最终发现是因为mysql安装目录下的data文件夹中的数据有问题,定位到问题了,修改起来就不难啦!
我们可以使用mysql –initialize命令让mysql自己初始化data文件夹,这样就不会有问题了。
但是注意执行mysql –initialize命令前应该注释掉安装目录下my.ini中datadir一行的内容,并删除掉原先的data目录,在执行就好了。
再次启动mysql就会成功啦!
希望能够帮助大家^-^