AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / ubuntu / 问题 / 1292362
Accepted
Nicholas Saunders
Nicholas Saunders
Asked: 2020-11-15 10:56:54 +0800 CST2020-11-15 10:56:54 +0800 CST 2020-11-15 10:56:54 +0800 CST

为什么 MariaDB 或 MySQL 不启动?

  • 772

显然清除和/或重新安装mysql并mariadb可能导致冲突,因此尝试:

root@mordor:~# 
root@mordor:~# sudo apt purge mariadb-server mariadb-client mysql-client mysql-server
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Package 'mysql-client' is not installed, so not removed
Package 'mysql-server' is not installed, so not removed
The following packages will be REMOVED:
  mariadb-client* mariadb-server*
0 upgraded, 0 newly installed, 2 to remove and 1 not upgraded.
After this operation, 20.5 kB disk space will be freed.
Do you want to continue? [Y/n] y
(Reading database ... 181581 files and directories currently installed.)
Removing mariadb-client (1:10.4.17+maria~focal) ...
Removing mariadb-server (1:10.4.17+maria~focal) ...
root@mordor:~# 
root@mordor:~# 
root@mordor:~# rm -rf  /var/lib/mysql
root@mordor:~# 
root@mordor:~# sudo apt install mariadb-client mariadb-server
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following NEW packages will be installed:
  mariadb-client mariadb-server
0 upgraded, 2 newly installed, 0 to remove and 1 not upgraded.
Need to get 0 B/6252 B of archives.
After this operation, 20.5 kB of additional disk space will be used.
Selecting previously unselected package mariadb-client.
(Reading database ... 181576 files and directories currently installed.)
Preparing to unpack .../mariadb-client_1%3a10.4.17+maria~focal_all.deb ...
Unpacking mariadb-client (1:10.4.17+maria~focal) ...
Selecting previously unselected package mariadb-server.
Preparing to unpack .../mariadb-server_1%3a10.4.17+maria~focal_all.deb ...
Unpacking mariadb-server (1:10.4.17+maria~focal) ...
Setting up mariadb-client (1:10.4.17+maria~focal) ...
Setting up mariadb-server (1:10.4.17+maria~focal) ...
root@mordor:~# 
root@mordor:~# mariadb
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
root@mordor:~# 
root@mordor:~# systemctl status mariadb.service
● mariadb.service - MariaDB 10.4.17 database server
     Loaded: loaded (/lib/systemd/system/mariadb.service; enabled; vendor preset: enabled)
    Drop-In: /etc/systemd/system/mariadb.service.d
             └─migrated-from-my.cnf-settings.conf
     Active: failed (Result: exit-code) since Sat 2020-11-14 10:43:31 PST; 1h 23min ago
       Docs: man:mysqld(8)
             https://mariadb.com/kb/en/library/systemd/
   Main PID: 90075 (code=exited, status=1/FAILURE)
     Status: "MariaDB server is down"

