Tuesday, January 17, 2012

MySQL .sock error resolved

After a few days of troubleshooting, installing, re-installing, purging, auto-removing, cleaning, auto-cleaning, updating, and upgrading, I have solved my MySQL woes.

Indeed, the problem appeared that MySQL service was not starting up properly on boot and manually starting the service was either hanging or just not getting the job done.

So, I looked at chkconfig and mysql was not enabled to start.

I opened:


sudo gedit /etc/rc.local


and added the line:

start mysql


right before the exit command.

Lo and behold, upon reboot and no other commands entered, I was able to connect to MySQL without any sock error.

Sunday, January 15, 2012

MySQL continued

Ok so, after typing all that up and going through a hundred or more forum posts, I was actually still having the same problem of MySQL-Server hanging when I was trying to install.

Fortunately, I documented everything as I found potential solutions, and referenced all of it to fix my problem.

Again, my symptoms were:


  • apt (advanced packaging tool) could not complete fresh install of MySQL. It would hang on the line: Setting up MySQL-Server-5.1
  • Because apt would freeze, I would have to force close, which would give me /var/lib/dpkg/lock issues, aka error: "Could not get lock /var/lib/apt/lists/lock"
  • Any attempt to purge/remove MySQL would end erroneously, either because of missing dependencies, or other errors. 
  • If I was able to trick MySQL into kind of finishing install, I would receive the error: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)'

To solve these problems:

Problem #1: apt (advanced packaging tool) could not complete fresh install of MySQL. It would hang on the line: Setting up MySQL-Server-5.1

Solution: I found that if I went into a new terminal tab while that was "setting up" and typed in:

  service mysql stop

It allowed the install to complete.

Problem #2: Because apt would freeze, I would have to force close, which would give me /var/lib/dpkg/lock issues, aka error: "Could not get lock /var/lib/apt/lists/lock"

Solution: First command I would type in: 

sudo fuser -vki /var/lib/dpkg/lock

Then, I entered every command verbatim (including the prefix LANG=C;) from Ubuntu's Help Site (Step 5):

sudo fuser -vvv /var/lib/dpkg/lock

cat /etc/lsb-release

uname -a

sudo rm /var/lib/apt/lists/lock 

sudo cp -arf /var/lib/dpkg /var/lib/dpkg.backup

sudo cp /var/lib/dpkg/status-old /var/lib/dpkg/status

sudo cp /var/lib/dpkg/available-old /var/lib/dpkg/available

