我刚刚从 debian repo 安装了 MariaDB,但无法启动它。
root@Debian9A1:~$ mysql
ERROR 2002 (HY000): Can't connect to local MySQL server through socket'/var/run/mysqld/mysqld.sock' (2)
我尝试启动该服务,但没有成功:
root@Debian9A1:/var/log/mysql# systemctl start mariadb
Job for mariadb.service failed because the control process exited with error code.
See "systemctl status mariadb.service" and "journalctl -xe" for details.
服务状态无用:
root@Debian9A1:/var/log/mysql# systemctl status mariadb.service
● mariadb.service - MariaDB 10.3.15 database server
Loaded: loaded (/lib/systemd/system/mariadb.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Mon 2019-07-22 16:28:51 CEST; 24s ago
Docs: man:mysqld(8)
https://mariadb.com/kb/en/library/systemd/
Process: 3987 ExecStartPre=/usr/bin/install -m 755 -o mysql -g root -d /var/run/mysqld (code=exit
juil. 22 16:28:51 Debian9A1 systemd[1]: Starting MariaDB 10.3.15 database server...
juil. 22 16:28:51 Debian9A1 systemd[1]: mariadb.service: Control process exited, code=exited status
juil. 22 16:28:51 Debian9A1 systemd[1]: Failed to start MariaDB 10.3.15 database server.
juil. 22 16:28:51 Debian9A1 systemd[1]: mariadb.service: Unit entered failed state.
juil. 22 16:28:51 Debian9A1 systemd[1]: mariadb.service: Failed with result 'exit-code'.
journalctl 也不是:
root@Debian9A1:/var/log/mysql# journalctl -xe
[...]
juil. 22 16:28:51 Debian9A1 systemd[1]: Starting MariaDB 10.3.15 database server...
-- Subject: L'unité (unit) mariadb.service a commencé à démarrer
-- Defined-By: systemd
-- Support: https://www.debian.org/support
--
-- L'unité (unit) mariadb.service a commencé à démarrer.
juil. 22 16:28:51 Debian9A1 systemd[1]: mariadb.service: Control process exited, code=exited status=127
juil. 22 16:28:51 Debian9A1 systemd[1]: Failed to start MariaDB 10.3.15 database server.
-- Subject: L'unité (unit) mariadb.service a échoué
-- Defined-By: systemd
-- Support: https://www.debian.org/support
--
-- L'unité (unit) mariadb.service a échoué, avec le résultat failed.
juil. 22 16:28:51 Debian9A1 systemd[1]: mariadb.service: Unit entered failed state.
juil. 22 16:28:51 Debian9A1 systemd[1]: mariadb.service: Failed with result 'exit-code'.
最后,文件 /var/log/mysql/error.log 中没有任何内容
您有什么想法可以帮助我解决问题吗?我已经尝试使用以下命令重新安装所有软件包:
apt-get --purge remove "mysql*"
apt-get --purge remove "mariadb*"
没有帮助
答案1
请执行:
service mariadb restart; journalctl -xe
因此,您可以确保没有其他消息会将 mysql/mariadb 输出推送到 -xe 视图之外。
也许数据库从未初始化。
因此了解 /etc/my.cnf 的内容可能会有所帮助。
让我们知道 datadir 位于何处。
datadir = /var/lib/mysql
但据我所知,它在某些发行版和版本中更改为 /var/lib/mariadb
如果设置了 datadir,并且非常重要:数据目录为空并且数据库没有运行:
执行mysql_install_db手动。
** 也许必须改变 datadir。
chown -R mysql:mysql /var/lib/mysql
然后重试:
service mariadb start; journalctl -xe
也许用它作为初始的 my.cnf
# This is default example of MySQL/MariaDB configuration provided with openSUSE package
# It is based on upstream defaults with some additional examples.
# The following options will be passed to all MariaDB clients
[client]
# password = your_password
# port = 3306
# socket = /var/run/mysql/mysql.sock
[xtrabackup]
target_dir = /DATA/BACKUP/mysql
datadir = /var/lib/mysql/
[mysqld]
socket = /var/lib/mysql/mysql.sock
innodb_buffer_pool_size = 20G
innodb_file_format = Barracuda
innodb_file_per_table = ON
innodb_buffer_pool_instances = 20
innodb_thread_concurrency = 4
innodb_purge_threads = 4
innodb_strict_mode = 1
innodb_old_blocks_time = 1000
innodb_stats_on_metadata = 0
innodb_write_io_threads = 4
innodb_read_io_threads = 4
innodb_io_capacity = 200000
innodb_open_files = 10000
innodb_log_file_size = 1G
innodb_log_buffer_size = 1G
innodb_log_files_in_group = 3
transaction-isolation = READ-COMMITTED
server-id = 1
#skip-networking
bind-address = 0.0.0.0
log_bin = master-mysql-bin
back_log = 500
concurrent_insert = ALWAYS
expire_logs_days = 10
delay-key-write = ALL
myisam-recover-options = FORCE,BACKUP
key_buffer_size = 512M
join_buffer_size = 256M
max_allowed_packet = 128M
max_heap_table_size = 1024M
tmp_table_size = 1024M
thread_stack = 192K
table_open_cache = 10240
table_definition_cache = 10240
open_files_limit = 100000
net_retry_count = 16384
query_cache_type = 0
query_cache_size = 0M
query_cache_limit = 0M
query_cache_min_res_unit = 1K
thread_cache_size = 100
max_connections = 100
ft_max_word_len = 20
ft_min_word_len = 3
long_query_time = 5
local-infile = 0
log-warnings = 2
performance_schema = ON
log-slave-updates
log-queries-not-using-indexes
skip-external-locking
skip-symbolic-links
skip-name-resolve
!includedir /etc/my.cnf.d
然后手动启动 mysql/mariadb:
# To ensure the service is stoppen:
service mariadb stop
/usr/sbin/mysqld --defaults-file=/etc/my.cnf --user=mysql
答案2
我认为您可能在 datadir 上遇到了权限问题,或者您仍在运行多个版本的 mariadb。
- 您可以发布您的 datadir 权限吗?
还有 rpm -qa|grep -i maria 的 debian 等效输出。我认为它类似于
apt-list --installed| grep -i maria
dpkg -l | grep -i maria
答案3
就我而言,问题出在 my.cnf(Centos 7)
- 找到 / -name my.cnf 备份并全部删除 sudo cp /etc/my.cnf ~/mysql_bkp/my.cnf sudo rm -r /etc/my.cnf sudo cp /etc/mysql/my.cnf ~/mysql_bkp/mysql/my.cnf sudo rm -r /etc/mysql/my.cnf
- 删除所有mysql目录 sudo rm -r /etc/mysql sudo rm -r /var/lib/mysql
- 重新安装 MariaDB sudo yum erasure mariadb sudo yum install mariadb
- 启动 MariaDB systemctl start mariadb
- 目标!
答案4
sudo apt install mysql-common
sudo service mysql start
service mysql status
这对我有用