描述

Linux主机安装MySQL 5.6.51后,无法正常启动。经排查,发现与deb安装的MySQL 8.0.40冲突导致,下面是问题处理过程,以及通过mysql命令连接数据库异常问题的处理。

安装信息

安装参考

mysql 5.6 linux安装配置_linux手动安装配置mysql5.6

安装命令

./scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/

安装目录:/usr/local/mysql

root@swift:/usr/local/mysql# ls
bin  data  docs  include  lib  LICENSE  man  my.cnf  my-new.cnf  mysql.log  mysql-test  README  scripts  share  sql-bench  support-files

启动报错/usr/local/mysql/support-files/mysql.server start

2024-11-13 12:18:52 569792 [Note] Plugin 'FEDERATED' is disabled.
2024-11-13 12:18:52 569792 [Note] InnoDB: Using atomics to ref count buffer pool pages
2024-11-13 12:18:52 569792 [Note] InnoDB: The InnoDB memory heap is disabled
2024-11-13 12:18:52 569792 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2024-11-13 12:18:52 569792 [Note] InnoDB: Memory barrier is not used
2024-11-13 12:18:52 569792 [Note] InnoDB: Compressed tables use zlib 1.2.11
2024-11-13 12:18:52 569792 [Note] InnoDB: Using Linux native AIO
2024-11-13 12:18:52 569792 [Note] InnoDB: Using CPU crc32 instructions
2024-11-13 12:18:52 569792 [Note] InnoDB: Initializing buffer pool, size = 16.0G
2024-11-13 12:18:52 569792 [Note] InnoDB: Completed initialization of buffer pool
2024-11-13 12:18:52 569792 [Note] InnoDB: Highest supported file format is Barracuda.
2024-11-13 12:18:52 569792 [Note] InnoDB: 128 rollback segment(s) are active.
2024-11-13 12:18:52 569792 [Note] InnoDB: Waiting for purge to start
2024-11-13 12:18:52 569792 [Note] InnoDB: 5.6.51 started; log sequence number 1627158
2024-11-13 12:18:52 569792 [ERROR] /usr/local/mysql/bin/mysqld: unknown variable 'mysqlx-bind-address=127.0.0.1'
2024-11-13 12:18:52 569792 [ERROR] Aborting

