1

I'm attempting to move one of my projects over from another VPS, and I think I've messed up my SQL database. I'm fairly sure the problem has started because there are multiple instances of MySQL on my VPS, however I'm having trouble removing all the files.

So first off I attempted to login to MySQL.

root@fileserver:~# mysql --user=root -p
Enter password:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

As there isn't a lot of important information in my database, I just decided to remove MySQL by doing the following

root@fileserver:~# sudo apt-get remove --purge mysql-server mysql-client mysql-common -y
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
  libaio1 libevent-core-2.0-5 libnuma1 mysql-client-core-5.7 mysql-server-core-5.7
Use 'sudo apt autoremove' to remove them.
The following packages will be REMOVED:
  mysql-client* mysql-client-5.7* mysql-common* mysql-server* mysql-server-5.7*
0 upgraded, 0 newly installed, 5 to remove and 18 not upgraded.
2 not fully installed or removed.
After this operation, 82.7 MB disk space will be freed.
(Reading database ... 150440 files and directories currently installed.)
Removing mysql-server (5.7.23-0ubuntu0.16.04.1) ...
Removing mysql-server-5.7 (5.7.23-0ubuntu0.16.04.1) ...
update-alternatives: warning: alternative /etc/mysql/my.cnf.fallback (part of link group my.cnf) doesn't exist; removing from list of alternatives
update-alternatives: warning: alternative /etc/mysql/mysql.cnf (part of link group my.cnf) doesn't exist; removing from list of alternatives
update-alternatives: warning: /etc/alternatives/my.cnf is dangling; it will be updated with best choice
Purging configuration files for mysql-server-5.7 (5.7.23-0ubuntu0.16.04.1) ...
Removing mysql-client (5.7.23-0ubuntu0.16.04.1) ...
Removing mysql-client-5.7 (5.7.23-0ubuntu0.16.04.1) ...
Removing mysql-common (5.7.23-0ubuntu0.16.04.1) ...
Purging configuration files for mysql-common (5.7.23-0ubuntu0.16.04.1) ...
Processing triggers for man-db (2.7.5-1) ...
Processing triggers for systemd (229-4ubuntu21.4) ...
root@fileserver:~# sudo apt-get remove --purge mysql-server mysql-client mysql-common -y
Reading package lists... Done
Building dependency tree
Reading state information... Done
Package 'mysql-client' is not installed, so not removed
Package 'mysql-common' is not installed, so not removed
Package 'mysql-server' is not installed, so not removed
The following packages were automatically installed and are no longer required:
  libaio1 libevent-core-2.0-5 libnuma1 mysql-client-core-5.7 mysql-server-core-5.7
Use 'sudo apt autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 18 not upgraded.
root@fileserver:~# sudo apt-get autoremove -y
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages will be REMOVED:
  libaio1 libevent-core-2.0-5 libnuma1 mysql-client-core-5.7 mysql-server-core-5.7
0 upgraded, 0 newly installed, 5 to remove and 18 not upgraded.
After this operation, 78.0 MB disk space will be freed.
(Reading database ... 150299 files and directories currently installed.)
Removing mysql-server-core-5.7 (5.7.23-0ubuntu0.16.04.1) ...
Removing mysql-client-core-5.7 (5.7.23-0ubuntu0.16.04.1) ...
Removing libaio1:amd64 (0.3.110-2) ...
Removing libevent-core-2.0-5:amd64 (2.0.21-stable-2ubuntu0.16.04.1) ...
Removing libnuma1:amd64 (2.0.11-1ubuntu1.1) ...
Processing triggers for man-db (2.7.5-1) ...
Processing triggers for libc-bin (2.23-0ubuntu10) ...
root@fileserver:~# sudo apt-get autoclean
Reading package lists... Done
Building dependency tree
Reading state information... Done
root@fileserver:~# rm -rf /etc/mysql
root@fileserver:~# sudo find / -iname 'mysql*' -exec rm -rf {} \;
find: '/var/lib/mysql-files': No such file or directory
find: '/var/lib/mysql-keyring': No such file or directory
root@fileserver:~#

So I wasn't sure that worked as there were quite a few errors, I attempted to re-install MySQL (this is why I think I have broken it)

