Can‘t connect to MySQL server on ‘localhost‘ (10061) + MySQL服务启动后停止,某些服务在未由其他服务或程序使用时将自动停止

    技术2025-03-23  22

    每次当我想好好学一门计算机相关语言时,这些工具总会出现各种解决半天都解决不了的问题!都不知道自己干了啥,MySQL说不能用就不能用了!好气哦!

    出现问题:

    1.cmd无法连接数据库

    D:\>mysql -uroot -p Enter password: ******* ERROR 2003 (HY000): Can't connect to MySQL server on 'localhost' (10061)

    2.尝试cmd启用数据库

    D:\>net start mysql MySQL 服务正在启动 .. MySQL 服务无法启动。 服务没有报告任何错误。 请键入 NET HELPMSG 3534 以获得更多的帮助。

    3.尝试在“服务”——“MySQL”中启动,结果,,,, 4.根据网上的解决办法,尝试用mysqld --console查看哪里出了问题 (1)先是warning:

    [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use –explicit_defaults_for_timestamp server option (see documentation for more details).

    (2)网上给出的解决方案是在my.ini文件中添加一句:explicit_defaults_for_timestamp=true 再把default-character-set=utf8改成default_character_set=utf8 我把自己的ini文件修改保存了以后还是不行,呜呜呜

    (3)当我再次用mysqld --console查看时,好像,,变了

    D:\>mysqld --console 2020-07-04T03:05:09.375556Z 0 [Note] --secure-file-priv is set to NULL. Operations related to importing and exporting data are disabled 2020-07-04T03:05:09.376138Z 0 [Note] mysqld (mysqld 5.7.27) starting as process 4024 ... 2020-07-04T03:05:09.382869Z 0 [Note] InnoDB: Mutexes and rw_locks use Windows interlocked functions 2020-07-04T03:05:09.383513Z 0 [Note] InnoDB: Uses event mutexes 2020-07-04T03:05:09.383868Z 0 [Note] InnoDB: _mm_lfence() and _mm_sfence() are used for memory barrier 2020-07-04T03:05:09.384320Z 0 [Note] InnoDB: Compressed tables use zlib 1.2.11 2020-07-04T03:05:09.385455Z 0 [Note] InnoDB: Number of pools: 1 2020-07-04T03:05:09.386043Z 0 [Note] InnoDB: Not using CPU crc32 instructions 2020-07-04T03:05:09.390048Z 0 [Note] InnoDB: Initializing buffer pool, total size = 128M, instances = 1, chunk size = 128M 2020-07-04T03:05:09.400286Z 0 [Note] InnoDB: Completed initialization of buffer pool 2020-07-04T03:05:09.598485Z 0 [Note] InnoDB: Highest supported file format is Barracuda. 2020-07-04T03:05:10.218205Z 0 [Note] InnoDB: Creating shared tablespace for temporary tables 2020-07-04T03:05:10.219566Z 0 [Note] InnoDB: Setting file '.\ibtmp1' size to 12 MB. Physically writing the file full; Please wait ... 2020-07-04T03:05:10.376093Z 0 [Note] InnoDB: File '.\ibtmp1' size is now 12 MB. 2020-07-04T03:05:10.394155Z 0 [Note] InnoDB: 96 redo rollback segment(s) found. 96 redo rollback segment(s) are active. 2020-07-04T03:05:10.395427Z 0 [Note] InnoDB: 32 non-redo rollback segment(s) are active. 2020-07-04T03:05:10.399229Z 0 [Note] InnoDB: Waiting for purge to start 2020-07-04T03:05:10.455335Z 0 [Note] InnoDB: 5.7.27 started; log sequence number 4125493 2020-07-04T03:05:10.462023Z 0 [Note] InnoDB: Loading buffer pool(s) from D:\mysql-5.7.27-winx64\data\ib_buffer_pool 2020-07-04T03:05:10.462301Z 0 [Note] Plugin 'FEDERATED' is disabled. 2020-07-04T03:05:10.466032Z 0 [ERROR] unknown variable 'default_character_set=utf8' 2020-07-04T03:05:10.467282Z 0 [ERROR] Aborting 2020-07-04T03:05:10.468561Z 0 [Note] Binlog end 2020-07-04T03:05:10.469915Z 0 [Note] Shutting down plugin 'ngram' 2020-07-04T03:05:10.479955Z 0 [Note] Shutting down plugin 'partition' 2020-07-04T03:05:10.483081Z 0 [Note] Shutting down plugin 'BLACKHOLE' 2020-07-04T03:05:10.486103Z 0 [Note] Shutting down plugin 'ARCHIVE' 2020-07-04T03:05:10.493928Z 0 [Note] Shutting down plugin 'PERFORMANCE_SCHEMA' 2020-07-04T03:05:10.499694Z 0 [Note] Shutting down plugin 'MRG_MYISAM' 2020-07-04T03:05:10.501326Z 0 [Note] Shutting down plugin 'MyISAM' 2020-07-04T03:05:10.507396Z 0 [Note] Shutting down plugin 'INNODB_SYS_VIRTUAL' 2020-07-04T03:05:10.510170Z 0 [Note] Shutting down plugin 'INNODB_SYS_DATAFILES' 2020-07-04T03:05:10.514425Z 0 [Note] Shutting down plugin 'INNODB_SYS_TABLESPACES' 2020-07-04T03:05:10.515804Z 0 [Note] InnoDB: Buffer pool(s) load completed at 200704 11:05:10 2020-07-04T03:05:10.519566Z 0 [Note] Shutting down plugin 'INNODB_SYS_FOREIGN_COLS' 2020-07-04T03:05:10.531578Z 0 [Note] Shutting down plugin 'INNODB_SYS_FOREIGN' 2020-07-04T03:05:10.534004Z 0 [Note] Shutting down plugin 'INNODB_SYS_FIELDS' 2020-07-04T03:05:10.536109Z 0 [Note] Shutting down plugin 'INNODB_SYS_COLUMNS' 2020-07-04T03:05:10.540540Z 0 [Note] Shutting down plugin 'INNODB_SYS_INDEXES' 2020-07-04T03:05:10.543510Z 0 [Note] Shutting down plugin 'INNODB_SYS_TABLESTATS' 2020-07-04T03:05:10.548196Z 0 [Note] Shutting down plugin 'INNODB_SYS_TABLES' 2020-07-04T03:05:10.554573Z 0 [Note] Shutting down plugin 'INNODB_FT_INDEX_TABLE' 2020-07-04T03:05:10.557970Z 0 [Note] Shutting down plugin 'INNODB_FT_INDEX_CACHE' 2020-07-04T03:05:10.562653Z 0 [Note] Shutting down plugin 'INNODB_FT_CONFIG' 2020-07-04T03:05:10.566867Z 0 [Note] Shutting down plugin 'INNODB_FT_BEING_DELETED' 2020-07-04T03:05:10.568725Z 0 [Note] Shutting down plugin 'INNODB_FT_DELETED' 2020-07-04T03:05:10.571586Z 0 [Note] Shutting down plugin 'INNODB_FT_DEFAULT_STOPWORD' 2020-07-04T03:05:10.578964Z 0 [Note] Shutting down plugin 'INNODB_METRICS' 2020-07-04T03:05:10.581995Z 0 [Note] Shutting down plugin 'INNODB_TEMP_TABLE_INFO' 2020-07-04T03:05:10.589305Z 0 [Note] Shutting down plugin 'INNODB_BUFFER_POOL_STATS' 2020-07-04T03:05:10.591138Z 0 [Note] Shutting down plugin 'INNODB_BUFFER_PAGE_LRU' 2020-07-04T03:05:10.593840Z 0 [Note] Shutting down plugin 'INNODB_BUFFER_PAGE' 2020-07-04T03:05:10.597767Z 0 [Note] Shutting down plugin 'INNODB_CMP_PER_INDEX_RESET' 2020-07-04T03:05:10.603434Z 0 [Note] Shutting down plugin 'INNODB_CMP_PER_INDEX' 2020-07-04T03:05:10.605548Z 0 [Note] Shutting down plugin 'INNODB_CMPMEM_RESET' 2020-07-04T03:05:10.608055Z 0 [Note] Shutting down plugin 'INNODB_CMPMEM' 2020-07-04T03:05:10.610524Z 0 [Note] Shutting down plugin 'INNODB_CMP_RESET' 2020-07-04T03:05:10.622389Z 0 [Note] Shutting down plugin 'INNODB_CMP' 2020-07-04T03:05:10.624096Z 0 [Note] Shutting down plugin 'INNODB_LOCK_WAITS' 2020-07-04T03:05:10.629486Z 0 [Note] Shutting down plugin 'INNODB_LOCKS' 2020-07-04T03:05:10.634720Z 0 [Note] Shutting down plugin 'INNODB_TRX' 2020-07-04T03:05:10.636417Z 0 [Note] Shutting down plugin 'InnoDB' 2020-07-04T03:05:10.639492Z 0 [Note] InnoDB: FTS optimize thread exiting. 2020-07-04T03:05:10.641252Z 0 [Note] InnoDB: Starting shutdown... 2020-07-04T03:05:10.753595Z 0 [Note] InnoDB: Dumping buffer pool(s) to D:\mysql-5.7.27-winx64\data\ib_buffer_pool 2020-07-04T03:05:10.761455Z 0 [Note] InnoDB: Buffer pool(s) dump completed at 200704 11:05:10 2020-07-04T03:05:11.931996Z 0 [Note] InnoDB: Shutdown completed; log sequence number 4125512 2020-07-04T03:05:11.934279Z 0 [Note] InnoDB: Removed temporary tablespace data file: "ibtmp1" 2020-07-04T03:05:11.935081Z 0 [Note] Shutting down plugin 'MEMORY' 2020-07-04T03:05:11.935809Z 0 [Note] Shutting down plugin 'CSV' 2020-07-04T03:05:11.936511Z 0 [Note] Shutting down plugin 'sha256_password' 2020-07-04T03:05:11.937398Z 0 [Note] Shutting down plugin 'mysql_native_password' 2020-07-04T03:05:11.939224Z 0 [Note] Shutting down plugin 'binlog' 2020-07-04T03:05:11.944393Z 0 [Note] mysqld: Shutdown complete

    把这些错误大致翻译了一下,意思就是一些东西被禁用了,然后剩下大部分代码都是各种关闭,也不太懂,,,

    解决办法:

    好了,现在我要开始慢慢摸索和尝试不同的解决方案了 方法一:本地计算机上的MySQL服务启动后停止。某些服务在未由其他服务或程序使用时将自动停止[解决方案]

    https://mp.weixin.qq.com/s?src=11&timestamp=1593828276&ver=2439&signature=4JpwD8FNmbi3VU1nw4b9HOlqiIschpay1X5JiroAK9iYA8LIQ4X68URn9I98nwAmAsjnIvQxsUP2nsP2R4YXUBMqYZkCxhbRSfOK-BLVlovEEgWJhEQ6tX7hezV97u&new=1

    (1)进入MySQL安装目录下的bin文件中,利用dir查看其中的文件

    D:\>cd D:\mysql-5.7.27-winx64\bin D:\mysql-5.7.27-winx64\bin>dir 驱动器 D 中的卷没有标签。 卷的序列号是 AA94-0437 D:\mysql-5.7.27-winx64\bin 的目录

    (2)也不知道(1)啥意思,反正区mysql文件里,把data文件清空就好了(我将原data文件剪切到了别处) (3)然后以管理员身份,在bin目录下输入mysqld –initialize,等待了几秒,发现没有报错,接下里再输入net start mysql,结果,又报错了!

    D:\mysql-5.7.27-winx64\bin>mysqld --initialize D:\mysql-5.7.27-winx64\bin>net start mysql MySQL 服务正在启动 .. MySQL 服务无法启动。

    (4)再次用mysqld --console查看报错问题,发现没有什么变化,然后继续搜索

    (5)还是将data文件清空,移除mysql,再重启服务,还是不行,,,

    D:\mysql-5.7.27-winx64\bin>mysqld --remove mysql Service successfully removed. D:\mysql-5.7.27-winx64\bin>mysqld --initialize-insecure --user=mysql D:\mysql-5.7.27-winx64\bin>mysqld --install --defaults-file=D:\mysql-5.7.27-winx64\my.ini Failed to install the service (Couldn't create service)

    https://www.cnblogs.com/kuoAT/p/7080535.html

    方法二:算了,备份好data,重装数据库!

    https://blog.csdn.net/W_Z_W_888/article/details/79054687

    方法三:这个安装过程清晰,我再次重启了MySQL,舒服!

    https://mp.weixin.qq.com/s/DJP9dCJNDErz8H36w_wtGw

    我还学到了一个新的启动mysql的方法! 直接开始+R,输入mysql -uroot -p 这样进去一输入密码即可!

    不过按照方法三安装的MySQL目录和以往不太一样,mysql目录下没有data文件,网上说通过cmd可以查看

    mysql> show global variables like "%datadir%"; +---------------+---------------------------------------------+ | Variable_name | Value | +---------------+---------------------------------------------+ | datadir | C:\ProgramData\MySQL\MySQL Server 5.7\Data\ | +---------------+---------------------------------------------+

    但是问题来了,C盘找不到ProgramData 原来,这个文件是隐藏文件,只需在文件夹上方,点击“查看”,勾选隐藏项目,这个文件夹就出来了! 试了一下,发现直接复制data文件过去,有表,但是仍然做不了任何操作,不浪费时间了,,,幸好我之前留了底,就重新搞一份好了。

    mysql> drop database lianxi; ERROR 1010 (HY000): Error dropping database (can't rmdir '.\lianxi', errno: 41) mysql> use rsgl; Database changed mysql> select *from gzb; ERROR 1146 (42S02): Table 'rsgl.gzb' doesn't exist mysql> show tables; +----------------+ | Tables_in_rsgl | +----------------+ | denglub | | department | | employee | | gzb | | kaoqb | +----------------+ 5 rows in set (0.00 sec) mysql> desc gzb; ERROR 1146 (42S02): Table 'rsgl.gzb' doesn't exist
    Processed: 0.009, SQL: 9