前因:
今天星期六,上午正在逛市场,突然老板打电话来说服务器掉线了,刚开始以为只是普通问题,让自己联系机房就好了,先把服务器跑起来,让用户可以访问,一些自动化处理程序等我回去了再启动。
结果机房说服务器系统坏了,跑不起来,只能重新搭建服务
于是赶紧回家,让机房把硬盘挂到别的机器上,想办法把数据给弄出来
把旧硬盘挂到新机器后,开始了数据操作,一开始想的是把旧硬盘的MySQL跑起来,在用工具导出来就好了,结果MySQL跑不起来了。
由于新机器没有按照任何环境,无法直接使用systemctl start mysql
,新机器也没有MySQL的配置文件,于是另辟蹊径
1.找个新的配置文件(my.cnf) 放到 /etc/my.conf
(刚好旧硬盘里有之前的my.cnf文件)
2.进入MySQL的安装目录直接操作 ./mysql --defaults-file=/etc/my.cnf
(--defaults-file=/etc/my.cnf 指定启动的配置文件)
3.启动
报错
[root@xslmbllajezxnqw bin]# ./mysqld --defaults-file=/etc/my.cnf
2024-11-23T15:00:17.085523Z 0 [Warning] [MY-000081] [Server] option 'max_allowed_packet': unsigned value 107374182400 adjusted to 1073741824.
2024-11-23T15:00:17.085604Z 0 [Warning] [MY-010915] [Server] '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.
2024-11-23T15:00:17.085714Z 0 [System] [MY-010116] [Server] /data/www/server/mysql/bin/mysqld (mysqld 8.0.24) starting as process 31595
2024-11-23T15:00:17.099843Z 0 [ERROR] [MY-010123] [Server] Fatal error: Please read "Security" section of the manual to find out how to run mysqld as root!
2024-11-23T15:00:17.100066Z 0 [ERROR] [MY-010119] [Server] Aborting
2024-11-23T15:00:17.118879Z 0 [System] [MY-010910] [Server] /data/www/server/mysql/bin/mysqld: Shutdown complete (mysqld 8.0.24) Source distribution
注意报错信息同有个 Please read "Security" section of the manual to find out how to run mysqld as root!
提示,要求不能使用root用户启动
于是再创建一个账户useradd www
将MySQL的数据目录所有权更改为www
用户
再次启动./mysqld --defaults-file=/etc/my.cnf --user=www
[root@xslmbllajezxnqw bin]# ./mysqld --defaults-file=/etc/my.cnf --user=www
2024-11-23T07:48:47.965407Z 0 [Warning] [MY-000081] [Server] option 'max_allowed_packet': unsigned value 107374182400 adjusted to 1073741824.
2024-11-23T07:48:47.965490Z 0 [Warning] [MY-010915] [Server] '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.
2024-11-23T07:48:47.965601Z 0 [System] [MY-010116] [Server] /data/www/server/mysql/bin/mysqld (mysqld 8.0.24) starting as process 26261
2024-11-23T07:48:48.008578Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2024-11-23T07:48:54.506873Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2024-11-23T07:48:54.745099Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Bind-address: '::' port: 33060, socket: /tmp/mysqlx.sock
2024-11-23T07:48:55.075232Z 0 [Warning] [MY-013595] [Server] Failed to initialize TLS for channel: mysql_main. See below for the description of exact issue.
2024-11-23T07:48:55.075566Z 0 [Warning] [MY-010069] [Server] Failed to set up SSL because of the following SSL library error: <%.*s|%.*s
2024-11-23T07:48:55.138937Z 0 [Warning] [MY-011302] [Server] Plugin mysqlx reported: 'Failed at SSL configuration: "SSL context is not usable without certificate and private key"'
2024-11-23T07:48:55.139080Z 0 [System] [MY-010931] [Server] /data/www/server/mysql/bin/mysqld: ready for connections. Version: '8.0.24' socket: '/tmp/mysql.sock' port: 3306 Source distribution.
成功
只要MySQL跑起来,后面安装普遍流程来操作就可以了
- navcat
- mysqldump
用上面的任一都行
写这篇文章用时30分钟不到,按照我一开始的想法是对的,但实际解决这个问题搞了大半天,期间老板一直再问好了吗?
,搞得我快要爆炸了