Restore Databases from Phpymyadmin - mysql

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

Related

Recover MySQL /var/lib/mysql after update

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.

MySQL how to recover data from an old disk?

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.

How to backup MySQL in rescue mode?

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

Lost or corrupt mysql table after computer is turned off or restarted

I'm using a mysql local database to store some data from two ruby scripts i created. The problem is that whenever I restart or turn off my computer my database seems to get corrupted as when i tried to access it it show the following error:
Can't connect to MySQL server on 'Andres-MacBook-Air-3.local' (61) (Mysql2::Error)
I then use the following commands (which I found while googling around) to restore the connection:
cd /usr/local/mysql
sudo ./bin/mysqld_safe
(Enter your password, if necessary)
(Press Control-Z)
bg
After I do that, I can connect to the database but when I try to access a table the following error comes up:
Error retrieving table information
An error occurred while retrieving the information for table 'fourCheckins'. Please try again.
MySQL said: Table 'trackpuntos.fourcheckins' doesn't exist
I think that turning off/restarting my computer is causing the problem as this same scenario has happen to be twice. Fortunately after the first time I am doing regular mysqldumps.
Does anyone have an idea on why is this happening/how to prevent it?
I'm running mysql 5.6.12, on a macbook air running OS Lion.
Thanks
I've been having the same problem for the past week. I'm finding the InnoDB databases are getting corrupted when I have open connections to the databases and I shut off/restart the computer.
I had installed mysql 5.6 unintentionally via homebrew upgrade on my Mac. I just rolled mysql back to 5.5.29 following the instructions below. After the downgrade back to 5.5, I set up my databases again, opened a bunch of connections, and then shutdown the computer. Upon reboot, I had no corruptions. Hopefully it'll stay that way!
Note: paths may be different for your system
Uninstall 5.6 mysql via homebrew
$ brew uninstall mysql
$ rm -rf /usr/local/var/mysql
Install 5.5.29 mysql via homebrew
$ cd /usr/local/Library/Formula
$ git checkout -b mysql-5.5.29 336c97637c5449018cde59f7d2a87a298692da08
$ brew install mysql
follow all the post-install steps for mysql...
$ unset TMPDIR
$ mysql_install_db --verbose --user=`whoami` --basedir="$(brew --prefix mysql)" --datadir=/usr/local/var/mysql --tmpdir=/tmp
$ launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
$ launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
reset homebrew to master !important!
$ git checkout master
Lastly, don't brew upgrade mysql until 5.6 is more stable!
I had the same problem after a reboot... Just stopped and restarted MySQL and my DB was working fine after that.

MAMP - Upgrade to MySQL 5.6

Is it possible to upgrade the MAMP MySQL library to 5.6 ?
Or I'll need to install MySQL natively (Lion) ?
If someone could point me in the right direction...
Thanks!
The latest MAMP has MySQL 5.5.9. Given the occasional wonkiness of MAMP and general lack of support, I'd be hesitant to mess about with it internally to upgrade it.
However, there's nothing wrong with disabling the MySQL that comes with it, installing 5.6 separately, then pointing it at the MAMP MySQL data files. You'll need to remember to run the upgrade script that comes with MySQL, so probably best to take a copy of the MAMP data first and move it to the data folder of the new MySQL install.
The only reason to use MAMP in the first place is that messing about with the built in copy of Apache can make file sharing stop working, so it's easier to use MAMP instead on a different port, but this doesn't apply to MySQL so you should be OK.
It is possible. I have it running. Install MySQL
http://dev.mysql.com/downloads/mysql/
Download the Mac version
Then change your mysql.sock in MAMP to the new one
mv /Applications/MAMP/tmp/mysql/mysql.sock /Applications/MAMP/tmp/mysql/mysql.sock.back
ln -s /var/mysql/mysql.sock /Applications/MAMP/tmp/mysql/mysql.sock
Restart MAMP
Found a solution on gist and modified it a bit:
#!/bin/sh
wget http://cdn.mysql.com/Downloads/MySQL-5.6/mysql-5.6.22-osx10.9-x86_64.tar.gz
tar xfvz mysql-5.6*
rm mysql-5.6.22-osx10.9-x86_64.tar.gz
echo "stopping mamp"
sudo /Applications/MAMP/bin/stop.sh
sudo killall httpd mysqld
echo "creating backup"
sudo rsync -a /Applications/MAMP ~/Desktop/MAMP-Backup
echo "copy bin"
sudo rsync -av mysql-5.6.*/bin/* /Applications/MAMP/Library/bin/ --exclude=mysqld_multi --exclude=mysqld_safe
echo "copy share"
sudo rsync -av mysql-5.6.*/share/* /Applications/MAMP/Library/share/
echo "fixing access (workaround)"
sudo chmod -R o+rw /Applications/MAMP/db/mysql/
sudo chmod -R o+rw /Applications/MAMP/tmp/mysql/
echo "starting mamp"
sudo /Applications/MAMP/bin/start.sh
echo "migrate to new version"
/Applications/MAMP/Library/bin/mysql_upgrade -u root --password=root -h 127.0.0.1
https://gist.github.com/tobi-pb/b9426db51f262d88515c
If everything worked, you have to delete the mySQL backup on your desktop. You can check the current mySQL-Version by executing the following command on your local server:
SHOW VARIABLES LIKE "%version%"
Download the official script by MAMP to update your MySQL to 5.6.12
http://blog-en.mamp.info/2015/07/how-to-use-mysql-5-6-with-mamp-and-mamp.html
For those of you who absolutely require MySQL 5.6 to be part of their development environment - maybe you are a Magento developer - we have released a shell script that updates the MySQL component of MAMP and MAMP PRO to v5.6. The script requires at least MAMP and MAMP PRO 3.3, older versions are untested.
Since MAMP 4.x is released, just use that version / upgrade your existing MAMP installation. MySQL 5.6 is already included.