Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I've occasionally lost my config file "/etc/mysql/my.cnf", and want to restore it. The file belongs to package mysql-common which is needed for some vital functionality so I can't just purge && install it: the dependencies would be also uninstalled (or if I can ignore them temporarily, they won't be working).

Is there a way to restore the config file from a package without un-ar-ing the package file?

dpkg-reconfigure mysql-common did not restore it.

share|improve this question
    
i've always just extracted the package files with 7zip (7z x /path/to/foo.deb, then 7z x data.tar.gz).... –  quack quixote Nov 9 '09 at 6:26
    
Personally, I like to setup something like etckeeper on my system right after I install. That way all changes and versions of configuration files get stored. (serverfault.com/questions/13091/advice-on-storing-etc-in-a-vcs) –  Zoredache Nov 9 '09 at 6:54
4  
And this, kids, is why we have backups... –  womble Nov 9 '09 at 7:08
    
@womble: actually, the situation is slightly different: i have a config file, but it's modified by me. I was not using conf.d folders, and when the package maintainer update it, upgrade process becomes really keen of displaying "config file modified" messages :) The reason is not that important to mention, so I decided to simplify my question –  kolypto Nov 9 '09 at 13:19

5 Answers 5

up vote 33 down vote accepted

dpkg -i --force-confmiss mysql-common.deb will recreate any missing configuration files, ie /etc/mysql/my.cnf in your case.

share|improve this answer
3  
Thanks! On Ubuntu, it was sudo dpkg --force-confmiss -i /var/cache/apt/archives/mysql-common*.deb –  kolypto Nov 9 '09 at 13:26

In Debian Squeeze — at least —, we also can do it this way, after su — or sudo for Ubuntu —

aptitude install -o Dpkg::Options::=--force-confmiss mysql-server

This will care for the dependencies of mysql-server and reset all the missing conf files of the lot, including mysql-common. Conflicting (remaining) files will be prompted out to be kept or reset.

Unfortunately, there is a bug in aptitude, and

aptitude purge -o Dpkg::Options::=--force-all mysql-server

will not work. So we have to do it one by one with

dpkg --force-all --purge  mysql-common  mysql-server  mysql-client …

This will remove any config file, original or modified, but custom files will be preserved, with an onscreen message. Note, by the way, that dpkg also recognizes --force-confnew and --force-confold options.

To get mysql-server dependencies' list print on screen :

aptitude --simulate remove mysql-server
share|improve this answer
    
Thank you! Works excellent in Ubuntu 12.04 –  Hendy Irawan May 5 '12 at 20:24

You can find default mysql config files in /usr/share/doc/mysql-server-5.0/examples/ or similar. That may be all that you need unless you have some really special/esoteric configurations enabled.

share|improve this answer

In my /etc/mysql/ directory, I have a my.cnf.orig file which contains the original contents of my.cnf.

I'm not sure where /etc/mysql/my.cnf.orig came from - that is, whether I created it, or the installation of mysql did it. I remember checking at one time that it was exactly the same as my.cnf

If you have such a thing, and no my.cnf you can copy one to the other.

sudo cp /etc/mysql/my.cnf.orig /etc/mysql/my.cnf

In any case, it's a simple text file of 3897 bytes and you could copy and paste from a generic Mysql configuration file.

It will be a good idea once you restore your /etc/mysql/my.cnf to make a copy so you can restore it easily in future.

share|improve this answer
    
I usually make a backup of original-install configuration files by copying them to /path/to/foo.conf.orig ... if these are automatically installed, they're created when apt-get is installing a new version and detects you've altered the original configuration file. –  quack quixote Nov 9 '09 at 6:10
    
Hmm, the more I think about it, the more it seems I created /etc/mysql/my.cnf.orig as a backup which wouldn't be overwritten by a fresh installation. But, putting it somewhere entirely different is a good idea. –  pavium Nov 9 '09 at 6:14
    
I was trying to be generic; for my.cnf I would copy it to /etc/mysql/my.cnf.orig. Then, naturally, make a tarball backup of /etc. :) –  quack quixote Nov 9 '09 at 6:19

You need to reinstall mysql-common with this command:apt-get install --reinstall mysql-common

share|improve this answer
    
Does that actually restore missing configuration files? –  poolie Oct 24 '13 at 8:44
    
No, that doesn't work. –  chrishiestand Jun 7 at 0:25

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.