Database error
–Error connecting to database: Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’ (2)
报错截图如下:
解决方法:
报错信息说是连接不上数据库,我们先看下数据的状态,
使用命令:systemctl status mariadb
如下信息:
[root@linux7 ~]# systemctl status mariadb
● mariadb.service - MariaDB database server
Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; vendor preset: disabled)
Active: inactive (dead) since 六 2020-03-07 08:46:43 CST; 2min 28s ago
Process: 4078 ExecStart=/usr/bin/mysqld_safe --basedir=/usr (code=exited, status=0/SUCCESS)
Main PID: 4078 (code=exited, status=0/SUCCESS)
3月 07 08:35:12 linux7.7oracle12.2 systemd[1]: Starting MariaDB database server…
3月 07 08:35:13 linux7.7oracle12.2 mariadb-prepare-db-dir[4044]: Database MariaDB is probably initialize…e.
3月 07 08:35:13 linux7.7oracle12.2 mariadb-prepare-db-dir[4044]: If this is not the case, make sure the …r.
3月 07 08:35:13 linux7.7oracle12.2 mysqld_safe[4078]: 200307 08:35:13 mysqld_safe Logging to ‘/var/log/…g’.
3月 07 08:35:13 linux7.7oracle12.2 mysqld_safe[4078]: 200307 08:35:13 mysqld_safe Starting mysqld daemo…sql
3月 07 08:35:19 linux7.7oracle12.2 systemd[1]: Started MariaDB database server.
3月 07 08:46:42 linux7.7oracle12.2 systemd[1]: Stopping MariaDB database server…
3月 07 08:46:43 linux7.7oracle12.2 systemd[1]: Stopped MariaDB database server.
Hint: Some lines were ellipsized, use -l to show in full.
结论:发现数据库状态是inactive (dead),尝试启动数据库。
[root@linux7 ~]# systemctl start mariadb
[root@linux7 ~]# systemctl status mariadb
● mariadb.service - MariaDB database server
Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; vendor preset: disabled)
Active: active (running) since 六 2020-03-07 08:52:22 CST; 4s ago
Process: 5609 ExecStartPost=/usr/libexec/mariadb-wait-ready $MAINPID (code=exited, status=0/SUCCESS)
Process: 5575 ExecStartPre=/usr/libexec/mariadb-prepare-db-dir %n (code=exited, status=0/SUCCESS)
Main PID: 5607 (mysqld_safe)
Tasks: 32
CGroup: /system.slice/mariadb.service
├─5607 /bin/sh /usr/bin/mysqld_safe --basedir=/usr
└─5770 /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql…
3月 07 08:52:20 linux7.7oracle12.2 systemd[1]: Starting MariaDB database server…
3月 07 08:52:20 linux7.7oracle12.2 mariadb-prepare-db-dir[5575]: Database MariaDB is probably initialize…e.
3月 07 08:52:20 linux7.7oracle12.2 mariadb-prepare-db-dir[5575]: If this is not the case, make sure the …r.
3月 07 08:52:21 linux7.7oracle12.2 mysqld_safe[5607]: 200307 08:52:21 mysqld_safe Logging to ‘/var/log/…g’.
3月 07 08:52:21 linux7.7oracle12.2 mysqld_safe[5607]: 200307 08:52:21 mysqld_safe Starting mysqld daemo…sql
3月 07 08:52:22 linux7.7oracle12.2 systemd[1]: Started MariaDB database server.
Hint: Some lines were ellipsized, use -l to show in full.
刷新zabbix页面,发现已经可以打开了,问题解决。