Is it possible that I can recover data from mySQL ubuntu server? I needed to change a disk in my server so I installed a new ubuntu, but in my old disk I still have files in /var/lib/mysql/ where my old databases are. Is it possible to recover a database from files? How to do it? Just copying database from old disk /var/lib/mysql/ to a new server disk? Will it work instantly or I need to create first empty databases in phpmyadmin?
If the data is still here it´s promising for your recovery.
1/. You need to back up this /var/lib/mysql directory
sudo cp -R -p /var/lib/mysql /var/lib/mysql.back
2/. Reinstall completely mysql (it will erase the mysql folder)
sudo apt-get install mysql-server
3/. Erase the new data folder with your old one
sudo cp -R -p /var/lib/mysql.bask /var/lib/mysql
If you´re using exactly same directories it should work like that.
Related
I did an update from Mysql 5.5 to 8.0 in a Centos 6 server without dumping the databases to a .sql file, I just copied the /var/lib/mysql directory to another location.
Now if I try to load mysqld service it crashes.
Being naive I deleted all the content of /var/lib/mysql and installed the service again, now it runs but now I do not know how to manually import the DB files to the directory (copy & paste of the folder does not work) in order to do a check of the DB and/or repair it.
rysnc should likely already be installed, but if it isn't you would:
sudo yum install rsync
Then
#make sure mysql isn't running
sudo service mysqld stop
#double check that there is no MySQL PID running
sudo ps aux | grep mysql
#move the new MySQL 8.0 data files out of the way
sudo mv /var/lib/mysql /var/lib/mysql.bak
#copy the original data files back to /var/lib/mysql
#note that the trailing / is required for both paths
sudo rsync -av /path/to/original/mysql/db/files/ /var/lib/mysql/
#change user and group ownership to mysql
sudo chown -R mysql:mysql /var/lib/mysql
#start MySQL
sudo service mysqld start
#run mysql_upgrade, replace {usernamehere} with the actual username
sudo mysql_upgrade -u {usernamehere} -p
Update:
You will need to downgrade the binaries to 5.5. Take a backup of each database once MySQL is running again and then upgrade in the following order:
5.6
5.7
8.0
You will need to run mysql_upgrade after each upgrade.
I recently upgraded my Mac to Mavericks and am having trouble getting MySQL to work.
I removed my previous MySQL installation per instructions found on the web, then downloaded the DMG file and ran the installer - after which, I was able to get it running, but was not able to log in.
I noticed the installer created a /usr/local/mysql/ directory which points to /usr/local/mysql-5.6.19-osx10.7-x86_64
I then replaced the /usr/local/mysql-5.6.19-osx10.7-x86_64/data directory with the old data directory, and now I can't start MySQL.
I get the error: "warning the /usr/local/mysql/data directory is not owned by the 'mysql' or '_mysql' user" and can no longer start MySQL.
I tried to change permissions of the directory with the following without luck:
sudo chmod -R 777 /usr/local/mysql/
sudo chmod -R 777 /usr/local/mysql-5.6.19-osx10.7-x86_64
sudo chown -R mysql:mysql /usr/local/mysql/data
sudo chown -R mysql:mysql /usr/local/mysql/data
sudo chown -R _mysql /usr/local/var/mysql
chown: /usr/local/var/mysql: No such file or directory
sudo chmod -R o+rwx /usr/local/var/mysql
chmod: /usr/local/var/mysql: No such file or directory
I did modify the plist file and cnf files as described here:
https://community.jboss.org/blogs/tedjones/2014/05/02/getting-mysql-up-and-running-after-upgrading-to-mavericks?_sscc=t
Not sure what else to do.
I was able to solve this problem. You just have to be meticulous when you run the install.
Please note that upgrading from Mac OS 10.8 or older to Mavericks will cause MySQL to no longer run (in other words, "Are you sure you want to upgrade to Mavericks?")
With MySQL non-functional, I decided to reinstall MySQL and upgrade to the newest version.
I followed the instructions in the link above with the following words of advice:
Backup your MySQL data directory before doing anything.
The MySQL data file is located in the /usr/local/mysql-5.6.19-osx10.7-x86_64/data directory (or similar, depending on what version you have installed).
BACK IT UP!
Make sure you stop MySQL before installing the upgraded version.
If your plist file has keepalive set to True, every time you try to quit MySQL, it will quit (or will appear to quit) but then immediately restart.
If you want to use the Preference Pane to start and stop MySQL, make sure you set keepalive in the .plist file to false, otherwise the Preference Pane won't work.
I tried to kill the plist process after making the change, but it wouldn't work. I just restarted my Mac and from that point on, I was able to start and stop MySQL from Terminal or the Preference Pane when needed.
Occasionally, the Preference Pane failed to start/stop MySQL. In that case, I would enter the start/stop command in Terminal and it worked.
Start MySQL:
sudo /usr/local/mysql/support-files/mysql.server start
Stop MySQL:
sudo /usr/local/mysql/support-files/mysql.server stop
Download the .dmg file from MySQL and run the installer.
I did try downloading the .tar file, and it may have worked - but on my second try, I chose the .dmg file and everything went smoothly.
If you try to start MySQL at this point, it should run without a problem.
Remember, since at this point you have a clean install of MySQL, you can log in with the username 'root' and password 'no password' (leave password blank).
Please note that if you start MySQL from the terminal, you will get more information than trying from the Preference Pane, so if you are having difficulty, make sure you stop and start MySQL from Terminal. You will get some error messages that you use to troubleshoot the problem.
You can modify the .cnf and .plist files as mentioned in the installer instructions above (as long as you stop MySQL before making any changes).
Typically you would copy and paste the information from the web page (mentioned above) into the .cnf file. It is pretty straight forward, but double and triple check that the copy and paste did not miss a character or two. This happened to me while pasting the code into the .cnf file (the first two characters were missing) and it took me hours to figure this out - which prevented MySQL from starting.
If the changes to the .cnf or .plist file don't seem to take effect, restart the Mac (easier than restarting the process).
Moving your data.
My install created a /usr/local/mysql/ alias or symbolic link to the /usr/local/mysql/mysql-5.6.19-osx10.7-x86_64 directory.
The /usr/local/mysql/data directory (which is actually the /usr/local/mysql/mysql-5.6.19-osx10.7-x86_64/data directory - remember, it's a symbolic link) is where your data resides.
You want a backup of your previous data directory. If you forgot to back that up before running the installer, and you have a Time Machine backup, you can retrieve it.
The easiest way to do this is to open the /usr/local/ directory (From the Finder and choose "Go to Folder" from the Go menu) and with the /usr/local/ directory open in the Finder, choose Enter Time Machine from the Time Machine menu. Go back to the last known date that has your previous MySQL installation. Find the folder of your previous MySQL install and open the data directory.
You have to choose all the files from the exact same point in time. You can't choose one data folder from one day and one data folder from another (I actually did this and spent a lot of time trying to figure out why one of my data tables were visible in Sequel Pro but wouldn't work). After a while, I finally figured out that everything absolutely has to be from the exact same point in time.
You can copy files while in Time Machine by right-clicking on them. Choose all your data folders (with the .ibd and .frm files in them) PLUS all the ib_logfiles (ib_logfile0, ib_logfile1), auto.cnf, and the .pid file. Basically copy everything in the mysql data folder EXCEPT the mysql, performance_schema, and test directories.
Exit Time Machine.
Make sure MySQL is stopped and then paste the data files into the /usr/local/mysql/data directory.
Set the privileges to the data directory.
In Terminal, enter:
sudo chown -R mysql:mysql /usr/local/mysql/data
Make sure NOT to use the chmod 777 command as some people online said it can damage things.
Now, start MySQL and you should have your data files from your previous MySQL install intact and functional. In addition, I did not have to reset any passwords for Sequel Pro. The Sequel Pro settings saved before the Mavericks upgrade worked.
I have a separate partition that holds both my www and mysql folders.
I have that partition set to automount at boot, and the apache2 starts fine, no errors.
However, when I just recently removed all traces of mysql-server-5.5, rebooted then restarted it, it would work normally.
But the second I make changes to my.cnf to point to /media/server/mysql, and try to start mysql then it error's out.
Here is the list of steps I have followed so far. Be advised, that Debian does not have apparmor, as far as I know, so I skipped that step.
Stop MySQL using the following command:
sudo /etc/init.d/mysql stop
Copy the existing data directory (default located in /var/lib/mysql) using the following command:
sudo cp -R -p /var/lib/mysql /newpath
edit the MySQL configuration file with the following command:
gedit /etc/mysql/my.cnf
Look for the entry for datadir, and change the path (which should be /var/lib/mysql) to the new data directory.
In the terminal, enter the command:
sudo gedit /etc/apparmor.d/usr.sbin.mysqld
Look for lines beginning with /var/lib/mysql. Change /var/lib/mysql in the lines with the new path.
Save and close the file.
Restart the AppArmor profiles with the command:
sudo /etc/init.d/apparmor reload
Restart MySQL with the command:
sudo /etc/init.d/mysql restart
Now login to MySQL, and you can access the same databases you had before.
from How to change MySQL data directory?
Although I also looked at the link here https://askubuntu.com/questions/137424/moving-mysql-datadir
My guess is that this is a permissions issue, but I could be wrong.
root#debian:~# chown -R mysql:mysql /media/server/mysql
root#debian:~# sudo /etc/init.d/mysql restart
[ ok ] Stopping MySQL database server: mysqld.
[FAIL] Starting MySQL database server: mysqld . . . . . . . . . . . . . . failed!
I'll admit I am still a newb at linux, so I may be doing things, that other's recommend, without really understanding what it is really doing.
It gives no details about why it is failing.
One other option, I may consider doing, is re-enable it to use the default data dir, and then just copy mysql files back from the partition.
But that denies the whole point of having a dedicated partition for webdev.
I appreciate any comments or efforts, thank you.
Instead of copying your original datadir (/var/lib/mysql), you should move it. It keeps better track on all metadata.
Insted of:
sudo cp -R -p /var/lib/mysql /newpath
use:
sudo mv /var/lib/mysql /newpath
or better save a copy of your original datadir and then move it, like this:
sudo cp -R -p /var/lib/mysql /var/lib/mysql.bak
sudo mv /var/lib/mysql /newpath
Then start mysql service, it should all go smoothly :)
Cheers!
I encountered the same problem, but after a short investigation.
I noticed that the mysql deamon failed because of the bin-logs.
So I edited the file "mysql-bin.index" in the datadirectory and updated the location of the bin files to the new datadirectory.
Now mysql did start without any issues.
I have a Rackspace VPS running CentOS that I can only access in Read Only rescue mode. How can I backup/restore MySQL using SSH and FTP with no access to mysql command line tools?
The reason for this is that the image used to build the server has an issue with Nova so Rackspace are unable to build from it. What I need to do is transfer all files onto a clean new machine.
I can access all files without issue, but I would also like to recover any MySQL database that were on the machine. However, MySQL will not run in the rescue mode Rackspace offer and I can't use these tools to make any kind of dump - I have SSH and FTP only. Can anyone hint as to how I can rescue/transfer my MySQL databases to the new machine?
Setup a new VPS with an identical version of mysql and transfer (scp/rsync/sftp) the raw database files in /var/lib/mysql and the mysql conf file (typically /etc/my.cnf) to the new server. Make sure the permissions of these files don't change on the new server. This wouldn't work without a third party utility (Percona Xtrabackup for example) if mysqld was running but since you cannot run mysqld in r/o mode anyways this is your best bet.
Example path is miliardowo
My old server was debian. New one is Ubuntu 14.04 LTS
Copy file from /var/lib/mysql/miliardowo to your server
Add permission in /var/lib/mysql/
chmod 700 miliardowo/
chmod 660 miliardowo/*
chmod g-s miliardowo/
chmod g-s miliardowo/*
chmod u-s miliardowo/
chmod u-s miliardowo/*
chown mysql:mysql miliardowo/
chown mysql:mysql miliardowo/*
updatedb
I test Drupal websites on my site locally on Mac using Phpmyadmin.
I recently had to to do a clean reinstall of my Mac. I have a full back up of my hardrive, but I'm not sure where to locate the databases in the back up and how to restore them.
Where does Phpmyadmin store the databases?
/usr/local/mysql/data
try it here
phpMyAdmin does not write any database files. It is a php client application which accesses a MySQL server.
On OSX the MySQL server creates its data files in /usr/local/mysql/data as far as I know.
1. Stop your MySQL server
sudo /usr/local/bin/mysql.server stop
2. Remove new data files
sudo mv /usr/local/mysql/data /usr/local/mysql/data.new
3. Copy old data files from your backup and fix prrmissions
sudo chown -R _mysql:wheel /usr/local/mysql/data
4. Start your server again
sudo /usr/local/bin/mysql.server start
5. Check and optimize databases
sudo /usr/local/mysql/bin/mysqlcheck --all-databases
Now phpMyAdmin will show all old databases