新安装的kali系统,想用docker环境走lamp服务,结果搞了好久都没办法正常,没办法,只有使用系统配置lamp服务,结果发现mysql无法启动,只能一步一步解决!

 

hya@hopiron-3650:~$ systemctl status mysql.service
● mysql.service - MySQL Community Server
   Loaded: loaded (/lib/systemd/system/mysql.service; disabled; vendor preset: d
   Active: failed (Result: exit-code) since Thu 2019-08-29 03:30:54 EDT; 34s ago
  Process: 30256 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=exi
lines 1-4/4 (END)...skipping...
● mysql.service - MySQL Community Server
   Loaded: loaded (/lib/systemd/system/mysql.service; disabled; vendor preset: disabled)
   Active: failed (Result: exit-code) since Thu 2019-08-29 03:30:54 EDT; 34s ago
  Process: 30256 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=exited, status=1/FAILURE)
~


hya@hopiron-3650:~$ /usr/share/mysql/mysql-systemd-start pre
MySQL system database not found in /var/lib/mysql. Please run mysqld --initialize.

hya@hopiron-3650:~$ mysqld --initialize
bash: mysqld:未找到命令

hya@hopiron-3650:~$ sudo mysqld --initialize
[sudo] hya 的密码:
2019-08-29T07:33:50.610970Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2019-08-29T07:33:52.826819Z 0 [Warning] InnoDB: New log files created, LSN=45790
2019-08-29T07:33:53.251437Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2019-08-29T07:33:53.478517Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 5a1008e1-ca2f-11e9-8271-484d7ea8929d.
2019-08-29T07:33:53.511502Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2019-08-29T07:33:53.532813Z 1 [Note] A temporary password is generated for root@localhost: ZrNDn4r1>rgR

#记下密码

hya@hopiron-3650:~$sudo service mysql start #依然报错

hya@hopiron-3650:~$ systemctl status mysql.service #重复执行找到问题

● mysql.service - MySQL Community Server
   Loaded: loaded (/lib/systemd/system/mysql.service; disabled; vendor preset: d
   Active: failed (Result: exit-code) since Thu 2019-08-29 03:30:54 EDT; 34s ago
  Process: 30256 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=exi
lines 1-4/4 (END)...skipping...
● mysql.service - MySQL Community Server
   Loaded: loaded (/lib/systemd/system/mysql.service; disabled; vendor preset: disabled)
   Active: failed (Result: exit-code) since Thu 2019-08-29 03:30:54 EDT; 34s ago
  Process: 30256 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=exited, status=1/FAILURE)
  Process: 30256 ExecStartPre=/usr/sbin/mysqld --daemonize --pid-file=/run/mysqld/mysqld.pid 
 
#直接执行ExecStartPre里面的语句

hya@hopiron-3650:~$ sudo /usr/sbin/mysqld --daemonize --pid-file=/run/mysqld/mysqld.pid
Please enable --log-error option or set appropriate redirections for standard output and/or standard error in daemon mode.

hya@hopiron-3650:~$ sudo /usr/sbin/mysqld --daemonize --pid-file=/run/mysqld/mysqld.pid --log-error
2019-08-29T08:19:22.623131Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2019-08-29T08:19:22.623946Z 0 [Warning] Insecure configuration for --secure-file-priv: Location is accessible to all OS users. Consider choosing a different directory.
2019-08-29T08:19:22.623977Z 0 [Note] /usr/sbin/mysqld (mysqld 5.7.21-1) starting as process 5444 ...
2019-08-29T08:19:22.624919Z 0 [ERROR] Fatal error: Please read "Security" section of the manual to find out how to run mysqld as root!

2019-08-29T08:19:22.624958Z 0 [ERROR] Aborting

2019-08-29T08:19:22.624994Z 0 [Note] Binlog end
Initialization of mysqld failed: 0
2019-08-29T08:19:22.625063Z 0 [Note] /usr/sbin/mysqld: Shutdown complete

#尝试以mysql用户进行启动mysql服务
hya@hopiron-3650:~$ sudo /usr/sbin/mysqld --daemonize --pid-file=/run/mysqld/mysqld.pid --log-error --user=mysql
2019-08-29T08:23:35.982165Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2019-08-29T08:23:35.982878Z 0 [Warning] Insecure configuration for --secure-file-priv: Location is accessible to all OS users. Consider choosing a different directory.
2019-08-29T08:23:35.982906Z 0 [Note] /usr/sbin/mysqld (mysqld 5.7.21-1) starting as process 6305 ...
2019-08-29T08:23:35.985337Z 0 [ERROR] Could not open file '/run/mysqld/mysqld.err' for error logging: No such file or directory
2019-08-29T08:23:35.985369Z 0 [ERROR] Aborting

2019-08-29T08:23:35.985420Z 0 [Note] Binlog end
Initialization of mysqld failed: 0
2019-08-29T08:23:35.985515Z 0 [Note] /usr/sbin/mysqld: Shutdown complete

#明显是没有/run/mysqld目录,执行以下语句
sudo mkdri /run/mysqld &&sudo  chown mysql:mysql /run/mysqld

#再启动mysql,依然报错,尝试查看刚才创建目录的错误信息

hya@hopiron-3650:~$ sudo cat /run/mysqld/mysqld.err 
2019-08-29T08:24:45.781961Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2019-08-29T08:24:45.783190Z 0 [Warning] Insecure configuration for --secure-file-priv: Location is accessible to all OS users. Consider choosing a different directory.
2019-08-29T08:24:45.783221Z 0 [Note] /usr/sbin/mysqld (mysqld 5.7.21-1) starting as process 6367 ...
2019-08-29T08:24:45.786829Z 0 [Note] InnoDB: PUNCH HOLE support available
2019-08-29T08:24:45.786842Z 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2019-08-29T08:24:45.786845Z 0 [Note] InnoDB: Uses event mutexes
2019-08-29T08:24:45.786847Z 0 [Note] InnoDB: GCC builtin __atomic_thread_fence() is used for memory barrier
2019-08-29T08:24:45.786849Z 0 [Note] InnoDB: Compressed tables use zlib 1.2.8
2019-08-29T08:24:45.786851Z 0 [Note] InnoDB: Using Linux native AIO
2019-08-29T08:24:45.787398Z 0 [Note] InnoDB: Number of pools: 1
2019-08-29T08:24:45.787482Z 0 [Note] InnoDB: Using CPU crc32 instructions
2019-08-29T08:24:45.788616Z 0 [Note] InnoDB: Initializing buffer pool, total size = 128M, instances = 1, chunk size = 128M
2019-08-29T08:24:45.794369Z 0 [Note] InnoDB: Completed initialization of buffer pool
2019-08-29T08:24:45.796193Z 0 [Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man page of setpriority().
2019-08-29T08:24:45.806170Z 0 [ERROR] InnoDB: The innodb_system data file 'ibdata1' must be writable
2019-08-29T08:24:45.806200Z 0 [ERROR] InnoDB: The innodb_system data file 'ibdata1' must be writable
2019-08-29T08:24:45.806209Z 0 [ERROR] InnoDB: Plugin initialization aborted with error Generic error
2019-08-29T08:24:46.407044Z 0 [ERROR] Plugin 'InnoDB' init function returned error.
2019-08-29T08:24:46.407079Z 0 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
2019-08-29T08:24:46.407090Z 0 [ERROR] Failed to initialize builtin plugins.
2019-08-29T08:24:46.407096Z 0 [ERROR] Aborting

2019-08-29T08:24:46.407133Z 0 [Note] Binlog end
2019-08-29T08:24:46.407229Z 0 [Note] Shutting down plugin 'CSV'
2019-08-29T08:24:46.407737Z 0 [Note] /usr/sbin/mysqld: Shutdown complete

#明显是mysql数据库目录没有权限


hya@hopiron-3650:~$ sudo chmod 777 -R /var/lib/mysql

#再次启动mysql,终于可以了,密码为sudo mysqld --initialize时最后提示的密码

总结:不知道是什么原因,导致mysql服务数据库、及必须的文件夹已经丢失,一步一步找到原因并重新初始化mysql数据库文件,并创建mysql必须的文件夹,重新修复并启动mysql

 

Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