0

After having had my huge hard drive crash (which was related to a LVM update of Debian, not the hardware) I am facing the next problem: I try to reinstall mysql after that crash and did a dpkg --ignore-depends ... --purge mysql-... on the machine. No more MySQL, only dependent packages:

kermit:~# dpkg -l | grep -i mysql
ii  courier-authlib-mysql
ii  libdbd-mysql-perl
ii  libpam-mysql
ii  php5-mysql
ii  postfix-mysql
ii  proftpd-mod-mysql

No mysql process running, no directories like /var/lib/mysql, no nothing. Basically (that's what I think) a clean install of mysql. But no, it is not that easy. Step by step:

kermit:/var/cache/apt/archives# ls mysql-*
mysql-client_5.1.43-0.dotdeb.1_all.deb       mysql-common_5.1.43-0.dotdeb.1_all.deb  mysql-server-5.1_5.1.43-0.dotdeb.1_i386.deb
mysql-client-5.1_5.1.43-0.dotdeb.1_i386.deb  mysql-server_5.1.43-0.dotdeb.1_all.deb
kermit:/var/cache/apt/archives# dpkg -i mysql-*.deb
[...]
Stopping MySQL database server: mysqld.
100204 19:37:47 [Note] Plugin 'FEDERATED' is disabled.
100204 19:37:47  InnoDB: Started; log sequence number 0 44233
ERROR: 1146  Table 'mysql.user' doesn't exist
100204 19:37:47 [ERROR] Aborting

100204 19:37:47  InnoDB: Starting shutdown...
100204 19:37:53  InnoDB: Shutdown completed; log sequence number 0 44233
100204 19:37:53 [Note] /usr/sbin/mysqld: Shutdown complete

Starting MySQL database server: mysqld . . . . . . . . . . . . . . failed!
invoke-rc.d: initscript mysql, action "start" failed.
[...]

Boom! Not good. Only empty files in /var/log/mysql/ and nothing in /var/log/mysql.*. But behold, there's /var/log/daemon.log:

Feb  4 19:38:13 kermit mysqld_safe: Starting mysqld daemon with databases from /var/lib/mysql
Feb  4 19:38:13 kermit mysqld: 100204 19:38:13 [Note] Plugin 'FEDERATED' is disabled.
Feb  4 19:38:13 kermit mysqld: /usr/sbin/mysqld: Table 'mysql.plugin' doesn't exist
Feb  4 19:38:13 kermit mysqld: 100204 19:38:13 [ERROR] Can't open the mysql.plugin table. Please run mysql_upgrade to create it.
Feb  4 19:38:13 kermit mysqld: 100204 19:38:13  InnoDB: Started; log sequence number 0 44233
Feb  4 19:38:13 kermit mysqld: 100204 19:38:13 [ERROR] Can't start server : Bind on unix socket: Permission denied
Feb  4 19:38:13 kermit mysqld: 100204 19:38:13 [ERROR] Do you already have another mysqld server running on socket: /var/run/mysqld/mysqld.sock ?
Feb  4 19:38:13 kermit mysqld: 100204 19:38:13 [ERROR] Aborting
Feb  4 19:38:13 kermit mysqld: 
Feb  4 19:38:13 kermit mysqld: 100204 19:38:13  InnoDB: Starting shutdown...
Feb  4 19:38:18 kermit mysqld: 100204 19:38:18  InnoDB: Shutdown completed; log sequence number 0 44233
Feb  4 19:38:18 kermit mysqld: 100204 19:38:18 [Note] /usr/sbin/mysqld: Shutdown complete
Feb  4 19:38:18 kermit mysqld: 
Feb  4 19:38:18 kermit mysqld_safe: mysqld from pid file /var/run/mysqld/mysqld.pid ended
Feb  4 19:38:27 kermit /etc/init.d/mysql[9108]: 0 processes alive and '/usr/bin/mysqladmin --defaults-file=/etc/mysql/debian.cnf ping' resulted in
Feb  4 19:38:27 kermit /etc/init.d/mysql[9108]: ^G/usr/bin/mysqladmin: connect to server at 'localhost' failed
Feb  4 19:38:27 kermit /etc/init.d/mysql[9108]: error: 'Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)'
Feb  4 19:38:27 kermit /etc/init.d/mysql[9108]: Check that mysqld is running and that the socket: '/var/run/mysqld/mysqld.sock' exists!
Feb  4 19:38:27 kermit /etc/init.d/mysql[9108]: 

Well, indeed no files there:

kermit:~# ls -larth /var/lib/mysql/ /var/lib/mysql/mysql/
/var/lib/mysql/mysql/:
insgesamt 0
drwx------ 2 mysql mysql  48  4. Feb 19:38 .
drwx------ 3 mysql mysql 192  4. Feb 19:38 ..

/var/lib/mysql/:
insgesamt 21M
-rw-rw----  1 mysql mysql 5,0M  4. Feb 19:35 ib_logfile1
-rw-r--r--  1 mysql mysql    0  4. Feb 19:37 debian-5.1.flag
drwxr-xr-x 42 root  root  1,1K  4. Feb 19:37 ..
drwx------  2 mysql mysql   48  4. Feb 19:38 mysql
drwx------  3 mysql mysql  192  4. Feb 19:38 .
-rw-rw----  1 mysql mysql 5,0M  4. Feb 19:38 ib_logfile0
-rw-rw----  1 mysql mysql  10M  4. Feb 19:38 ibdata1

Some more dirs:

kermit:/etc/mysql# ls -larth /var/run/mysqld/
insgesamt 512
drwxr-xr-x 13 root  root 672  4. Feb 19:35 ..
drwxr-xr-x  2 mysql root  48  4. Feb 19:35 .

kermit:~# ls -larth /var/log/mysql*
-rw-r----- 1 mysql adm  0  4. Feb 19:37 /var/log/mysql.log
-rw-r----- 1 mysql adm  0  4. Feb 19:37 /var/log/mysql.err

/var/log/mysql:
insgesamt 4,0K
drwxr-xr-x 15 root  root 4,3K  4. Feb 19:35 ..
drwxr-s---  2 mysql adm    48  4. Feb 19:35 .

Config:

kermit:/etc/mysql# grep -v ^# my.cnf  | grep -v "^$"
[client]
port        = 3306
socket      = /var/run/mysqld/mysqld.sock
[mysqld_safe]
socket      = /var/run/mysqld/mysqld.sock
nice        = 0
[mysqld]
user        = mysql
pid-file    = /var/run/mysqld/mysqld.pid
socket      = /var/run/mysqld/mysqld.sock
port        = 3306
basedir     = /usr
datadir     = /var/lib/mysql
tmpdir      = /tmp
language    = /usr/share/mysql/english
skip-external-locking
bind-address        = 127.0.0.1
key_buffer      = 16M
max_allowed_packet  = 16M
thread_stack        = 192K
thread_cache_size       = 8
myisam-recover         = BACKUP
query_cache_limit   = 1M
query_cache_size        = 16M
expire_logs_days    = 10
max_binlog_size         = 100M
[mysqldump]
quick
quote-names
max_allowed_packet  = 16M
[mysql]
[isamchk]
key_buffer      = 16M
!includedir /etc/mysql/conf.d/

Anyone any idea?

Thanks!

DaDaDom
  • 532
  • 6
  • 16
  • It was a permission problem, but not mysql specific: the /var had the wrong permission, 700 instead of 755. Fixing that also fixed mysql. – DaDaDom Feb 05 '10 at 08:11

3 Answers3

0

move your /var/lib/mysql/ to /var/lib/mysql.bad and retry your install. dpkg will maybe reinstall all the databases.

You should maybe remove the packages because re-install...

Dom
  • 6,628
  • 1
  • 19
  • 24
0

I had this issue after updating mysql.

I did:

mysqlcheck --all-databases --repair -u root -p
mysql_upgrade -u root -p

But in your case, you may have to empty /var/lib/mysql/* before reinstalling, as it keeps transaction logs inside

Mathieu Chateau
  • 3,175
  • 15
  • 10
0

There are a couple of approaches to dealing with this:

Use a generic method of setting up the mysql server, according to the mysql documentation, but accommodating any Debian specificity. It will involve running mysql_install_db (probably with --user= and --datadir= just in case) and setting permissions on the relevant directories before you attempt to start the service, at least.

OR

Try to fix the Debian-created installation, probably by starting over, ensuring that everything is out of the way and no related processes are left running and re-obtaining just the packages you need and their dependencies. I'm not a Debian person, but I'd be inclined to let your package manager do the dependency resolution rather than handing a series of .debs to dpkg. (apt-get install mysql-server, IIRC).

HopelessN00b
  • 53,385
  • 32
  • 133
  • 208
dotplus
  • 1,220
  • 7
  • 12
  • The directory permissions were the thing: I already had thought about those but I never checked the upper levels. The `/var` directory had the wrong permission, 700 instead of 755. After fixing that, everything worked without a glitch! Marking this as the correct answer. – DaDaDom Feb 05 '10 at 08:08