Is it possible to duplicate a MySQL database from their files? [I know mysqldump would be the best method to duplicate a db, but that's not possible as all we have is the backed up files from the mysql folder].
We have the ibdata1 file, the ib_log* files, and the full directories for the three db's we want to restore from the backed up files (folders seem to contain all needed frm and par files). Obviously already tried just to copy all the files into /var/lib/mysql and though it appeared the structure was intact attempts to access the data were unsuccessful.
i.e. show databases will show the db's, use dbname works, and show tables properly displays the tables, but when trying to access the data from [any] table (via query) it says ERROR 1146 (42S02): Table 'dbname.dbtable' doesn't exist - despite mysql having happily showed us the table does exist when we did show tables.
Should also point out the service was stopped prior to copying files and all files chown'ed to have mysql as owner and then the service restarted prior to attempting to access the data.
To answer your question indirectly, there is some information here regarding setting up replication using a raw file copy. So I guess the answer is possibly yes, but it may depend.
http://dev.mysql.com/doc/refman/5.0/en/replication-howto-rawdata.html
Not wishing to add to your current pain, but were you relying on a backup that you have never tried / don't know how to restore?
Related
I have an error with Xampp where it will not connect to my database. I have had this error several times in the past and no solutions have helped. I find that uninstalling and reinstalling ends up being the fastest method, however, by doing so I lose my database tables. As I have no access to the default export and import functions, I was wondering how I transfer the tables across.
Last time, I copied and pasted these files into the same directory when I reinstalled Xampp and the tables transferred but the data within did not. The tables had also lost some functionality as well.
If anyone has any methods to do this I will greatly appreciate it.
The best way to backup and restore your data is to dump the database to an SQL file. You can use the provided mysqldump tool for that, which is the best tool for the job.
Copying the entire MySQL "datadir" (which is probably one level up from the screenshot you've posted) and completely replacing one of your new stopped MySQL instance will probably work, but is not reliable and is not supported. Since there are other files (such as ibdata1) that handle the overall health and functioning of the entire MySQL instance, you can't only copy over individual database directories. Furthermore, you should only do this when the original and replacement MySQL servers/daemons/services are completely stopped because otherwise there are file corruption or concurrency issues.
Since you're running the server on your own computer, you should grant yourself sufficient access to be able to use mysqldump and use that regularly as a backup, since file-level backups of the data directory are not reliable.
I have created a GameCenter type database in sequel pro using root, but for some reason every now and again I get the following errors when connecting to the database and trying to access the tables:
An error occurred while retrieving the information for
table 'Achievement'. Please try again.
MySQL said: Table 'gamecenter2.achievement'
doesn't exist
I have looked around and most people say it is a problem that occurs when copying a database from one place to another however I am not doing that.
In terminal using MySQL the database and tables all show up but I get the same error when trying to access a table's contents:
SHOW COLUMNS FROM Achievement;
ERROR 1146 (42S02): Table 'gamecenter2.achievement' doesn't exist
Any help with this would be really appreciated as running the CREATE TABLES and INSERT over and over is getting quite tiresome!
I've had the same problem recently (and same error message in sequel pro) and have since discovered that it is because certain types of MySQL databases (i.e. those using InnoDB) store the actual data for individual tables outside in a file named "ibdata1" (you can read more on this here: https://dba.stackexchange.com/questions/15531/why-does-innodb-store-all-databases-in-one-file). Thus, if you restore individual folders for your database(s) using time machine, you are actually just restoring empty database architectures without the good stuff inside. If you haven't also restored that "ibdata1" file along with the appropriate "ib_logfile" files it won't be able to find the data. The solution is to make sure you've also restored those files (or a recent good copy).
Do also make sure you stop the mysql service before restoring anything, i.e. "mysql.server stop" from the command line (or "launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist" if you've installed mysql using homebrew).
I'm sure that there are a lot of people facing my problem; I had copied the data folder inside mysql on the hard disk, then format my computer, then I have pasted the data folder,
then all databases shows the number of tables, and when I make query show tables.
Its showing all tables inside database, but when I try to access the tables, it's showing table does not exist?
Please, I have a lot of projects, can any body help me?
Note that there was no password on the previous version and the user was root as now.
Please help.
I did not move any database file, but I had the same error message "No tables found in database" within PhpMyAdmin. But I could access the database by sql. I found out that it was caused by the browser. Using another browser or a private window helped. Did not try a restart or deleting cache so far.
If your phpMyAdmin no longer sees any tables in any of your local databases, that is because permissions change away from mysql.mysql on any database directory under /var/lib/mysql to, say, root.root (most probably).
You will have to change the owner from root.root to mysql.mysql, to do this, youâll need root access and putty. Key in this command:
chown -R mysql.mysql /var/lib/mysql/
Probably a duplicate: MySQL Table does not exist error, but it does exist
But moving files is not the way to save the database,best way is the export,import.
I've got a database (all MyISAM tables) and the machine where MySQL was running is no longer bootable. However, we have all the MySQL data files from the data directory. How can I restore the data from the MYD and FRM files, or whatever other files I should be looking at in the data directory?
I've been doing some searching on this and it sounds like for MyISAM I should just be able to copy the database subdirectory from the old MySQL data directory to the new MySQL data directory. However, that's not working for me. A database with the name of the database I'm trying to recover shows up in the list of databases in phpMyAdmin, but all the tables show "in use" and have no information (e.g., number of rows, number of bytes, column information, etc.). Any operation on those tables (e.g., SELECT * FROM {table}, REPAIR {table}, CHECK {table}) returns a "no such table" error.
One of the tools I ran across in my search is DBACentral by MicroOLAP. It's got component that's supposed to restore data from FRM/MYD files, but when I tried to run it, it didn't list any tables that it could recover from my FRM/MYD files.
This is on a developer workstation that's running Vista Business 32bit. MySQL version is 5.0.27. After fixing the machine, I went and got the exact same version of MySQL (v5.0.27), thinking that if I'm just going to drop in the binary data files I should do it with the same version of MySQL. It still didn't work.
Any insights would be greatly appreciated... thanks!
-Josh
Install the same version of mysql.
Remove mysql directory from data directory of the server and copy it from the crashed server. This is the key element
copy directory of database you want to recover into data directory of new server
start mysql.
switch to mysql database: USE mysql; and run REPAIR TABLE <table name> on every table.
Do the same with database you want to recover
tip: make sure the 2 directories have the same permissions like data directory
If you did not save mysql database (mysql directory in your old server's data dir, then you can try to:
create database with the same name as database you want to recover.
Then you can create each table (it would be good to use the same structure - you'd have bigger chance of recovery).
then stop mysql server and delete files from database directory and overwrite them with files from old server
start mysql and repair each table.
I wound up giving up. I think the answer is that, with my particular version of MySQL, this doesn't work. Hopefully things have improved since then.
I have a recovery disc image which contains the datafiles for mysql server.
The original server is unavailable - all I have is the datafiles (programdata, program files etc).
I am not able to make a mysqldump file.
On the new server, I've installed the exact copy of mysql server, and copied the files/folders (all the myd myi files) from the disc image to the new server.
After restarting the mysql service, I can see the list of my databases in mysql administrator.
However, when I try to view a table, I get an error:
"1146 The table {dbname}.{tablename} does not exist."
I tried running myisamchk but this says there is n problem (at least no error is displayed)
Can anyone help?
Bob
You will need a copy of the corresponding .frm files, which contain the format information MySQL needs to read the raw row data from .myd/.myi or ibdata files. Without the .frm files, MySQL does not know the tables are even supposed to exist (which is why they're not found, and myisamchk doesn't see any broken tables).
If you don't have these files, you may be in trouble. You should be able to reconstruct the .frm by re-CREATEing the tables from scratch, then stopping the server and dropping the .myd/.myis over the empty versions. But you will need to know the exact datatypes and indexes that were originally used in the schema. (“Very difficult repair”)