Is it possible to manufacture a mysql.sock socket file MySQL will like?
Linux - ServerThis forum is for the discussion of Linux Software used in a server related context.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
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?
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 .
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?
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,
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");
}
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.