MySQL 启动失败的常见原因---发表到爱可生开源社区

MySQL 启动失败的常见原因---发表到爱可生开源社区爱可生开源社区 技术分享 MySQL 启动失败的常见原因 MySQL 启动失败的最常见的原因有两类 分别是无法访问系统资源和参数设置错误造成的 下面分别分析如下 无法访问系统资源 MySQL 不能访问启动需要的资源是造成而 MySQL 无法启动的一个常见原因 如 文件 端口等 由于 linux 中用于启动

大家好,我是讯享网,很高兴认识大家。

无法访问系统资源

MySQL 不能访问启动需要的资源是造成而 MySQL 无法启动的一个常见原因,如:文件,端口等。由于 linux 中用于启动 mysqld 进程的 mysql 用户通常是不能登陆的,可以使用类似下面的命令检查文件的访问权限。

 # sudo -u mysql touch /var/lib/mysql/b 

讯享网

找出问题后,修改对应文件或目录的权限或属主后通常可以解决问题。但有时 mysql 用户有访问文件和目录的权限,但仍然会被拒绝访问,例如下面这个例子:

讯享网mysql> system sudo -u mysql touch /home/mysql/data/a mysql> create table t1 (id int primary key,n varchar(10)) data directory='/home/mysql/data'; ERROR 1030 (HY000): Got error 168 from storage engine 
# mysqld --no-defaults --console --user mysql 2020-11-03T03:36:07.Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.19) starting as process 21171 2020-11-03T03:36:07.Z 1 [ERROR] [MY-012574] [InnoDB] Unable to lock ./ibdata1 error: 11 

这个故障产生的原因是另外一个 mysqld 进程已经启动并占用了对应的文件。


讯享网

参数设置错误

参数设置错误造成 MySQL 无法启动的原因也非常常见,此时先要检查 MySQL 启动时会调用的参数,下面的命令可以查询 MySQL 启动时调用参数文件的顺序:

讯享网$ mysqld --verbose --help | grep "Default options " -A 1 Default options are read from the following files in the given order: /etc/my.cnf /etc/mysql/my.cnf ~/.my.cnf 

知道了 MySQL 参数文件的调用顺序,我们就可以检查对应的参数文件,找出其中的错误,如果觉得参数文件的可读性不强,可以使用下面的命令显示 mysqld 程序将要调用的参数:

$ mysqld --print-defaults /usr/sbin/mysqld would have been started with the following arguments: ...... 
  1. 在 mysqld 后加上第一个参数–no-defaults ,这个参数的作用是通知 mysqld 在启动的时候不要读任何参数文件;
  2. 第二个参数是 --console,这个参数会把错误信息输出到屏幕上,这个参数带来的一个弊端是所有的信息都输出到屏幕上,让屏幕显得比较乱,但对于我们调试却是很方便的;
  3. 第三个参数是 --log-error-verbosity=3,这个参数会显示详细的日志;
  4. 然后再在后面加上有把握的参数,可以一次只加一个参数,然后启动 mysqld,采用排除法逐步找出错误的参数。

看这个例子:

讯享网root@scutech:~# mysqld --no-defaults --console --log-error-verbosity=3 --user mysql --gtid_mode=on 2020-11-03T07:14:20.Z 0 [Note] [MY-010949] [Server] Basedir set to /usr/. 2020-11-03T07:14:20.Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.19) starting as process 22617 2020-11-03T07:14:20.Z 0 [Note] [MY-012366] [InnoDB] Using Linux native AIO 2020-11-03T07:14:20.Z 0 [Note] [MY-010747] [Server] Plugin 'FEDERATED' is disabled. 2020-11-03T07:14:20.Z 1 [Note] [MY-012932] [InnoDB] PUNCH HOLE support available 2020-11-03T07:14:20.Z 1 [Note] [MY-012943] [InnoDB] Mutexes and rw_locks use GCC atomic builtins 2020-11-03T07:14:20.Z 1 [Note] [MY-012944] [InnoDB] Uses event mutexes 2020-11-03T07:14:20.Z 1 [Note] [MY-012945] [InnoDB] GCC builtin __atomic_thread_fence() is used for memory barrier 2020-11-03T07:14:20.Z 1 [Note] [MY-012948] [InnoDB] Compressed tables use zlib 1.2.11 2020-11-03T07:14:20.Z 1 [Note] [MY-013251] [InnoDB] Number of pools: 1 2020-11-03T07:14:20.Z 1 [Note] [MY-012951] [InnoDB] Using CPU crc32 instructions 2020-11-03T07:14:20.Z 1 [Note] [MY-012203] [InnoDB] Directories to scan './' 2020-11-03T07:14:20.Z 1 [Note] [MY-012204] [InnoDB] Scanning './' 2020-11-03T07:14:20.Z 1 [Note] [MY-012208] [InnoDB] Completed space ID check of 6 files. 2020-11-03T07:14:20.Z 1 [Note] [MY-012955] [InnoDB] Initializing buffer pool, total size = 128.000000M, instances = 1, chunk size =128.000000M 2020-11-03T07:14:20.Z 1 [Note] [MY-012957] [InnoDB] Completed initialization of buffer pool 2020-11-03T07:14:20.Z 0 [Note] [MY-011952] [InnoDB] If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man page of setpriority(). 2020-11-03T07:14:20.Z 1 [Note] [MY-013086] [InnoDB] Starting to parse redo log at lsn = , whereas checkpoint_lsn =  2020-11-03T07:14:20.Z 1 [Note] [MY-013083] [InnoDB] Log background threads are being started... 2020-11-03T07:14:20.Z 1 [Note] [MY-012532] [InnoDB] Applying a batch of 0 redo log records ... 2020-11-03T07:14:20.Z 1 [Note] [MY-012535] [InnoDB] Apply batch completed! 2020-11-03T07:14:20.Z 1 [Note] [MY-013252] [InnoDB] Using undo tablespace './undo_001'. 2020-11-03T07:14:20.Z 1 [Note] [MY-013252] [InnoDB] Using undo tablespace './undo_002'. 2020-11-03T07:14:20.Z 1 [Note] [MY-012910] [InnoDB] Opened 2 existing undo tablespaces. 2020-11-03T07:14:20.Z 1 [Note] [MY-011980] [InnoDB] GTID recovery trx_no:  2020-11-03T07:14:20.Z 1 [Note] [MY-012923] [InnoDB] Creating shared tablespace for temporary tables 2020-11-03T07:14:20.Z 1 [Note] [MY-012265] [InnoDB] Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ... 2020-11-03T07:14:20.Z 1 [Note] [MY-012266] [InnoDB] File './ibtmp1' size is now 12 MB. 2020-11-03T07:14:20.Z 1 [Note] [MY-011825] [InnoDB] Scanning temp tablespace dir:'./#innodb_temp/' 2020-11-03T07:14:21.Z 1 [Note] [MY-013018] [InnoDB] Created 128 and tracked 128 new rollback segment(s) in the temporary tablespace. 128 are now active. 2020-11-03T07:14:21.Z 1 [Note] [MY-012976] [InnoDB] 8.0.19 started; log sequence number  2020-11-03T07:14:21.Z 1 [Note] [MY-011089] [Server] Data dictionary restarting version '80017'. 2020-11-03T07:14:21.Z 1 [Note] [MY-012357] [InnoDB] Reading DD tablespace files 2020-11-03T07:14:21.Z 1 [ERROR] [MY-012657] [InnoDB] Encryption can't find master key, please check the keyring plugin is loaded. 2020-11-03T07:14:21.Z 1 [ERROR] [MY-012226] [InnoDB] Encryption information in datafile: ./b/t1.ibd can't be decrypted, please confirm the keyfile is match and keyring plugin is loaded. 2020-11-03T07:14:21.Z 1 [Note] [MY-012355] [InnoDB] Tablespace 34, name 'b/t1', unable to open file './b/t1.ibd' - Invalid encryption meta-data information 2020-11-03T07:14:21.Z 1 [Note] [MY-012356] [InnoDB] Validated 8/8 tablespaces 2020-11-03T07:14:21.Z 1 [Note] [MY-010006] [Server] Using data dictionary with version '80017'. 2020-11-03T07:14:21.Z 0 [Note] [MY-012487] [InnoDB] DDL log recovery : begin 2020-11-03T07:14:21.Z 0 [Note] [MY-012488] [InnoDB] DDL log recovery : end 2020-11-03T07:14:21.Z 0 [Note] [MY-011946] [InnoDB] Loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool 2020-11-03T07:14:21.Z 0 [Note] [MY-011946] [InnoDB] Buffer pool(s) load completed at  3:44:21 2020-11-03T07:14:21.Z 0 [ERROR] [MY-010912] [Server] GTID_MODE = ON requires ENFORCE_GTID_CONSISTENCY = ON. 2020-11-03T07:14:21.Z 0 [ERROR] [MY-010119] [Server] Aborting 2020-11-03T07:14:21.Z 0 [Note] [MY-012330] [InnoDB] FTS optimize thread exiting. 2020-11-03T07:14:21.Z 0 [Note] [MY-010120] [Server] Binlog end 2020-11-03T07:14:21.Z 0 [Note] [MY-010733] [Server] Shutting down plugin 'keyring_file' 2020-11-03T07:14:21.Z 0 [Note] [MY-010733] [Server] Shutting down plugin 'mysqlx_cache_cleaner' 2020-11-03T07:14:21.Z 0 [Note] [MY-010733] [Server] Shutting down plugin 'mysqlx' 2020-11-03T07:14:21.Z 0 [Note] [MY-010733] [Server] Shutting down plugin 'ngram' 2020-11-03T07:14:21.Z 0 [Note] [MY-010733] [Server] Shutting down plugin 'BLACKHOLE' 2020-11-03T07:14:21.Z 0 [Note] [MY-010733] [Server] Shutting down plugin 'ARCHIVE' 2020-11-03T07:14:21.Z 0 [Note] [MY-010733] [Server] Shutting down plugin 'TempTable' 2020-11-03T07:14:21.Z 0 [Note] [MY-010733] [Server] Shutting down plugin 'PERFORMANCE_SCHEMA' 2020-11-03T07:14:21.Z 0 [Note] [MY-010733] [Server] Shutting down plugin 'MRG_MYISAM' 2020-11-03T07:14:21.Z 0 [Note] [MY-010733] [Server] Shutting down plugin 'MyISAM' 2020-11-03T07:14:21.Z 0 [Note] [MY-010733] [Server] Shutting down plugin 'INNODB_SESSION_TEMP_TABLESPACES' 2020-11-03T07:14:21.Z 0 [Note] [MY-010733] [Server] Shutting down plugin 'INNODB_CACHED_INDEXES' 2020-11-03T07:14:21.Z 0 [Note] [MY-010733] [Server] Shutting down plugin 'INNODB_VIRTUAL' 2020-11-03T07:14:21.Z 0 [Note] [MY-010733] [Server] Shutting down plugin 'INNODB_COLUMNS' 2020-11-03T07:14:21.Z 0 [Note] [MY-010733] [Server] Shutting down plugin 'INNODB_TABLESPACES' 2020-11-03T07:14:21.Z 0 [Note] [MY-010733] [Server] Shutting down plugin 'INNODB_INDEXES' 2020-11-03T07:14:21.Z 0 [Note] [MY-010733] [Server] Shutting down plugin 'INNODB_TABLESTATS' 2020-11-03T07:14:21.Z 0 [Note] [MY-010733] [Server] Shutting down plugin 'INNODB_TABLES' 2020-11-03T07:14:21.Z 0 [Note] [MY-010733] [Server] Shutting down plugin 'INNODB_FT_INDEX_TABLE' 2020-11-03T07:14:21.Z 0 [Note] [MY-010733] [Server] Shutting down plugin 'INNODB_FT_INDEX_CACHE' 2020-11-03T07:14:21.Z 0 [Note] [MY-010733] [Server] Shutting down plugin 'INNODB_FT_CONFIG' 2020-11-03T07:14:21.Z 0 [Note] [MY-010733] [Server] Shutting down plugin 'INNODB_FT_BEING_DELETED' 2020-11-03T07:14:21.Z 0 [Note] [MY-010733] [Server] Shutting down plugin 'INNODB_FT_DELETED' 2020-11-03T07:14:21.Z 0 [Note] [MY-010733] [Server] Shutting down plugin 'INNODB_FT_DEFAULT_STOPWORD' 2020-11-03T07:14:21.Z 0 [Note] [MY-010733] [Server] Shutting down plugin 'INNODB_METRICS' 2020-11-03T07:14:21.Z 0 [Note] [MY-010733] [Server] Shutting down plugin 'INNODB_TEMP_TABLE_INFO' 2020-11-03T07:14:21.Z 0 [Note] [MY-010733] [Server] Shutting down plugin 'INNODB_BUFFER_POOL_STATS' 2020-11-03T07:14:21.Z 0 [Note] [MY-010733] [Server] Shutting down plugin 'INNODB_BUFFER_PAGE_LRU' 2020-11-03T07:14:21.Z 0 [Note] [MY-010733] [Server] Shutting down plugin 'INNODB_BUFFER_PAGE' 2020-11-03T07:14:21.Z 0 [Note] [MY-010733] [Server] Shutting down plugin 'INNODB_CMP_PER_INDEX_RESET' 2020-11-03T07:14:21.Z 0 [Note] [MY-010733] [Server] Shutting down plugin 'INNODB_CMP_PER_INDEX' 2020-11-03T07:14:21.Z 0 [Note] [MY-010733] [Server] Shutting down plugin 'INNODB_CMPMEM_RESET' 2020-11-03T07:14:21.Z 0 [Note] [MY-010733] [Server] Shutting down plugin 'INNODB_CMPMEM' 2020-11-03T07:14:21.Z 0 [Note] [MY-010733] [Server] Shutting down plugin 'INNODB_CMP_RESET' 2020-11-03T07:14:21.Z 0 [Note] [MY-010733] [Server] Shutting down plugin 'INNODB_CMP' 2020-11-03T07:14:21.Z 0 [Note] [MY-010733] [Server] Shutting down plugin 'INNODB_TRX' 2020-11-03T07:14:21.Z 0 [Note] [MY-010733] [Server] Shutting down plugin 'InnoDB' 2020-11-03T07:14:21.Z 0 [Note] [MY-013072] [InnoDB] Starting shutdown... 2020-11-03T07:14:21.Z 0 [Note] [MY-011944] [InnoDB] Dumping buffer pool(s) to /var/lib/mysql/ib_buffer_pool 2020-11-03T07:14:21.Z 0 [Note] [MY-011944] [InnoDB] Buffer pool(s) dump completed at  3:44:21 2020-11-03T07:14:22.Z 0 [Note] [MY-013084] [InnoDB] Log background threads are being closed... 2020-11-03T07:14:23.013239Z 0 [Note] [MY-012980] [InnoDB] Shutdown completed; log sequence number  2020-11-03T07:14:23.016772Z 0 [Note] [MY-012255] [InnoDB] Removed temporary tablespace data file: "ibtmp1" 2020-11-03T07:14:23.017200Z 0 [Note] [MY-010733] [Server] Shutting down plugin 'MEMORY' 2020-11-03T07:14:23.017777Z 0 [Note] [MY-010733] [Server] Shutting down plugin 'CSV' 2020-11-03T07:14:23.018155Z 0 [Note] [MY-010733] [Server] Shutting down plugin 'sha2_cache_cleaner' 2020-11-03T07:14:23.018492Z 0 [Note] [MY-010733] [Server] Shutting down plugin 'caching_sha2_password' 2020-11-03T07:14:23.018826Z 0 [Note] [MY-010733] [Server] Shutting down plugin 'sha256_password' 2020-11-03T07:14:23.019159Z 0 [Note] [MY-010733] [Server] Shutting down plugin 'mysql_native_password' 2020-11-03T07:14:23.025400Z 0 [Note] [MY-010733] [Server] Shutting down plugin 'binlog' 2020-11-03T07:14:23.026551Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.19) MySQL Community Server - GPL. root@scutech:~# 

看这个例子,我们很容易知道是需要我们同时设置参数 GTID_MODE 和 ENFORCE_GTID_CONSISTENCY 同时为 on 才行。

文章下方是我的微信,欢迎加我。👇

小讯
上一篇 2025-02-20 07:49
下一篇 2025-03-04 15:34

相关推荐

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容,请联系我们,一经查实,本站将立刻删除。
如需转载请保留出处:https://51itzy.com/kjqy/125428.html