sudo rm -rf /var/lib/dpkg/updates/*

sudo rm -rf /var/lib/apt/lists

sudo rm /var/cache/apt/*.bin

sudo mkdir /var/lib/apt/lists

sudo mkdir /var/lib/apt/lists/partial

LANG=C;sudo apt-get clean

LANG=C;sudo apt-get autoclean

LANG=C;sudo apt-get --purge autoremove

LANG=C;sudo apt-get update -o APT::Cache-Limit=25165824

sudo dpkg --configure -a

sudo dpkg --clear-avail

LANG=C;sudo apt-get -f install

LANG=C;sudo apt-get --fix-missing install

LANG=C;sudo apt-get update -o APT::Cache-Limit=25165824 && sudo apt-get dist-upgrade


This cleared up my apt-get/dpkg issues, including partially installed packages.


Problem #3: Any attempt to purge/remove MySQL would end erroneously, either because of missing dependencies, or other errors. 

Solution: Perform the previous step before you go here. 
First I kill any mysql process, check: 

ps -e | grep mysql

And make sure mysql/mysqld is not running. Then:

apt-get --purge autoremove mysql-common

apt-get --purge autoremove mysql-server

In addition to this, I deleted /var/lib/mysql, because that appeared to contain some user information and configuration files that were overlapping into the "fresh installs". I did a locate mysql and looked around at some of the folders and deleted any that I thought contained configuration files or user info. 

Problem #4: If I was able to trick MySQL into kind of finishing install, I would receive the error: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)'

Solution: As long as you delete /var/lib/mysql, purge all MySQL packages and perform a fresh install, you should no longer receive this error. Just make sure your mysqld (MySQL daemon) service is running and your /etc/my.cnf file is pointing to the right location. But, since you theoretically did a fresh install, the default my.cnf settings should be correct and working, they were for me.

Good luck.

MySQL and dpkg lock Troubleshooting

Well, I'm having problems with my LAMP setup, so I am going to document some of it. Hopefully, if someone comes across similar errors/symptoms, this will help solve their problems as well. I am running Ubuntu 11.10, no significant mods.


Symptoms:


  • Initial MySQL error: error: 'Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)'
  • Attempts to fix/repair MySQL installation fail, leading to decision to uninstall/re-install MySQL.
  • Upon attempt to re-install MySQL, Ubuntu hangs while "Setting up mysql-server-5.1 (5.1.58-1ubuntu1)", and can not Ctrl+C out of it, forced to close terminal. (Even after waiting 30+ minutes.)
  • Attempts to re-install anything at this point leads to error message "Could not get lock /var/lib/apt/lists/lock". Or any variation of /var/lib/lock.

Steps Taken:
  1. Unfortunately, the "lock" error is very persistent and even following many common troubleshooting steps, can be difficult to alleviate. 
What is happening when the /var/lib/apt/lists/lock, or any other lock file is preventing apt (advanced packaging tool)?

This error appears to occur when you have halted apt in the middle of upgrading/installing/purging without letting it complete on its own. It can also occur when you have apt and Synaptic Package Manager running at the same time. There may be other instances of this occurring independent of prematurely ending apt. 

How do I fix this? (MOST SUCCESSFUL SOLUTION: fuser -vki /var/lib/dpkg/lock)

Now that you understand why the error is occurring, you can evaluate your unique problem. 

Basic Possible Solution #1 & #1a: Check to make sure there is only one package manager running at a time. Ubuntu could have a few things going on, including Update Manager scanning for updates, Software Center installing something, Synaptic. If you can soft-close these, it will be better than force-closing/killing processes. Reboot. If you have already done this, go to step 2. This apparently solves the problem for some people.

Possible Solution #2: In a terminal, enter in the command line: ps -e | grep apt
This will show you any processes with the keyword apt (our likely culprit for the source of this problem) and you can then kill the process(es) with the command line input: sudo kill 8488 (change 8488 to the corresponding process PID). Once you complete this, you can check to see if this solved your problem by entering: apt-get update or apt-get upgrade.
If your apt command is working correctly, you have solved your problem. It may give you an error message that says: E: dpkg was interrupted, you must manually run 'sudo dpkg --configure -a' to correct the problem. If that is your situation, go ahead and type that into the command line. This will try to finish off where apt got hung up. If it completes its task and returns you to command line prompt, you should be in the clear. If it continues to hang or returns a /var/lib/lock error, try another solution. If you tried ps -e | grep apt and could not locate the process using the lock, try another approach: sudo fuser -vki /var/lib/dpkg/lock (not only will this find the process, the -k flag will kill it) or sudo lsof | grep /var/lib/dpkg/lock (this will only locate the process using the lock) (change the location of the lock file to fit your situation).

Possible Solution #3: You can try a less preferred method of removing the lock files causing the lockup. Because your problem is unique, your /lock will likely be in a unique file location. To begin, if your error is, for example, Could not get lock /var/lib/apt/lists/lock, you can try typing into the command line: sudo rm -f /var/lib/apt/lists/lock. Again, check if this fixes your problem by typing: apt-get update or apt-get upgrade. Additionally, a bit of a rough method, you can try: sudo killall -9 apt-get aptitude. I personally did not find much success in just outright deleting the lock file, I even went as far as to locate lock, and removed every instance of the file I could find. That did not get me any further. I include these examples because some people claim it solved their issue. I call these methods rough or less preferred, because you are not being very precise with your troubleshooting. It is more of a cluster-attack. Theoretically, there is one underlying problem here that you can eradicate with precision. It is just a matter of signal flow and finding where that problem begins and ends.

Possible Solution #4: Official Steps from Ubuntu's Help Site:
sudo fuser -vvv /var/lib/dpkg/lock

cat /etc/lsb-release

uname -a

sudo rm /var/lib/apt/lists/lock 

sudo cp -arf /var/lib/dpkg /var/lib/dpkg.backup

sudo cp /var/lib/dpkg/status-old /var/lib/dpkg/status

sudo cp /var/lib/dpkg/available-old /var/lib/dpkg/available

sudo rm -rf /var/lib/dpkg/updates/*

sudo rm -rf /var/lib/apt/lists

sudo rm /var/cache/apt/*.bin

sudo mkdir /var/lib/apt/lists

sudo mkdir /var/lib/apt/lists/partial

LANG=C;sudo apt-get clean

LANG=C;sudo apt-get autoclean

LANG=C;sudo apt-get --purge autoremove

LANG=C;sudo apt-get update -o APT::Cache-Limit=25165824

sudo dpkg --configure -a

sudo dpkg --clear-avail

LANG=C;sudo apt-get -f install

LANG=C;sudo apt-get --fix-missing install

LANG=C;sudo apt-get update -o APT::Cache-Limit=25165824 && sudo apt-get dist-upgrade



Steps Taken(continued)


Hopefully through that, you are able to get your lock cleared up, and now we can move on to repairing our MySQL setup.

Why is MySQL giving me a  'Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)' error in the first place? 

Potential Causes:
  • mysqld.sock file becomes corrupt.
  • no disk space to write the .sock file to.
  • mysqld is not running. (verify with: ps -ef | grep mysqld and ps -ef | grep mysql)
  • the Linux user does not have permission to access the file.
  • MySQL is expecting to find the socket in a location where it is not.

Possible Solution #1: Verify the user has permission to access the file. Do this by: 
usermod -G usernamehere
chmod g+rwx /var/lib/mysql

Possible Solution #2: Edit /etc/my.cnf to specify the correct location of the .sock file. If your /etc/my.cnf is pointing to /var/lib/mysql/mysql.sock, try changing it to /tmp/mysql.sock

Possible Solution #3: service mysql start     or     /etc/init.d/mysqld start



Steps Taken(conclusion)

Ultimately, I was able to fix every problem I was having through one or more methods described above. If you got through everything and still having MySQL problems, I recommend a fresh install.

Feel free to comment in any corrections/questions/suggestions/things that worked for you.



Saturday, January 7, 2012

Israel responds to credit card hack

BBC News - Israel vows to retaliate after credit cards are hacked

" Israel has said it will respond to cyber-attacks in the same way it responds to violent "terrorist" acts after the credit card details of thousands of its citizens were published online.

A hacker named OxOmar claiming to be Saudi said on Thursday he had leaked the private information.

Credit card companies say at least 6,000 valid cards have been exposed.

Reports say OxOmar may be a 19-year-old living in Mexico.

Such cyber-attacks are "a breach of sovereignty comparable to a terrorist operation, and must be treated as such", Deputy Foreign Minister Danny Ayalon has said.

"Israel has active capabilities for striking at those who are trying to harm it, and no agency or hacker will be immune from retaliatory action," he added, without giving further details.

An aide to Mr Ayalon said Israel was aware of the report OxOmar may be in Mexico, but had not yet requested help from the Mexican authorities, Reuters news agency reports."

Indian hackers