Nov 14 10:43:29 mordor systemd[1]: Starting MariaDB 10.4.17 database server...
Nov 14 10:43:29 mordor mysqld[90075]: 2020-11-14 10:43:29 0 [Note] /usr/sbin/mysqld (mysqld 10.4.17-MariaDB-1:10.4.17+maria~focal-l>
Nov 14 10:43:29 mordor mysqld[90075]: 2020-11-14 10:43:29 0 [Warning] Could not increase number of max_open_files to more than 1638>
Nov 14 10:43:29 mordor mysqld[90075]: 2020-11-14 10:43:29 0 [Warning] Changed limits: max_open_files: 16384  max_connections: 500 (>
Nov 14 10:43:31 mordor systemd[1]: mariadb.service: Main process exited, code=exited, status=1/FAILURE
Nov 14 10:43:31 mordor systemd[1]: mariadb.service: Failed with result 'exit-code'.
Nov 14 10:43:31 mordor systemd[1]: Failed to start MariaDB 10.4.17 database server.
root@mordor:~# 

我该如何开始mariadb?我可以再次清除它,但这只是一个循环。

password apt database mariadb sockets
  • 2 2 个回答
  • 353 Views

2 个回答

  • Voted
  1. Best Answer
    Rinzwind
    2020-11-15T11:01:03+08:002020-11-15T11:01:03+08:00

    第一次检查 mariadb 是否正在运行。如果不是,您将无法连接到它。

    你忘了做

    sudo mysql_secure_installation
    

    设置用户和密码。

    关于这个命令也请...

    • 删除匿名用户
    • 删除测试数据库
    • 禁止远程root登录

    通常你也可以这样做:

    sudo -i
    {admin password}
    mariadb
    

    然后设置用户和密码。尽量避免使用通用名称作为用户(即 no root、admin、您的用户名等)并使用个人用户名。它使它成为人们需要猜测的另一件事。

    • 1
  2. Nicholas Saunders
    2020-11-15T12:17:32+08:002020-11-15T12:17:32+08:00

    至少可以进入数据库:

    root@mordor:~# 
    root@mordor:~# sudo apt purge mariadb-server-core-10.4 mariadb-server-10.4 mariadb-client-core-10.4  mariadb-client-10.4 
    Reading package lists... Done
    Building dependency tree       
    Reading state information... Done
    Package 'mariadb-client-10.4' is not installed, so not removed
    Package 'mariadb-client-core-10.4' is not installed, so not removed
    Package 'mariadb-server-10.4' is not installed, so not removed
    Package 'mariadb-server-core-10.4' is not installed, so not removed
    The following packages were automatically installed and are no longer required:
      galera-4 libdbd-mysql-perl libdbi-perl libterm-readkey-perl socat
    Use 'sudo apt autoremove' to remove them.
    0 upgraded, 0 newly installed, 0 to remove and 1 not upgraded.
    root@mordor:~# 
    root@mordor:~# sudo apt purge mysql-server-core-8.0 mysql-server-8.0 mysql-client-core-8.0 mysql-client-8.0
    Reading package lists... Done
    Building dependency tree       
    Reading state information... Done
    Package 'mysql-client-8.0' is not installed, so not removed
    Package 'mysql-client-core-8.0' is not installed, so not removed
    Package 'mysql-server-8.0' is not installed, so not removed
    Package 'mysql-server-core-8.0' is not installed, so not removed
    The following packages were automatically installed and are no longer required:
      galera-4 libdbd-mysql-perl libdbi-perl libterm-readkey-perl socat
    Use 'sudo apt autoremove' to remove them.
    0 upgraded, 0 newly installed, 0 to remove and 1 not upgraded.
    root@mordor:~# 
    root@mordor:~# rm -rf  /var/lib/mysql
    root@mordor:~# 
    root@mordor:~# sudo apt install mariadb-client mariadb-server
    Reading package lists... Done
    Building dependency tree       
    Reading state information... Done
    The following additional packages will be installed:
      mariadb-client-10.4 mariadb-client-core-10.4 mariadb-server-10.4 mariadb-server-core-10.4
    Suggested packages:
      mailx mariadb-test tinyca
    The following NEW packages will be installed:
      mariadb-client mariadb-client-10.4 mariadb-client-core-10.4 mariadb-server mariadb-server-10.4 mariadb-server-core-10.4
    0 upgraded, 6 newly installed, 0 to remove and 1 not upgraded.
    Need to get 0 B/12.9 MB of archives.
    After this operation, 142 MB of additional disk space will be used.
    Do you want to continue? [Y/n] 
    Preconfiguring packages ...
    Selecting previously unselected package mariadb-client-core-10.4.
    (Reading database ... 181260 files and directories currently installed.)
    Preparing to unpack .../0-mariadb-client-core-10.4_1%3a10.4.17+maria~focal_amd64.deb ...
    Unpacking mariadb-client-core-10.4 (1:10.4.17+maria~focal) ...
    Selecting previously unselected package mariadb-client-10.4.
    Preparing to unpack .../1-mariadb-client-10.4_1%3a10.4.17+maria~focal_amd64.deb ...
    Unpacking mariadb-client-10.4 (1:10.4.17+maria~focal) ...
    Selecting previously unselected package mariadb-server-core-10.4.
    Preparing to unpack .../2-mariadb-server-core-10.4_1%3a10.4.17+maria~focal_amd64.deb ...
    Unpacking mariadb-server-core-10.4 (1:10.4.17+maria~focal) ...
    Selecting previously unselected package mariadb-server-10.4.
    Preparing to unpack .../3-mariadb-server-10.4_1%3a10.4.17+maria~focal_amd64.deb ...
    Unpacking mariadb-server-10.4 (1:10.4.17+maria~focal) ...
    Selecting previously unselected package mariadb-client.
    Preparing to unpack .../4-mariadb-client_1%3a10.4.17+maria~focal_all.deb ...
    Unpacking mariadb-client (1:10.4.17+maria~focal) ...
    Selecting previously unselected package mariadb-server.
    Preparing to unpack .../5-mariadb-server_1%3a10.4.17+maria~focal_all.deb ...
    Unpacking mariadb-server (1:10.4.17+maria~focal) ...
    Setting up mariadb-server-core-10.4 (1:10.4.17+maria~focal) ...
    Setting up mariadb-client-core-10.4 (1:10.4.17+maria~focal) ...
    Setting up mariadb-client-10.4 (1:10.4.17+maria~focal) ...
    Setting up mariadb-client (1:10.4.17+maria~focal) ...
    Setting up mariadb-server-10.4 (1:10.4.17+maria~focal) ...
    Failed to stop mysql.service: Unit mysql.service not loaded.
    Created symlink /etc/systemd/system/mysql.service → /lib/systemd/system/mariadb.service.
    Created symlink /etc/systemd/system/mysqld.service → /lib/systemd/system/mariadb.service.
    Created symlink /etc/systemd/system/multi-user.target.wants/mariadb.service → /lib/systemd/system/mariadb.service.
    Setting up mariadb-server (1:10.4.17+maria~focal) ...
    Processing triggers for man-db (2.9.1-1) ...
    root@mordor:~# 
    root@mordor:~# sudo mysql_secure_installation
    
    NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
          SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!
    
    In order to log into MariaDB to secure it, we'll need the current
    password for the root user. If you've just installed MariaDB, and
    haven't set the root password yet, you should just press enter here.
    
    Enter current password for root (enter for none): 
    OK, successfully used password, moving on...
    
    Setting the root password or using the unix_socket ensures that nobody
    can log into the MariaDB root user without the proper authorisation.
    
    You already have your root account protected, so you can safely answer 'n'.
    
    Switch to unix_socket authentication [Y/n] n
     ... skipping.
    
    You already have your root account protected, so you can safely answer 'n'.
    
    Change the root password? [Y/n] y
    New password: 
    Re-enter new password: 
    Password updated successfully!
    Reloading privilege tables..
     ... Success!
    
    
    By default, a MariaDB installation has an anonymous user, allowing anyone
    to log into MariaDB without having to have a user account created for
    them.  This is intended only for testing, and to make the installation
    go a bit smoother.  You should remove them before moving into a
    production environment.
    
    Remove anonymous users? [Y/n]  
     ... Success!
    
    Normally, root should only be allowed to connect from 'localhost'.  This
    ensures that someone cannot guess at the root password from the network.
    
    Disallow root login remotely? [Y/n] 
     ... Success!
    
    By default, MariaDB comes with a database named 'test' that anyone can
    access.  This is also intended only for testing, and should be removed
    before moving into a production environment.
    
    Remove test database and access to it? [Y/n] 
     - Dropping test database...
     ... Success!
     - Removing privileges on test database...
     ... Success!
    
    Reloading the privilege tables will ensure that all changes made so far
    will take effect immediately.
    
    Reload privilege tables now? [Y/n] 
     ... Success!
    
    Cleaning up...
    
    All done!  If you've completed all of the above steps, your MariaDB
    installation should now be secure.
    
    Thanks for using MariaDB!
    root@mordor:~# 
    root@mordor:~# mariadb -u root
    Welcome to the MariaDB monitor.  Commands end with ; or \g.
    Your MariaDB connection id is 57
    Server version: 10.4.17-MariaDB-1:10.4.17+maria~focal-log mariadb.org binary distribution
    
    Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
    
    Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
    
    MariaDB [(none)]> exit
    Bye
    root@mordor:~# 
    

    或作为普通用户:

    nicholas@mordor:~$ 
    nicholas@mordor:~$ mariadb -u root -p
    Enter password: 
    Welcome to the MariaDB monitor.  Commands end with ; or \g.
    Your MariaDB connection id is 60
    Server version: 10.4.17-MariaDB-1:10.4.17+maria~focal-log mariadb.org binary distribution
    
    Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
    
    Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
    
    MariaDB [(none)]> 
    MariaDB [(none)]> exit
    Bye
    nicholas@mordor:~$ 
    
    • 0

相关问题

  • 如何编写 shell 脚本来安装应用程序列表?

  • 如何查看存档中可用的软件包的所有版本?

  • 是否可以说出我安装的哪些软件包不在原版安装中?

  • 如何删除 PPA?

  • 使用 apt-get upgrade 时如何强制安装内核更新?

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    如何运行 .sh 脚本?

    • 16 个回答
  • Marko Smith

    如何安装 .tar.gz(或 .tar.bz2)文件?

    • 14 个回答
  • Marko Smith

    如何列出所有已安装的软件包

    • 24 个回答
  • Marko Smith

    无法锁定管理目录 (/var/lib/dpkg/) 是另一个进程在使用它吗?

    • 25 个回答
  • Martin Hope
    Flimm 如何在没有 sudo 的情况下使用 docker? 2014-06-07 00:17:43 +0800 CST
  • Martin Hope
    Ivan 如何列出所有已安装的软件包 2010-12-17 18:08:49 +0800 CST
  • Martin Hope
    La Ode Adam Saputra 无法锁定管理目录 (/var/lib/dpkg/) 是另一个进程在使用它吗? 2010-11-30 18:12:48 +0800 CST
  • Martin Hope
    David Barry 如何从命令行确定目录(文件夹)的总大小? 2010-08-06 10:20:23 +0800 CST
  • Martin Hope
    jfoucher “以下软件包已被保留:”为什么以及如何解决? 2010-08-01 13:59:22 +0800 CST
  • Martin Hope
    David Ashford 如何删除 PPA? 2010-07-30 01:09:42 +0800 CST

热门标签

10.10 10.04 gnome networking server command-line package-management software-recommendation sound xorg

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve