LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 09-29-2008, 05:12 PM   #1
brianpbarnes
Member
 
Registered: Dec 2005
Posts: 143

Rep: Reputation: 15
Is it possible to manufacture a mysql.sock socket file MySQL will like?


Hi,

I have seen the question of how to create a mysql.sock file asked dozens of times on many Linux forums. Nobody has ever answered it directly. Does anybody know? It appears to be a closely guarded secret.

One helpful person made a vague reference to mknod and I did RTFM. There are a lot of parameters which I am unfamiliar with.

How does one do:
mksocket /var/lib/mysql/mysql.sock ??

Background:
=================

I am running Suse 11 with mysql installed from yast and trying to restore a number of databases from a dead machine. I have all of the MYD, MYI and frm files. I copied them (cp) to a new directory, set the datadir in /etc/my.cnf and started mysql. Unfortunately, I failed to set the permissions to let mysql read the user.MYD, MYI and frm files.

When I started the mysql service, it ate its own socket file which used to live in /var/lib/mysql and failed to create a new one.

There really used to be a socket file. From my shell history:
vulcan:/var/lib/mysql # ll
total 20572
-rw-rw---- 1 mysql mysql 5242880 Sep 29 05:19 ib_logfile0
-rw-rw---- 1 mysql mysql 5242880 Sep 21 04:36 ib_logfile1
-rw-rw---- 1 mysql mysql 10485760 Sep 29 04:25 ibdata1
drwx------ 2 mysql mysql 4096 Sep 21 04:36 mysql
srwxrwxrwx 1 mysql mysql 0 Sep 29 05:19 mysql.sock


My new data directory from /etc/my.cnf
# The MySQL server
[mysqld]
datadir = /rr/mysql

Here's what happened when I (stupidly) started mysql with the wrong file permissions:
vulcan:/rr/mysql/data/mysql # /etc/rc.d/mysql start
Creating MySQL privilege database...
Installing MySQL system tables...
OK
Filling help tables...
OK
PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:
/usr/bin/mysqladmin -u root password 'new-password'
/usr/bin/mysqladmin -u root -h vulcan.fractasia password 'new-password'

Alternatively you can run:
/usr/bin/mysql_secure_installation
.........

Here's what I see now when I try to start mysql:
vulcan:/var/lib/mysql # /etc/rc.d/mysql start
Starting service MySQL warning: /var/lib/mysql/mysql.sock didn't appear within 30 seconds


How do I make mysql.sock "appear". Abra Cadabra!

Thank you,

BrianP

P.S. I did reinstall mysql from YAST. YAST -> start_service -> mysql returns a zero return code but `ls -elf | grep mysql` confirms that no server got started.
 
Old 09-29-2008, 05:39 PM   #2
brianpbarnes
Member
 
Registered: Dec 2005
Posts: 143

Original Poster
Rep: Reputation: 15
mysql_install_db fails to create mysql.sock file?

Hi,
I am trying to reinstall mysql from scratch. YAST -> software -> mysql -> update does nothing. The mysql_install_db file usually works.


vulcan:/var/lib/mysql # mysql_install_db
Installing MySQL system tables...
OK
Filling help tables...
OK
PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:
/usr/bin/mysqladmin -u root password 'new-password'

....

vulcan:/rr/mysql # /usr/bin/mysqladmin -u root password XXXXXXXXX
/usr/bin/mysqladmin: connect to server at 'localhost' failed
error: 'Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)'
Check that mysqld is running and that the socket: '/var/lib/mysql/mysql.sock' exists!

The socket file does not exits. I can only find cups, smlrpc and xen-api sockets searching from root.

Does anybody know where to find a mk_sock utility?

Thank you,

BrianP
 
Old 09-29-2008, 06:07 PM   #3
ilikejam
Senior Member
 
Registered: Aug 2003
Location: Glasgow
Distribution: Fedora / Solaris
Posts: 3,109

Rep: Reputation: 97
Hi.

The mysqld binary creates the socket.

Make sure /var/lib/mysql has rwx rights set for whatever user is specified as user= in my.cnf .
Also, make sure socket=/var/lib/mysql/mysql.sock is present in my.cnf .

Dave

Last edited by ilikejam; 09-29-2008 at 06:08 PM.
 
Old 09-29-2008, 07:29 PM   #4
brianpbarnes
Member
 
Registered: Dec 2005
Posts: 143

Original Poster
Rep: Reputation: 15
/etc/rc.d/mysql start __EATS__ mysql.sock file?

Hi,
Trying once again to get mysql to use my old user and database files. I deleted it in YAST, reinstalled it and it came back to life.

I stopped the daemon, changed the basedir in the /etc/my.cnf file and restarted the daemon. Again, it ate its own mysql.sock file.

It really was running and /var/lib/mysql/mysql.sock file existed.
vulcan:/rr/mysql # ps -elf | grep mysql
0 S brianp 7954 5088 0 80 0 - 3635 wait 04:24 ? 00:00:00 /bin/sh /usr/bin/mysql-administrator
0 S brianp 7958 7954 0 80 0 - 95899 sys_po 04:24 ? 00:00:02 /usr/bin/mysql-administrator-bin
4 S root 18302 1 0 80 0 - 3327 wait 08:00 ? 00:00:00 /bin/sh /usr/bin/mysqld_safe --mysqld=mysqld --user=mysql --pid-file=/var/lib/mysql/mysqld.pid --socket=/var/lib/mysql/mysql.sock --datadir=/var/lib/mysql
4 S mysql 18351 18302 0 80 0 - 35528 select 08:00 ? 00:00:00 /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --user=mysql --pid-file=/var/lib/mysql/mysqld.pid --skip-external-locking --port=3306 --socket=/var/lib/mysql/mysql.sock
0 R root 18373 4374 0 80 0 - 1071 - 08:00 pts/0 00:00:00 grep mysql

<< edit /etc/my.cnf file to change basedir >>

vulcan:/var/lib/mysql # /etc/rc.d/mysql start
Starting service MySQL warning: /var/lib/mysql/mysql.sock didn't appear within 30 seconds

I want to use all my old users and all of my old databases, but not on /var which is located on my (small) system drive. My system drive has nothing but the OS on it for backup purposes. I keep all of my data files on any other drive.

The YAST install method gives you no option as to where to put the database files.

The socket file spec in the my.cnf file did not change, just the basedir. Why is mysql destroying the mysql.sock file?

Thank you,

BrianP
 
Old 09-29-2008, 07:48 PM   #5
ilikejam
Senior Member
 
Registered: Aug 2003
Location: Glasgow
Distribution: Fedora / Solaris
Posts: 3,109

Rep: Reputation: 97
Ah.

I don't think it's the socket that's the problem. I think the presence of the socket is how the startup script tells whether or not the DB started up OK (but I could be wrong). On Fedora, for example, when mysql stops it always deletes its socket.

Check /var/log/mysqld.log for errors - startup problems should be in there.

Dave
 
Old 09-29-2008, 08:38 PM   #6
brianpbarnes
Member
 
Registered: Dec 2005
Posts: 143

Original Poster
Rep: Reputation: 15
The real root cause of the mysql.sock error!

Dave,
Digging a bit deeper as you suggested, I did find this error in the /var/log/mysqld.log:
080929 08:07:55 mysqld started
080929 8:07:55 [ERROR] Can't find messagefile '/rr/mysql/share/mysql/english/errmsg.sys'
080929 8:07:55 [ERROR] Aborting

This caused an abort on the mysql daemon startup. The safe_mysqld script then nuked the socket file. Then I got the true but misleading error about the sockets' non-existence.

My old database (from 3 years ago) and the latest appear to not be entirely compatible.

Instead of trying to graft my old datadir onto the new installation, I instead just copied my .frm files (which can not be linked???) to newly made database directories and linked the .MYD and .MYI files into the new database dirs.

I wrote a tiny Perl script to speed things up (since I have 491 files to manipulate.

Thanks for the pointer. I have my old databases and users up and running. Ye Ha! Below in the script.

BrianP

=====================================================================
The Gory Details:

NOTE: Use you own peril. Debug before executing. Written by halfwit
hacker. BEWARE!


#!/usr/bin/perl -w

&link_mysql();

sub link_mysql() {
$datdir = "/rr/mysql/data";
$mysql = "/var/lib/mysql"; # Location mysql installs dbs in.
$cmd = "find $datdir -name '*.MYD' -o -name '*.MYI' -o -name '*.frm'";
print("Cmd = \"$cmd\".\n");
@file = `$cmd`;
chomp @file; # Nuke nasty newlines.
printf("Found %d DB files.\n", scalar @file);
foreach $file (@file) {
# Don't monkey with the mysql database.
next if $file =~ m/data\/mysql/;
# Expect: /rr/mysql/data/bbdb/bpb_picblob.MYI
# link to /var/lib/mysql/bbdb/*
($dir = $file) =~ s/^(.*)\/.*/$1/; # Nuke base file name.
($base = $file) =~ s/^.*\///; # Nuke path.
($mdir = $dir) =~ s/^$datdir\///;
$mdir = "$mysql/$mdir";
unless(-d "$mdir" || defined $mdir{$mdir}) {
$mdir{$mdir} = $mdir; # For testing. Only mkdir once.
# Create the new dir and set ownership/group/perms.
$cmd = "mkdir $mdir; chown brianp.mysql $mdir; chmod 770 $mdir";
print("Cmd = \"$cmd\".\n");
`$cmd`;
}
if($file =~ m/\.frm/) {
$cmd = "cp $file $mdir";
}
elsif($file =~ m/\.MYD|\.MYI/) {
$cmd = "ln -s $file $mdir/$base"
}
print("Cmd = \"$cmd\".\n");
`$cmd`;
}
$cmd = "chown -R brianp.mysql `find $mysql -name '*.frm'`";
print("Cmd = \"$cmd\".\n");
$cmd = "chmod -R 660 `find $mysql -name '*.frm'`";
print("Cmd = \"$cmd\".\n");
}
 
Old 04-12-2012, 05:01 AM   #7
hillazw
LQ Newbie
 
Registered: Sep 2011
Posts: 1

Rep: Reputation: Disabled
Thumbs up pindura

Problem: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)

Solution: root$ lsof -i tcp;3306 (this is to show the processes running)

mysqld 15885 mysql 203u IPv4 58195527 0t0 TCP Gre

kill -9 15885

rcmysql restart

this solved my problem and the mysql.sock was restored.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock welery Linux - Software 19 03-06-2014 07:19 AM
Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' mohadesz Linux - Server 3 03-15-2008 05:06 AM
Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' mathimca05 Linux - Newbie 2 10-17-2007 02:04 AM
Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) Splenden Linux - Server 1 04-05-2007 08:34 PM
Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) sunlinux Linux - Software 1 11-07-2006 12:08 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 10:58 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration