I've been working on my development database and have tweaked its performance.
However, to my surprise I can't find a way to export the indexes to my production database.
I thought there would be an easy way to do this. I don't want to replace the data in my production database.
The main problem is that I can't see sorting in the indexes so its going to be difficult to even do it manually.
you can use the following command to take a dump
and indexes will be copied automatically.
Extending on @origo's answer. There is a case where i needed to extract the DDL for a bunch of indexes. This script does the job.
source : https://rogerpadilla.wordpress.com/2008/12/02/mysql-export-indexes/
I also have development and production servers with the same database structure.
I modified indexes on both of them so I wanted to merge all together. So I needed to compare data with Notepad+.
Here is how you export indexes for all tables, all databases and how to filter and compare them:
Now, phpMyAdmin -> Export to CSV-Excel:
add a header row -> delete all columns but leave "database_name table_name index column value"
Then, filter by database.
Copy all from database1 to a notepad+ screen 1, filter excel database2, copy all to notepad+ screen 2 -> COMPARE!
I believe you're trying to export the indexes themselves and not just the code to regenerate them in production, right? (I'm assuming this because the load of generating these indexes is not favorable in most production environments.)
The mysqldump utility is useful if performance isn't your main concern, and I use it all the time. If you're looking for a very fast method, though, I would suggest copying the actual InnoDB files from one cold database to the other (assuming they're exactly the same MySQL version with the exactly the same configuration and the exactly the same expected behavior, etc). This method is dangerous if there any differences between the systems.
It sounds like, in your situation, you might want to copy your good data to your testing environment first. My development cycle typically follows this approach: DDL flows from testing to production via programming, and DML flows from production to testing via actual use of the system.
Perhaps you mean "How do I re-create my development indexes on my (existing) live database"?
If so, I think the SQL commands you're looking for are;
SHOW CREATE TABLE {tablename};
ALTER TABLE ADD INDEX {index_name} (col1, col2)
ALTER TABLE DROP INDEX {index_name}
You can copy the "KEY" and "CONSTRAINT" rows from "SHOW CREATE TABLE" output and put it back in the "ALTER TABLE ADD INDEX".
Hope this helps!
First, read the tutorial here about how-to Export MySQL Indexes using a SQL query. Further:
If you do complete DUMP of your database and IMPORT it to another (using PHPMyAdmin, etc), the indexes will get regenerated.
If possible, you can copy contents of your entire MySQL database folder to the production database. This will do the trick too, quickly. Read more here at MySQL docs.