Situation description

I have a linux server:

Distributor ID: Debian 
Description:    Debian GNU/Linux 5.0.10 (lenny) 
Release:    5.0.10 Codename:    lenny 

Lately, the MySQL server was a litte bit slow when trying to establish a connection to the databases, so I tried to restart the service with service mysql restart since then 2 things happened:

  1. The service stops and refuses to be restarted once again
  2. It displays an error:

Once I try service mysql (start or restart or even stop)

invalid option -- n
Try `tail --help' for more information.
tail: invalid option -- n
Try `tail --help' for more information.

mysql start gives:

ERROR 2002 Can't connect to local Mysql server through socket
/var/run/mysqld/mysqld.sock (2)

But this file doesn't exist in any way in this directory. I though that maybe this file is located somewhere else in my server and the my.cnf just contains the wrong path and this is why the call fails. I tried to find the right path for the file: mysqld.sock and edit the required line in my.cnf file, but with find command I figure out there is no such a file mysqld.sock or mysql.sock in all the server directories.

In a next step I tried to re-install the MySQL server from scratch, what happened is that the old MySQL version and also Apache was successfully removed and the process for the installation was broken and failed to continue.

php -v shows the next output:

PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/lib/php5/20060613/mysql.so' - /usr/lib/php5/20060613/mysql.so: cannot open shared object file: No such file or directory in Unknown on line 0
PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/lib/php5/20060613/mysqli.so' - /usr/lib/php5/20060613/mysqli.so: cannot open shared object file: No such file or directory in Unknown on line 0
PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/lib/php5/20060613/pdo_mysql.so' - /usr/lib/php5/20060613/pdo_mysql.so: cannot open shared object file: No such file or directory in Unknown on line 0
PHP 5.2.6-1+lenny16 with Suhosin-Patch (cli) (built: Feb  3 2012 08:19:55)
Copyright (c) 1997-2008 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2008 Zend Technologies
with the ionCube PHP Loader v3.1.28, Copyright (c) 2002-2007, by ionCube Ltd.

What I am trying to do now:

I made a backup for my websites located under /var/www/vhosts and I want to upgrade the system to Wheezy 7.0 Then to install Apache and MySQL what can I do in such a case, I don't even know if I still have my databases or they are already lost.

What steps are required to fix that?

Have to reconfigure after that the virtual host to enable my websites once again.

I am lost any help?


To install mysql on debian Lenny I tried this:

aptitude -t lenny-backports install mysql-server-5.1 mysql-client-5.1 mysql-common

During the installation it displays that a connecxion test was faild, in the error log file:

mysql: error while loading shared libraries: libreadline.so.6: cannot open shared object file: No such file or directory
  • The socket file only exists when the mysql server is running, so don't panic over it not being on your disk. But please elaborate on the installation was broken in your re-install process. What errors do you get? – Oldskool Mar 29 '14 at 13:25
  • I closed the windows that contains the installation errors :( – amani Mar 29 '14 at 13:27
  • Shouldn't you be starting the mysqld rather than mysql? Pretty sure but different distributions of MySQL may have it packaged differently, but at least for me on CentOS 6 mysql is the client, mysqld is the server. – George Spiceland Mar 29 '14 at 13:28
  • I tied that too but the command loads for a log time and nothing happen ... – amani Mar 29 '14 at 13:29
  • For the first time when that happend I tried mysqld_safe and it works fine, then after severals hours mysql service stoped once again and refused to be started even with mysqld or mysqld_safe – amani Mar 29 '14 at 13:32

Your server was compromised (as per previous question and also confirmed somehow with the strange behaviour of binaries like tail or others that were replaced).

So you have to do a clean re-install of everything; no commands can be trusted and they may not work properly as it seems to be happening. You should use a new server and install Linux and the rest of the stack (mysql, php etc) from scratch from repositories, or copy your data and code, wipe your current server and re-install.

Before that you want to try and figure out where the vulnerability was that they exploited so it doesn't happen again.

Also you want to test first in a server or investigate (ask, seach) if newer (current) versions of the stack (especially PHP) have backwards-incompatibility issues.

  • I aware oh this fact but for the moment I really need to make this server works again.. then I have to rebuilt every thing in a new server but in the meanwhile this server have to be reparaid(services have to work once again) – amani Mar 29 '14 at 14:35
  • 1
    sorry but it may not be possible to "repair" your server without knowing exactly what the exploit did, which you may never know and thus a clean reinstall is the only way. Otherwise you'll probably just spend a lot of time going in circles. If you can't have a second server then copy your data out and clean-reinstall this one. – LinuxDevOps Mar 29 '14 at 14:39
  • It’s not clear to me that the server is compromised as much as it is most possibly unintentionally screwed up thanks to a few other things as well. Irregardless, you cannot repair a damaged system like this. There is a reason for security & patches. And avoiding frustration like this is one of them. – Giacomo1968 Mar 29 '14 at 22:30

A few issues I see. You say you did this:

sudo service mysql restart

But are you logged in as root or a superuser?

Also, This error makes 100% no sense:

invalid option -- n
Try `tail --help' for more information.
tail: invalid option -- n
Try `tail --help' for more information.

So are you trying to tail the MySQL log? And perhaps entered the tail command incorrectly? I would recommend doing this instead:

sudo tail -f -n 200 /var/log/mysql/mysql.log

EDIT: In your comments above, you say:

$ sudo apt-get remove mysql-server mysql-client mysql-common this command made an error and the procedure was stoped... after that service (mysql or apache2) status,start or whatever indicates there is no mysql server or apache

So you ran sudo apt-get remove mysql-server mysql-client mysql-common? You completely removed MySQL from your system. Why would you do that if you are upgrading? Upgrading is an in-place process.

I would recommend you check if anything is in this directory which is where the actual MySQL binary files are stored:

ls -la /var/lib/mysql/

If anything is still there, I would do the following to retain that content:

sudo mv /var/lib/mysql/ /var/lib/mysql_BACKUP/

Then reinstall MySQL like this:

sudo apt-get install mysql-server mysql-client mysql-common

Once reinstalled, stop the MySQL server like this:

sudo service mysql stop

Then shuffle the directories for the binary DBs like so to get the old DBs in place again:

sudo mv /var/lib/mysql/ /var/lib/mysql_FRESH_INSTALL_BACKUP/

sudo mv /var/lib/mysql_BACKUP/ /var/lib/mysql/
  • I am logged as root and this error make sence because in etc/init.d/mysql file in mysql call function there is a call to the tail with n parameter but once I tested tail with n in a command line it works fine – amani Mar 29 '14 at 14:11
  • can I please give me the right command to reinstall MYSQL – amani Mar 29 '14 at 14:58
  • Look at my latest edit. You run the same apt-get command you ran before, but use install instead of remove. – Giacomo1968 Mar 29 '14 at 15:57
  • Ihave already did that but it displays the next:Reading package lists... Done Building dependency tree Reading state information... Done Note, selecting mysql-server-5.0 instead of mysql-server Package mysql-server-5.0 is not available, but is referred to by another package. This may mean that the package is missing, has been obsoleted, or is only available from another source E: Package mysql-server-5.0 has no installation candidate – amani Mar 29 '14 at 17:33
  • This the result of the command you gave to me..I tried in an another way could you please see the edit on the question – amani Mar 29 '14 at 19:44

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