root@fileserver:~# sudo apt-get install mysql-client mysql-server
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed:
  mysql-client mysql-server
0 upgraded, 2 newly installed, 0 to remove and 18 not upgraded.
1 not fully installed or removed.
Need to get 0 B/20.9 kB of archives.
After this operation, 219 kB of additional disk space will be used.
Selecting previously unselected package mysql-client.
(Reading database ... 150436 files and directories currently installed.)
Preparing to unpack .../mysql-client_5.7.23-0ubuntu0.16.04.1_all.deb ...
Unpacking mysql-client (5.7.23-0ubuntu0.16.04.1) ...
Selecting previously unselected package mysql-server.
Preparing to unpack .../mysql-server_5.7.23-0ubuntu0.16.04.1_all.deb ...
Unpacking mysql-server (5.7.23-0ubuntu0.16.04.1) ...
Setting up mysql-server-5.7 (5.7.23-0ubuntu0.16.04.1) ...
update-alternatives: error: alternative path /etc/mysql/mysql.cnf doesn't exist
dpkg: error processing package mysql-server-5.7 (--configure):
 subprocess installed post-installation script returned error exit status 2
Setting up mysql-client (5.7.23-0ubuntu0.16.04.1) ...
dpkg: dependency problems prevent configuration of mysql-server:
 mysql-server depends on mysql-server-5.7; however:
  Package mysql-server-5.7 is not configured yet.

dpkg: error processing package mysql-server (--configure):
 dependency problems - leaving unconfigured
No apport report written because the error message indicates its a followup error from a previous failure.
                                                                                                          Errors were encountered while processing:
 mysql-server-5.7
 mysql-server
E: Sub-process /usr/bin/dpkg returned an error code (1)

After this I attempted to start MySQL

root@fileserver:~# sudo /etc/init.d/mysql start
[....] Starting mysql (via systemctl): mysql.serviceJob for mysql.service failed because the control process exited with error code. See "systemctl status mysql.service" and "journalctl -xe" for details.
     failed!

So I looked in journalctl -xe as advised and this is the log that I am shown

root@fileserver:~# journalctl -xe
-- The process /usr/share/mysql/mysql-systemd-start could not be executed and failed.
--
-- The error number returned by this process is 3.
Sep 30 06:35:38 fileserver systemd[1]: mysql.service: Control process exited, code=exited status=217
Sep 30 06:35:38 fileserver systemd[1]: Failed to start MySQL Community Server.
-- Subject: Unit mysql.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit mysql.service has failed.
--
-- The result is failed.
Sep 30 06:35:38 fileserver systemd[1]: mysql.service: Unit entered failed state.
Sep 30 06:35:38 fileserver systemd[1]: mysql.service: Failed with result 'exit-code'.
Sep 30 06:35:39 fileserver systemd[1]: mysql.service: Service hold-off time over, scheduling restart.
Sep 30 06:35:39 fileserver systemd[1]: Stopped MySQL Community Server.
-- Subject: Unit mysql.service has finished shutting down
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit mysql.service has finished shutting down.
Sep 30 06:35:39 fileserver systemd[1]: Starting MySQL Community Server...
-- Subject: Unit mysql.service has begun start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit mysql.service has begun starting up.
Sep 30 06:35:39 fileserver systemd[16248]: mysql.service: Failed at step USER spawning /usr/share/mysql/mysql-systemd-start: No such process
-- Subject: Process /usr/share/mysql/mysql-systemd-start could not be executed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- The process /usr/share/mysql/mysql-systemd-start could not be executed and failed.
--
-- The error number returned by this process is 3.
Sep 30 06:35:39 fileserver systemd[1]: mysql.service: Control process exited, code=exited status=217
Sep 30 06:35:39 fileserver systemd[1]: Failed to start MySQL Community Server.
-- Subject: Unit mysql.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit mysql.service has failed.
--
-- The result is failed.
Sep 30 06:35:39 fileserver systemd[1]: mysql.service: Unit entered failed state.
Sep 30 06:35:39 fileserver systemd[1]: mysql.service: Failed with result 'exit-code'.
Sep 30 06:35:39 fileserver systemd[1]: mysql.service: Service hold-off time over, scheduling restart.
Sep 30 06:35:39 fileserver systemd[1]: Stopped MySQL Community Server.
-- Subject: Unit mysql.service has finished shutting down
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit mysql.service has finished shutting down.
Sep 30 06:35:39 fileserver systemd[1]: mysql.service: Start request repeated too quickly.
Sep 30 06:35:39 fileserver systemd[1]: Failed to start MySQL Community Server.
-- Subject: Unit mysql.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit mysql.service has failed.
--
-- The result is failed.

