How do I restore MySQL DB from backup - mysql

My server recently crashed and I have backed the Mysql files using raid.
BACKED UP DIRECTORY
/backup/var/lib/mysql
I installed new OS(RHEL5.3) to my server and I want to restore my DB to MySQL
How do I do this?
I know you can ssh mysql > the dump files
but, these backed up files are not in DUMP.
They are separated as .MYD .MYI .frm etc..

I guess your backup file is not in the same server as your database.
Try:
scp -r /backup/var/lib/mysql/* DB_SERVER:YOUR_NEW_DATABASE_DIRECTORY
Then
ssh DB_SERVER
.. restart your mysql daemon (easier)
.. or flush privileges, flush tables ...

Copy these files directly to your mysql data directory, and you will be able to access them in MySQL. That should help you!

Related

connecting MySQL database to copied and pasted data directory

I copied a database directory from the datadir (/var/lib/mysql/) of a MySQL instance running on a server to my local machine. Is it possible to put this database directory into my local MySQL datadir and access that database?
What I have done so far is copy the database directory like above, I log in to the MySQL and can see the database, I switch to it and can list all the tables. But when ever I try to query a table I get something like:
select * from users limit 1;
ERROR 1146 (42S02): Table 'users' doesn't exist
Also from mysqldump:
mysqldump: Got error: 1146: Table 'very_first_table' doesn't exist when using LOCK TABLES
Is it possible to do what I am trying to do here?
So I got it to work, bare in mind that my end goal was to get a database dump from the database. The mysql folder was extracted from a older virtual machine snapshot which could not be run at the moment, so I couldn't just log in to it and do a normal dump. Here is what I did:
1) I installed mysql on a fresh vm on my local machine
2) I shut down mysql with service mysql stop
3) I removed the existing /var/lib/mysql folder from the fresh install
4) I replaced it with the /var/lib/mysql folder that was removed from the old snapshot
5) I ran chown -R mysql:mysql /var/lib/mysql
6) I restarted mysql with service mysql start
7) Then I checked if I could log in and query the tables, I could!
So I was able to run the dump after that.

Recover databases from backed up ibdata + frm files on volume

I've got ~ 30 sites worth of databases data on a volume on my server in the following directory /mnt/volume0/var/lib/mysql
The directory contains a 6.2G ibdata1 file and directories containing .frm files for each of the websites.
I'm trying to get dumps of the databases so I can move them to another server, however accessing mysql only shows the default databases (as datadir in /etc/mysql/mysql.conf.d/mysqld.cnf is set to /var/lib/mysql)
I've tried changing the datadir in /etc/mysql/mysql.conf.d/mysqld.cnf to /mnt/volume0/var/lib/mysql but mysql fails to start.
It was complaining about "failed to set datadir" which I fixed by running chown mysql:mysql mysql/ -R on /mnt/volume0/var/lib/mysql but now it's complaining about Failed password for root from xxx.xx.xxx.xx port 19192 ssh2
Any help is greatly appriciated!
Thanks
You can try to reset your password
mysqld_safe --skip-grant-tables
if you have here an error, then you have a bigger problem
mysql --user=root mysql
update user set Password=PASSWORD('your new password') where user='root';
flush privileges;
exit;
I ended up solving this issue by replacing the contents of /var/lib/mysql/ on my local machine with the contents of /mnt/volume0/var/lib/mysql/ (from the server).
I then encountered an error whilst trying to start MySQL Table 'performance_schema.session_variables' doesn't exist which I solved by upgrading MySQL on my local machine and restarting: https://stackoverflow.com/a/20262826/8231049
Now I'm able to dump the databases from my local machine :)
Edit: Can't accept my answer before waiting 2 days. Will do then.

Mysql backup from a mounted root drive

I had a problem with my hdd. There is a new system running in place and I found that I can mount and access the / of my old hdd (It had a Debian Linux distribution). However I forgot to backup some important data in the DB tables and I was wondering if there was anyway to execute a mysql server command from the mysql server installation in the mounted drive?
If your hdd contains complete OS, you can simply mount it and chroot to it. In chrooted environment start your mysql server and take data-backup with mysqldump command.
Or you can simply install mysql-server on your new system, change data directory option in /etc/my.cnf to the mounted partition, backup the data with mysqldump command. You can then revert the my.cnf change back.

Moving mysql database from one server to another server

I want to move my mysql database from rackspace server to aws server.Is there any way to do it easily.It contains more or less 1 million rows of data
If your site is not a live site and downtime is not an issue, you can try the below
#step1: take a dump of your db
>mysqldump –-user root –-password=myrootpassword db_test > db_test.sql
#step2: zip the .sql file - this is optional
>gzip db_test.sql
#step3: transfer the file to AWS using .pem file
>scp -i myAmazonKey.pem db_test.sql.gz ec2-user#<ur_ip_address>:~/.
#step4: login to your AWS instance
#step5: unzip the file
>gunzip db_test.sql.gz
#step6: import the db to your AWS mysql instance
>mysql -u username -p password db_name < db_test.sql
Please go through the below steps,
Old Server
Stop mysql server
Copy contents of datadir to another location on disk (~/mysqldata/*)
Start mysql server again (downtime was 10-15 minutes)
compress the data (tar -czvf mysqldata.tar.gz ~/mysqldata)
copy the compressed file to new server
New Server
install mysql (don't start)
unzip compressed file (tar -xzvf mysqldata.tar.gz)
move contents of mysqldata to the datadir
Make sure your innodb_log_file_size is same on new server, or if it's not, don't copy the old log files (mysql will generate these)
Start mysql

How to restore full mysql (dir)

My problem is: I'm saved the /var/www/virtual and the /var/lib/mysql directories. And after reinstall OS I set up the MySQL and when restored these two directories i'm got error in mysql server. So MySQL server don't want to start up.
So what way can i restore the mysql database directory?
The MySQL server don't start after I copy the ibdata1 file.