2024-11-13 12:18:52 569792 [Note] Binlog end
2024-11-13 12:18:52 569792 [Note] Shutting down plugin 'partition'
2024-11-13 12:18:52 569792 [Note] Shutting down plugin 'PERFORMANCE_SCHEMA'
2024-11-13 12:18:52 569792 [Note] Shutting down plugin 'INNODB_SYS_DATAFILES'
2024-11-13 12:18:52 569792 [Note] Shutting down plugin 'INNODB_SYS_TABLESPACES'
2024-11-13 12:18:52 569792 [Note] Shutting down plugin 'INNODB_SYS_FOREIGN_COLS'
2024-11-13 12:18:52 569792 [Note] Shutting down plugin 'INNODB_SYS_FOREIGN'
2024-11-13 12:18:52 569792 [Note] Shutting down plugin 'INNODB_SYS_FIELDS'
2024-11-13 12:18:52 569792 [Note] Shutting down plugin 'INNODB_SYS_COLUMNS'
2024-11-13 12:18:52 569792 [Note] Shutting down plugin 'INNODB_SYS_INDEXES'
2024-11-13 12:18:52 569792 [Note] Shutting down plugin 'INNODB_SYS_TABLESTATS'
2024-11-13 12:18:52 569792 [Note] Shutting down plugin 'INNODB_SYS_TABLES'
2024-11-13 12:18:52 569792 [Note] Shutting down plugin 'INNODB_FT_INDEX_TABLE'
2024-11-13 12:18:52 569792 [Note] Shutting down plugin 'INNODB_FT_INDEX_CACHE'
2024-11-13 12:18:52 569792 [Note] Shutting down plugin 'INNODB_FT_CONFIG'
2024-11-13 12:18:52 569792 [Note] Shutting down plugin 'INNODB_FT_BEING_DELETED'
2024-11-13 12:18:52 569792 [Note] Shutting down plugin 'INNODB_FT_DELETED'
2024-11-13 12:18:52 569792 [Note] Shutting down plugin 'INNODB_FT_DEFAULT_STOPWORD'
2024-11-13 12:18:52 569792 [Note] Shutting down plugin 'INNODB_METRICS'
2024-11-13 12:18:52 569792 [Note] Shutting down plugin 'INNODB_BUFFER_POOL_STATS'
2024-11-13 12:18:52 569792 [Note] Shutting down plugin 'INNODB_BUFFER_PAGE_LRU'
2024-11-13 12:18:52 569792 [Note] Shutting down plugin 'INNODB_BUFFER_PAGE'
2024-11-13 12:18:52 569792 [Note] Shutting down plugin 'INNODB_CMP_PER_INDEX_RESET'
2024-11-13 12:18:52 569792 [Note] Shutting down plugin 'INNODB_CMP_PER_INDEX'
2024-11-13 12:18:52 569792 [Note] Shutting down plugin 'INNODB_CMPMEM_RESET'
2024-11-13 12:18:52 569792 [Note] Shutting down plugin 'INNODB_CMPMEM'
2024-11-13 12:18:52 569792 [Note] Shutting down plugin 'INNODB_CMP_RESET'
2024-11-13 12:18:52 569792 [Note] Shutting down plugin 'INNODB_CMP'
2024-11-13 12:18:52 569792 [Note] Shutting down plugin 'INNODB_LOCK_WAITS'
2024-11-13 12:18:52 569792 [Note] Shutting down plugin 'INNODB_LOCKS'
2024-11-13 12:18:52 569792 [Note] Shutting down plugin 'INNODB_TRX'
2024-11-13 12:18:52 569792 [Note] Shutting down plugin 'InnoDB'
2024-11-13 12:18:52 569792 [Note] InnoDB: FTS optimize thread exiting.
2024-11-13 12:18:52 569792 [Note] InnoDB: Starting shutdown...
2024-11-13 12:18:55 569792 [Note] InnoDB: Shutdown completed; log sequence number 1627168
2024-11-13 12:18:55 569792 [Note] Shutting down plugin 'BLACKHOLE'
2024-11-13 12:18:55 569792 [Note] Shutting down plugin 'ARCHIVE'
2024-11-13 12:18:55 569792 [Note] Shutting down plugin 'MRG_MYISAM'
2024-11-13 12:18:55 569792 [Note] Shutting down plugin 'MyISAM'
2024-11-13 12:18:55 569792 [Note] Shutting down plugin 'MEMORY'
2024-11-13 12:18:55 569792 [Note] Shutting down plugin 'CSV'
2024-11-13 12:18:55 569792 [Note] Shutting down plugin 'sha256_password'
2024-11-13 12:18:55 569792 [Note] Shutting down plugin 'mysql_old_password'
2024-11-13 12:18:55 569792 [Note] Shutting down plugin 'mysql_native_password'
2024-11-13 12:18:55 569792 [Note] Shutting down plugin 'binlog'
2024-11-13 12:18:55 569792 [Note] /usr/local/mysql/bin/mysqld: Shutdown complete

关键信息

/usr/local/mysql/bin/mysqld: unknown variable 'mysqlx-bind-address=127.0.0.1'

排查

检查环境,存在deb安装的MySQL 8.0.40

root@swift:/usr/local/mysql# dpkg -l | grep mysql
ii  mysql-client-8.0                           8.0.40-0ubuntu0.22.04.1                 amd64        MySQL database client binaries
ii  mysql-client-core-8.0                      8.0.40-0ubuntu0.22.04.1                 amd64        MySQL database core client binaries
ii  mysql-common                               5.8+1.0.8                               all          MySQL database common files, e.g. /etc/mysql/my.cnf
ii  mysql-server                               8.0.40-0ubuntu0.22.04.1                 all          MySQL database server (metapackage depending on the latest version)
ii  mysql-server-8.0                           8.0.40-0ubuntu0.22.04.1                 amd64        MySQL database server binaries and system database setup
ii  mysql-server-core-8.0                      8.0.40-0ubuntu0.22.04.1                 amd64        MySQL database server binaries

可能存在冲突

查看配置文件 my.cnf 中并没有配置 mysqlx-bind-address=127.0.0.1

当前目录/usr/local/mysql下中没有该配置

跟踪启动脚本bash -x support-files/mysql.server start,获取到

+ test -r /usr/local/mysql/my.cnf
+ extra_args='-e /usr/local/mysql/my.cnf'
++ /usr/local/mysql/bin/my_print_defaults -e /usr/local/mysql/my.cnf mysqld server mysql_server mysql.server
+ parse_server_arguments --user=mysql --bind-address=127.0.0.1 --mysqlx-bind-address=127.0.0.1 --key_buffer_size=16M --myisam-recover-options=BACKUP --log_error=/var/log/mysql/error.log --max_binlog_size=100M --default-time_zone=+8:00 --default_storage_engine=InnoDB --character_set_server=utf8mb4 --collation_server=utf8mb4_general_ci --server_id=80 --log_bin=mysql_bin --expire_logs_days=30 --binlog_format=STATEMENT --max_binlog_size=1073741824 --sync_binlog=0 --datadir=/usr/local/mysql/data --symbolic-links=0 --sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES --event_scheduler=ON --max_connections=600 --innodb_buffer_pool_size=16G --max_connect_errors=1000 --join_buffer_size=2M --sort_buffer_size=512k --read_rnd_buffer_size=512k --thread_cache_size=50 --innodb_log_file_size=8G --innodb_buffer_pool_instances=24 --slow_query_log=on --slow_query_log_file=/usr/local/mysql/ --long_query_time=4 --log-queries-not-using-indexes=true --table_definition_cache=20000 --innodb_open_files=20000 --table_open_cache=20000 --read_buffer_size=1M --max_allowed_packet=209715200 --net_read_timeout=28800 --net_write_timeout=28800

手动执行 /usr/local/mysql/bin/my_print_defaults -e /usr/local/mysql/my.cnf mysqld server mysql_server mysql.server查看配置

root@swift:/usr/local/mysql# /usr/local/mysql/bin/my_print_defaults -e /usr/local/mysql/my.cnf mysqld server mysql_server mysql.server
--user=mysql
--bind-address=127.0.0.1
--mysqlx-bind-address=127.0.0.1
--key_buffer_size=16M
--myisam-recover-options=BACKUP
--log_error=/var/log/mysql/error.log
--max_binlog_size=100M
--default-time_zone=+8:00
--default_storage_engine=InnoDB
--character_set_server=utf8mb4
--collation_server=utf8mb4_general_ci
--server_id=80
--log_bin=mysql_bin
--expire_logs_days=30
--binlog_format=STATEMENT
--max_binlog_size=1073741824
--sync_binlog=0
--datadir=/usr/local/mysql/data
--symbolic-links=0
--sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
--event_scheduler=ON
--max_connections=600
--innodb_buffer_pool_size=16G
--max_connect_errors=1000
--join_buffer_size=2M
--sort_buffer_size=512k
--read_rnd_buffer_size=512k
--thread_cache_size=50
--innodb_log_file_size=8G
--innodb_buffer_pool_instances=24
--slow_query_log=on
--slow_query_log_file=/usr/local/mysql/
--long_query_time=4
--log-queries-not-using-indexes=true
--table_definition_cache=20000
--innodb_open_files=20000
--table_open_cache=20000
--read_buffer_size=1M
--max_allowed_packet=209715200
--net_read_timeout=28800
--net_write_timeout=28800

找到配置--mysqlx-bind-address=127.0.0.1的出处,然后处理,成功启动安装的mysql 5.6.51

连接数据库失败问题处理

直接运行mysql命令,提示无法找到sock文件

root@swift:/usr/local/mysql# mysql
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

# 查看mysql版本
root@swift:/usr/local/mysql# mysql --help
mysql  Ver 8.0.40-0ubuntu0.22.04.1 for Linux on x86_64 ((Ubuntu))

# 查看可执行文件位置
root@swift:/usr/local/mysql# which mysql
/usr/bin/mysql

异常原因:

使用的mysql命令是通过deb安装的MySQL 8.0.40版本,默认配置和安装的MySQL 5.6.51中的/usr/local/mysql/bin/mysql 不一致,8.0.40默认使用的sock文件为 /var/run/mysqld/mysqld.sock,而5.6.51使用的sock文件是/tmp/mysql.sock

这里的报错是因为deb安装的MySQL 8.0.40数据库没有启动导致,服务没有启动,没有socket文件,所以提示无法连接。

如果想要使用默认的这个mysql命令,连接MySQL 5.6.51,可以通过手动指定socket文件,来进行连接。

解决方法

如果使用8.0.40的mysql可执行文件连接新启动的5.6.51,提示无sock文件,查看新启动的5.6.51的sock文件在哪里,手动指定后可进入

root@swift:/usr/local/mysql# mysql -S /tmp/mysql.sock
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.51-log MySQL Community Server (GPL)

Copyright (c) 2000, 2024, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> exit
Bye
root@swift:/usr/local/mysql#

查找手动安装的mysql的sock文件位置配置

root@swift:/usr/local/mysql# grep '\.sock' * -R
bin/mysql_config:socket='/tmp/mysql.sock'

配置位于 bin/mysql_config 文件中定义的

version='5.6.51'
socket='/tmp/mysql.sock'

查看sock文件,文件存在

root@swift:/usr/local/mysql# ls /tmp/mysql.sock
/tmp/mysql.sock
root@swift:/usr/local/mysql# file /tmp/mysql.sock
/tmp/mysql.sock: socket

指定该sock文件,可正常进入

使用Mysql 5.6.51安装目录下的mysql客户端连接mysql数据库报错

root@swift:/usr/local/mysql/bin# ./mysql --help
./mysql: error while loading shared libraries: libncurses.so.5: cannot open shared object file: No such file or directory

依赖库有问题,缺失。

查看lib库

root@swift:/usr/local/mysql/bin# ldd mysql
        linux-vdso.so.1 (0x00007ffce315e000)
        libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007ee58cb4b000)
        librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007ee58cb46000)
        libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007ee58cb41000)
        libncurses.so.5 => not found
        libstdc++.so.6 => /lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007ee58c800000)
        libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007ee58ca58000)
        libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007ee58ca38000)
        libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007ee58c400000)
        /lib64/ld-linux-x86-64.so.2 (0x00007ee58cb62000)
        libtinfo.so.5 => not found

可以看到,缺少 libncurses.so.5 库文件

处理,安装libncurses5即可

apt install libncurses5

安装后可正常进入

root@swift:/usr/local/mysql/bin# ./mysql -u swift
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 5.6.51-log MySQL Community Server (GPL)

Copyright (c) 2000, 2021, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

Linux下多版本MySQL共存时配置环境变量PATH指定默认版本

两个版本的mysql,配置/usr/local/mysql/bin下的优先,默认使用5.6.51版本,因为默认sock文件位置不同。

编辑/etc/profile,新增

# mysql
PATH=/usr/local/mysql/bin:$PATH
export PATH

加载

source /etc/profile

查看mysql命令路径

swift@swift:/usr/local/mysql/bin$ which mysql
/usr/local/mysql/bin/mysql
swift@swift:/usr/local/mysql/bin$ which -a mysql
/usr/local/mysql/bin/mysql
/usr/bin/mysql
/bin/mysql

可以直接mysql命令直接连接MySQL 5.6.51

标签: 问题记录, MySQL

添加新评论