root@fileserver:~# mysql --user=root -p
Enter password:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
root@fileserver:~# sudo apt-get install mysql-client mysql-server
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed:
  mysql-client mysql-server
0 upgraded, 2 newly installed, 0 to remove and 18 not upgraded.
1 not fully installed or removed.
Need to get 0 B/20.9 kB of archives.
After this operation, 219 kB of additional disk space will be used.
Selecting previously unselected package mysql-client.
(Reading database ... 150436 files and directories currently installed.)
Preparing to unpack .../mysql-client_5.7.23-0ubuntu0.16.04.1_all.deb ...
Unpacking mysql-client (5.7.23-0ubuntu0.16.04.1) ...
Selecting previously unselected package mysql-server.
Preparing to unpack .../mysql-server_5.7.23-0ubuntu0.16.04.1_all.deb ...
Unpacking mysql-server (5.7.23-0ubuntu0.16.04.1) ...
Setting up mysql-server-5.7 (5.7.23-0ubuntu0.16.04.1) ...
update-alternatives: error: alternative path /etc/mysql/mysql.cnf doesn't exist
dpkg: error processing package mysql-server-5.7 (--configure):
 subprocess installed post-installation script returned error exit status 2
Setting up mysql-client (5.7.23-0ubuntu0.16.04.1) ...
dpkg: dependency problems prevent configuration of mysql-server:
 mysql-server depends on mysql-server-5.7; however:
  Package mysql-server-5.7 is not configured yet.

dpkg: error processing package mysql-server (--configure):
 dependency problems - leaving unconfigured
No apport report written because the error message indicates its a followup error from a previous failure.
                                                                                                          Errors were encountered while processing:
 mysql-server-5.7
 mysql-server
E: Sub-process /usr/bin/dpkg returned an error code (1)
root@fileserver:~# ^C
root@fileserver:~# ^C
root@fileserver:~# service mysql start
Job for mysql.service failed because the control process exited with error code. See "systemctl status mysql.service" and "journalctl -xe" for details.
root@fileserver:~# sudo /etc/init.d/mysql start
[....] Starting mysql (via systemctl): mysql.serviceJob for mysql.service failed because the control process exited with error code. See "systemctl status mysql.service" and "journalctl -xe" for details.
 failed!
root@fileserver:~# ^C
root@fileserver:~# systemctl status mysql.service
● mysql.service - MySQL Community Server
   Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
   Active: inactive (dead) (Result: exit-code) since Sun 2018-09-30 06:38:37 EDT; 25s ago
  Process: 16482 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=exited, status=217/USER)
 Main PID: 15680 (code=exited, status=203/EXEC)

Sep 30 06:38:37 fileserver systemd[1]: Failed to start MySQL Community Server.
Sep 30 06:38:37 fileserver systemd[1]: mysql.service: Unit entered failed state.
Sep 30 06:38:37 fileserver systemd[1]: mysql.service: Failed with result 'exit-code'.
Sep 30 06:38:37 fileserver systemd[1]: mysql.service: Service hold-off time over, scheduling restart.
Sep 30 06:38:37 fileserver systemd[1]: Stopped MySQL Community Server.
Sep 30 06:38:37 fileserver systemd[1]: mysql.service: Start request repeated too quickly.
Sep 30 06:38:37 fileserver systemd[1]: Failed to start MySQL Community Server.
root@fileserver:~# ^C
root@fileserver:~# journalctl -xe
-- The process /usr/share/mysql/mysql-systemd-start could not be executed and failed.
--
-- The error number returned by this process is 3.
Sep 30 06:38:36 fileserver systemd[1]: mysql.service: Control process exited, code=exited status=217
Sep 30 06:38:36 fileserver systemd[1]: Failed to start MySQL Community Server.
-- Subject: Unit mysql.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit mysql.service has failed.
--
-- The result is failed.
Sep 30 06:38:36 fileserver systemd[1]: mysql.service: Unit entered failed state.
Sep 30 06:38:36 fileserver systemd[1]: mysql.service: Failed with result 'exit-code'.
Sep 30 06:38:37 fileserver systemd[1]: mysql.service: Service hold-off time over, scheduling restart.
Sep 30 06:38:37 fileserver systemd[1]: Stopped MySQL Community Server.
-- Subject: Unit mysql.service has finished shutting down
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit mysql.service has finished shutting down.
Sep 30 06:38:37 fileserver systemd[1]: Starting MySQL Community Server...
-- Subject: Unit mysql.service has begun start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit mysql.service has begun starting up.
Sep 30 06:38:37 fileserver systemd[16482]: mysql.service: Failed at step USER spawning /usr/share/mysql/mysql-systemd-start: No such process
-- Subject: Process /usr/share/mysql/mysql-systemd-start could not be executed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- The process /usr/share/mysql/mysql-systemd-start could not be executed and failed.
--
-- The error number returned by this process is 3.
Sep 30 06:38:37 fileserver systemd[1]: mysql.service: Control process exited, code=exited status=217
Sep 30 06:38:37 fileserver systemd[1]: Failed to start MySQL Community Server.
-- Subject: Unit mysql.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit mysql.service has failed.
--
-- The result is failed.
Sep 30 06:38:37 fileserver systemd[1]: mysql.service: Unit entered failed state.
Sep 30 06:38:37 fileserver systemd[1]: mysql.service: Failed with result 'exit-code'.
Sep 30 06:38:37 fileserver systemd[1]: mysql.service: Service hold-off time over, scheduling restart.
Sep 30 06:38:37 fileserver systemd[1]: Stopped MySQL Community Server.
-- Subject: Unit mysql.service has finished shutting down
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit mysql.service has finished shutting down.
Sep 30 06:38:37 fileserver systemd[1]: mysql.service: Start request repeated too quickly.
Sep 30 06:38:37 fileserver systemd[1]: Failed to start MySQL Community Server.
-- Subject: Unit mysql.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit mysql.service has failed.
--
-- The result is failed.

The strange thing is, even after I have completely uninstalled MySQL, I can attempt to login with mysql --user=root -p and I can type my password and get error 2002. Surely this shouldn't be happening if I have completely uninstalled it?

Any help would be appreciated, I'm very much a beginner when it comes to this and I don't fully understand all of the output of the logs.

Hopefully I've posted enough information. Cheers.

  • You really should run sudo apt autoremove as it recommended. – Michael Hampton Sep 30 '18 at 23:29
2

Surely this shouldn't be happening if I have completely uninstalled it?

Clearly you haven't completely uninstalled it. There are 2 parts to mysql, the client and the server. They are usually installed via different packages. The command mysql is the client program. It runs and requests the information that you said told it to ask for. It then attempts to make a connection using default parameters to the local server. The local server is not running so you get a 2002 error ...cannot connect to server...

  • How do I completely uninstall it? I would have thought 'sudo apt-get remove --purge mysql-server mysql-client mysql-common -y' would remove the client and the server. – Dan P Sep 30 '18 at 13:22
  • 1
    Depends on how you installed it in the first place. If you created your own build with make or installed it via dpkg without using a package management system your management system doesn't know about it. – Broco Sep 30 '18 at 20:54
0

So I don't know Ubuntu so well, but there's your error...

Selecting previously unselected package mysql-server.
Preparing to unpack .../mysql-server_5.7.23-0ubuntu0.16.04.1_all.deb ...
Unpacking mysql-server (5.7.23-0ubuntu0.16.04.1) ...
Setting up mysql-server-5.7 (5.7.23-0ubuntu0.16.04.1) ...
**update-alternatives: error: alternative path /etc/mysql/mysql.cnf doesn't exist**
dpkg: error processing package mysql-server-5.7 (--configure):
 subprocess installed post-installation script returned error exit status 2

You could try to copy the default mysql.cnf file to that location as a quick fix, but you should definitely try to figure out what that error is/where it comes from...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.