MySQL8 Restore from Physical Files - Innodb - mysql

I recently had one of my VM's go down (MS Server 2016) and the only version I am able to get up and running is two weeks old. However, I do have a backup of my C:/ drive from last night that has my C:/ProgramData/MySQL and C:/Program Files/MySQL in order to restore my databases can I simply shut down MySQL service, copy/replace the folders in my VM, and start MySQL again?
[SOLVED] As stated in the comment below:
Copying the entire C:/ProgramData/MySQL folder did not work for me, the MySQL service would not start. Instead, copying just the contents of C:/ProgramData/MySQL/MySQL Server 8.0/Data solved the problem. The service started with no errors and all my data was recovered.

Related

Duplicate MySQL database without shell

I crashed my first Ubuntu installation by changing some distribution stuff (now stuck in login loop, even in shell).
So I installed Ubuntu again on my second hard drive from which I can access the crashed Ubuntu setup.
And since I can't start Apache2 or reach the MySQL server there anymore, I'm wondering if there is a possibility to duplicate the MySQL data just by copying files from one hard drive to another.
Or maybe someone has an alternative idea to restore the MySQL data?
You can create a database of the same name on the other computer and then transfer the content of /var/lib/mysql/_dbname_/. Stop before the copying and start after it.

MySQL corrupts after every server restart

I Have a bit of an odd problem. I am running MySQL and Drupal site from a windows environment (not by choice but it is just how things have worked out) and most of the time the site is fine however every time the server is restarted (from updates or for maintenance) The MySQL Database will corrupt.
When I log in to MySQL Work bench I notice that the server status is stopped and when I try to start it I get the error:
ERROR Fatal error: Can't open and lock privilege tables: Can't find file: 'user' (errno: 2 - No such file or directory)
and then MySQL Server fails to restart.
The only way around this problem is to delete data folder in the ProgramData/MySQL and then replace it with a backup from a fresh install of MySQL then import a backup of my tables and recreate my users.
My Question is what is causing MySQL to corrupt at every sever restart and what can I do to prevent this happening moving forward?
This occurs when mysql can not find or do not have permissions to user.MYD or user.MYI or user.frm in the data directory. When you start mysql, make sure that these files exist in data directory. You can just copy those files when mysql does not start
This worked for me:
Stick with the 32 bit.
Uninstall and make sure you then DELETE the mysql-data folder and all its subfolders before installing, and prefer to use the 32 bit (sometimes 64 bit versions are the problem).
(Source)

Mysql databases not recogniced after moving files

I have a problem with my database/schema.
I wanted to change the raid configuration on my server. To do so, I first shutdown the mysql server, which is actually percona5.6, and then moved all the files to another location.
I then restarted the server and configured the raid.
Then I let it boot, unfortunately the mysql server started as well and of course couldn't find the moved databases.
When I then moved the files back to the reconfigured drive and started the server, the databases where gone.
All databases have the right owner and group (percona:percona) and are innodb tables (file_per_table=1).
My question now is, how can I reinitialize the databases, if possible?
Thanks for the help.
You do not have to reinitialise the databases if they are in the correct directories and if all directories have the correct permissions for the database user. Also check if the directories have the correct owner.

Attaching an existing database with MySQL

Disclaimer: I have never used MySQL before!
I have a folder containing a number of .frm, .myd and .myi files that I believe are a MySQL database. I have pulled these files from a defunct server for a client who has not used the server or database for some years but is now looking to resurect some of the data for a new venture.
I have downloaded the latest free edition of MySQL, along with MySQL Workbench and am looking to connecct the existing database to the new installation; the equivalent to an "Attach" if I were using MS SQL Server.
I have found a few articles that say if I simply copy the folder into the data folder for MySQL and restart the service the database will show up. I have tried this (using both the data folder within the installation folder and also the "MySQL Datafiles" folder created during the intial configuration but when I restart the service nothing shows up.
How should I go about attaching this database?
Ok. I found the answer, the folder I was adding the database to was the wrong one.
Though I had found 2 "data" folders, there was a 3rd hiding in C:\ApplicationData; once I added my data files in here and restarted the MySQL service I could see the data.
On Windows 8 the default folder where MySql databases are stored is:
C:\ProgramData\MySQL\MySQL Server 5.6\data
5.6 is the version.
Please note it is ProgramData not Program Files which is easy to overlook.
Copying there and restarting the service worked fine for me. I'm even copying the DBs from an earlier 5.X version.

How to recover/restore the data (records) of my MySQL database on a corrupted hard drive?

A few days ago my hard drive crashed (no booting anymore). On this hard drive was a MySQL installation with a database (called "db_cedar"). Meanwhile, I could connect the corrupted hard drive as a second hard drive to my computer. That means I have full access to the file system of the crashed hard drive, thus on the MySQL files and folders.
I did never a backup of my database. I know, my fault. :-(
Is there a way to recover/restore the data (records) of my database (db_cedar) or even the entire database, for example by copying particular MySQL files or folders (on the crashed hard drive) and puting these on my new hard drive with a freshly installed version of MySQL? Note: The freshly installed MySQL version on my new hard drive is exactly the same version of the MySQL version on the crashed hard drive.
I would be very happy for any help. Thank you!
Provided the data is not corrupt, you should be able to copy the entire database directory + the my.cnf file and get back up and running.
For restoring InnoDB databases, have a look at my answer here.and have a look at taking cold backup f innodb from mysql docs here. For MYSIAM, it is easier. As #mluebke said just copy database directory and the my.cnf (for non-windows) or my.ini for windows