0

For some reason my /var/run/ dir on debian6 had it's chown and chmod changed. Problem is from what? Outcome is that mysql fails. I'm guessing the easiest way to fix is to reinstall MySQL. (Previously this LAMP was running fine.)

However, I have established databases and tables and don't want to lose them. Since mysql is not running I can't backup (correct?).

I just want to confirm that:

1). if I reinstall, I won't loose my databases.

2). apt-get install mysql-server mysql-client is the correct command to use.

Thanks.

EDIT:

/var/log/syslog output when running /etc/init.d/mysql start:

mysqld_safe: Starting mysqld daemon with databases from /var/lib/mysql
mysqld: 130109 10:44:10 [Note] Plugin 'FEDERATED' is disabled.
mysqld: #007/usr/sbin/mysqld: Can't find file: './mysql/plugin.frm' (errno: 13)
mysqld: 130109 10:44:10 [ERROR] Can't open the mysql.plugin table. Please run mysql_upgrade to create it.
mysqld: 130109 10:44:10 InnoDB: The InnoDB memory heap is disabled
mysqld: 130109 10:44:10 InnoDB: Mutexes and rw_locks use GCC atomic builtins
mysqld: 130109 10:44:10 InnoDB: Compressed tables use zlib 1.2.3.4
mysqld: 130109 10:44:10 InnoDB: Using Linux native AIO
mysqld: 130109 10:44:10 InnoDB: Initializing buffer pool, size = 128.0M
mysqld: 130109 10:44:10 InnoDB: Completed initialization of buffer pool
mysqld: 130109 10:44:10  InnoDB: Operating system error number 13 in a file operation.
mysqld: InnoDB: The error means mysqld does not have the access rights to
mysqld: InnoDB: the directory.
mysqld: InnoDB: File name ./ibdata1
mysqld: InnoDB: File operation call: 'create'.
mysqld: InnoDB: Cannot continue operation.
mysqld_safe: mysqld from pid file /var/run/mysqld/mysqld.pid ended
/etc/init.d/mysql[4531]: 0 processes alive and '/usr/bin/mysqladmin --defaults-file=/etc/mysql/debian.cnf ping' resulted in
/etc/init.d/mysql[4531]: #007/usr/bin/mysqladmin: connect to server at 'localhost' failed
/etc/init.d/mysql[4531]: error: 'Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)'
/etc/init.d/mysql[4531]: Check that mysqld is running and that the socket: '/var/run/mysqld/mysqld.sock' exists!
/etc/init.d/mysql[4531]: 
3
  • What is the error message when you try to start mysql? It will be much better to fix it than to re-install.
    – Khaled
    Jan 9, 2013 at 15:23
  • 1
    Agreed, much better to fix and find what changed the permissions. You can change the ownership back again using chown/chmod commands. When you do ls -la /var/run what has the ownership been changed to?
    – Sc0rian
    Jan 9, 2013 at 15:25
  • changed to a user and www-data. I tried changing back to root:root. Even opened up /var/run/mysqld/ to 777 to no avail.
    – dmayo
    Jan 9, 2013 at 15:43

3 Answers 3

1

it would be good to find out what really has happened; you can take a look at any other computer with the same OS and mysql installed and use chmod and chown to restore the expected rights and ownership.

quick look at a random debian server tells me:

root@serv:/var/run# ls -la /var/run/mysqld/*
total 12
drwxr-xr-x  2 mysql root  4096 Oct 24 13:29 .
drwxr-xr-x 14 root  root  4096 Jan  9 01:28 ..
-rw-rw----  1 mysql mysql    5 Oct 24 13:29 mysqld.pid
srwxrwxrwx  1 mysql mysql    0 Oct 24 13:29 mysqld.sock

so try first:

chown mysql:mysql /var/run/mysqld/*
chown mysql:root /var/run/mysqld 

and appropriate chmods if needed

if you decide to re-install - be on the safe side:

  • try to shut down cleanly mysql - if needed using regular kill and waiting
  • copy all the data files [not just few - eg not just the directory of one database; it might not be enough for innodb]
  • copy all the config files

only then try to uninstall + reinstall

1
  • The issue was permissions. I did have another install to compare to, and kept going back to /var/log/syslog and seeing where the errors where thrown. In addition to /var/run, there were permission issues in /var/lib/mysql. chown mysql:mysql -R /var/lib/mysql chmod 660 -R /var/lib/mysql
    – dmayo
    Jan 9, 2013 at 17:17
1

A plain reinstall as you propose is guaranteed not to help in this case, as none of the scripts which effect these permissions would be changed by a straight reinstall. Some things to note: /var/run is now a tmpfs mounted at runtime. The permissions are set when it is mounted. from /etc/init.d/mountkernfs.sh:

domount tmpfs "" /var/run varrun -omode=0755,nosuid$RUN_OPT

So you should have /var/run as root:root and chmod 0775.

Another thing to note is that /var/run is empty at every boot. Any changes you make to /var/run will be gone during a reboot.

When the mysql init runs, it will make sure /var/run/mysqld exists. If it doesn't, it will be re-created with the correct permissions. from /etc/init.d/mysql:

test -e /var/run/mysqld || install -m 755 -o mysql -g root -d /var/run/mysqld

So if you haven't yet rebooted, you could try /etc/init.d/mysql stop && rm -r /var/run/mysqld && /etc/init.d/mysql start.

If you have rebooted, then something else is wrong. Perhaps you have an old version of the mysql init script (this can happen if you modified it, then upgraded, the upgrade would not (by default) overwrite your changes to the init script. You can check if you have an old version of the mysql init script by asking dpkg what the current packaged md5 of the script is:

# dpkg -s mysql-server-5.1 | grep init.d
/etc/init.d/mysql ea6d050ac82ed69d01970f9b95ab9b9d

then compare that to the md5sum on your filesystem:

# md5sum /etc/init.d/mysql
ea6d050ac82ed69d01970f9b95ab9b9d  /etc/init.d/mysql
4
  • Thanks Stew. Last time I looked at the website, all was ok. Now (literally months later, I'm getting these issues). mysql-server-5.5 /etc/init.d/mysql 7ecd4a6dfd5fbc57f44d79b1e5223f2c 7ecd4a6dfd5fbc57f44d79b1e5223f2c /etc/init.d/mysql
    – dmayo
    Jan 9, 2013 at 16:02
  • 5.5 isn't in debian 6. Did you get this from the unreleased testing/unstable repositories? or from some third party like bpo? (I'd recommend against any of these, btw). In any case, everything I said above should still hold true.
    – stew
    Jan 9, 2013 at 16:06
  • I have added these to many of my servers running D6 and have had no issues for well over a year (18 months probably): deb http://dotdeb.mirror.borgnet.us/ stable all deb-src http://dotdeb.mirror.borgnet.us/ stable all
    – dmayo
    Jan 9, 2013 at 16:12
  • no issues, until today, i guess…
    – stew
    Jan 9, 2013 at 18:29
0

I would avoid changing any permissions on the /var/run directory at the moment, but only change the /var/run/mysqld path.

You must make sure the mysql user can access and write to the mysqld directory. The first command assigns the correct group and the second command allows that group to write to that path.

sudo chgrp mysql /var/run/mysqld/

sudo chmod g+w /var/run/mysqld/

2
  • mysql will create the directory if it doesn't already exist, and those are the wrong group/permissions. better to just remove /var/run/mysqld and service mysql restart
    – stew
    Jan 9, 2013 at 15:40
  • I removed mysqld dir and ran service mysql restart and it did recreate the dir with mysql:root and 755. Still failing a restart.
    – dmayo
    Jan 9, 2013 at 15:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .