暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

没有错误日志时如何排除MySQL启动故障

oracleace 2024-08-08
118

当 MySQL 服务器出现问题时,你的第一个反应可能是检查错误日志文件。然而,如果 MySQL 服务器因选项配置错误而无法启动,你可能在错误日志文件中找不到任何消息,因为甚至指定错误文件的选项可能都没有生效。

复制
    oracle@Yuan mysql$ sudo systemctl restart mysqld
    Job for mysqld.service failed because the control process exited with error code. See "systemctl status mysqld.service" and "journalctl -xe" for details.
    复制

    你可以手动检查 MySQL 配置文件以查找错误的选项,但一种更有效的方法是使用 --print-defaults 选项,让 MySQL 服务器守护进程(mysqld)列出它使用的选项,并在控制台上显示输出。

    下面是一个示例:

    复制
      oracle@Yuan mysql$ usr/sbin/mysqld --print-defaults
      /usr/sbin/mysqld would have been started with the following arguments:
      --innodb_redo_log_capacity=200M --innodb_print_ddl_logs=1 --log_slow_extra=ON --user=mysql --pid-file=/var/run/mysqld/mysqld.pid --socket=/var/run/mysqld/mysqld.sock --server-id=39 --port=3306 --basedir=/usr --datadir=/u01/mysql --tmpdir=/tmp --skip-name-resolve --default_time_zone=+8:00 --character-set-server=UTF8MB4 --innodb_buffer_pool_size=20G --innodb_buffer_pool_instances=8 --innodb_log_file_size=1G --innodb_io_capacity=5000 --innodb_io_capacity_max=10000 --innodb_open_files=65535 --innodb_flush_method=O_DIRECT --innodb_lock_wait_timeout=10 --innodb_rollback_on_timeout=1 --innodb_print_all_deadlocks=1 --innodb_status_output=0 --innodb_status_output_locks=1 --innodb_sort_buffer_size=67108864 --innodb_adaptive_hash_index=OFF --innodb_flush_log_at_trx_commit=1 --lock_wait_timeout=3600 --open_files_limit=65535 --back_log=1024 --max_connections=512 --max_connect_errors=1000000 --table_open_cache=10240 --table_definition_cache=10240 --thread_stack=512K --sort_buffer_size=8M --join_buffer_size=8M --read_buffer_size=16M --read_rnd_buffer_size=16M --bulk_insert_buffer_size=64M --thread_cache_size=768 --interactive_timeout=600 --wait_timeout=600 --tmp_table_size=96M --max_heap_table_size=96M --max_allowed_packet=128M --skip-innodb-adaptive-hash-index=1 --performance_schema_instrument=%memory%=on --performance_schema_instrument=%lock%=on --performance-schema-consumer-events-stages-history-long --log_error=/var/log/mysql/error.log --log_error_verbosity=2 --slow_query_log=1 --long_query_time=2 --expire_logs_days=30 --log_bin=on --sync_binlog=200 --binlog_format=ROW --binlog_rows_query_log_events=1 --master_info_repository=TABLE --relay_log_info_repository=TABLE --gtid_mode=on --enforce_gtid_consistency=1 --log_salve_updates --relay_log_recovery=1


      复制

      如果有许多选项,你仍然无法确定哪个选项是错误的,你可以将所有这些选项(除了 log_error
      )添加到启动 MySQL 服务器的命令中,这样任何错误输出都会显示在控制台上:

        oracle@Yuan mysql$ sudo mysqld --no-defaults --user mysql --innodb_redo_log_capacity=200M --innodb_print_ddl_logs=1 --log_slow_extra=ON --user=mysql --pid-file=/var/run/mysqld/mysqld.pid --socket=/var/run/mysqld/mysqld.sock --server-id=39 --port=3306 --basedir=/usr --datadir=/u01/mysql --tmpdir=/tmp --skip-name-resolve --default_time_zone=+8:00 --character-set-server=UTF8MB4 --innodb_buffer_pool_size=20G --innodb_buffer_pool_instances=8 --innodb_log_file_size=1G --innodb_io_capacity=5000 --innodb_io_capacity_max=10000 --innodb_open_files=65535 --innodb_flush_method=O_DIRECT --innodb_lock_wait_timeout=10 --innodb_rollback_on_timeout=1 --innodb_print_all_deadlocks=1 --innodb_status_output=0 --innodb_status_output_locks=1 --innodb_sort_buffer_size=67108864 --innodb_adaptive_hash_index=OFF --innodb_flush_log_at_trx_commit=1 --lock_wait_timeout=3600 --open_files_limit=65535 --back_log=1024 --max_connections=512 --max_connect_errors=1000000 --table_open_cache=10240 --table_definition_cache=10240 --thread_stack=512K --sort_buffer_size=8M --join_buffer_size=8M --read_buffer_size=16M --read_rnd_buffer_size=16M --bulk_insert_buffer_size=64M --thread_cache_size=768 --interactive_timeout=600 --wait_timeout=600 --tmp_table_size=96M --max_heap_table_size=96M --max_allowed_packet=128M --skip-innodb-adaptive-hash-index=1 --performance_schema_instrument=%memory%=on --performance_schema_instrument=%lock%=on --performance-schema-consumer-events-stages-history-long   --log_error_verbosity=2 --slow_query_log=1 --long_query_time=2 --expire_logs_days=30 --log_bin=on --sync_binlog=200 --binlog_format=ROW --binlog_rows_query_log_events=1 --master_info_repository=TABLE --relay_log_info_repository=TABLE --gtid_mode=on --enforce_gtid_consistency=1 --log_salve_updates --relay_log_recovery=1
        2024-08-07T02:56:39.118864Z 0 [Warning] [MY-011068] [Server] The syntax 'expire-logs-days' is deprecated and will be removed in a future release. Please use binlog_expire_logs_seconds instead.
        2024-08-07T02:56:39.118895Z 0 [Warning] [MY-011069] [Server] The syntax '--master-info-repository' is deprecated and will be removed in a future release.
        2024-08-07T02:56:39.118907Z 0 [Warning] [MY-011069] [Server] The syntax '--relay-log-info-repository' is deprecated and will be removed in a future release.
        2024-08-07T02:56:39.122585Z 0 [System] [MY-010116] [Server] usr/sbin/mysqld (mysqld 8.0.31) starting as process 56667
        2024-08-07T02:56:39.131240Z 0 [Warning] [MY-013869] [InnoDB] Ignored deprecated configuration parameter innodb_log_file_size. Used innodb_redo_log_capacity instead.
        2024-08-07T02:56:39.134288Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
        2024-08-07T02:56:41.511535Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
        2024-08-07T02:56:41.907107Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
        2024-08-07T02:56:41.907183Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel.
        2024-08-07T02:56:41.910645Z 0 [ERROR] [MY-000068] [Server] unknown option '--log_salve_updates'.
        2024-08-07T02:56:41.910721Z 0 [ERROR] [MY-010119] [Server] Aborting
        2024-08-07T02:56:43.949602Z 0 [System] [MY-010910] [Server] usr/sbin/mysqld: Shutdown complete (mysqld 8.0.31) MySQL Community Server - GPL.


        复制

        输出显示 unknown option '--log_salve_updates'
        ,显然是一个拼写错误。

        说明:在Windows 平台上需要使用 --console
        选项将错误日志输出到屏幕,Linux平台不用这个选项。

        即使所有选项都正确,MySQL 服务器也可能因为这些选项之间的不正确关系而无法启动。在这种情况下,你可以通过逐步排除的方法来找到错误,即逐步输入部分选项并多次尝试。

        关于号主,姚远:

        • Oracle ACE(Oracle和MySQL数据库方向)

        • 华为云最有价值专家

        • 《MySQL 8.0运维与优化》的作者

        • 拥有 Oracle 10g、12c和19c OCM等数十项数据库认证

        • 曾任IBM公司数据库部门经理

        • 20+年DBA经验,服务2万+客户

        • 精通C和Java,发明两项计算机专利


        号主在certview.oracle.com网站上的证书截图:

        欢迎关注我的公众号,一起学习数据库技术

        欢迎加我的微信,拉你进数据库微信群

        推荐文章👇

        国外的程序员没有35岁魔咒吗?

        试看号主的拙作《MySQL 8.0运维与优化》(清华大学出版社)

        托业890分的Oracle ACE为您翻译国际大佬的雄文(合集)

        又考了一个Oracle优化的OCP,交一下作业

        一个计算机工程师如何达到英语专业八级的水平

        学好Oracle只需要看一本书就够了?


        文章转载自oracleace,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

        评论