• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 46
  • Last Modified:

moving tables from mysql schema to new scheme

Somehow my developer had the bright idea to create tables to be used with a web application into the system/default 'mysql' DB?!  I misunderstood his question and he ended up creating tables in the 'mysql' db/schema.  Anyway...  At this point should I just export the entire mysql schema as a .sql file and then import into the new schema?  Then delete the tables I don't need?  This will resort in system tables coming with it that aren't needed.  Will the below work?

use mysql;
mysqldump -u root mysql > dump.sql
mysql -u root newdb < dump.sql

Then I'll use MySQL WorkBench to delete unneeded system/mysql tables from newdb?
0
gopher_49
Asked:
gopher_49
  • 3
  • 2
1 Solution
 
Chris StanyonCommented:
Several ways to do it. Which will be easiest will depend on how many tables you have.

If you only have a few, you could do it all through mysql workbench. Copy schema a data for each tables with something like:

CREATE TABLE newdb.tableName LIKE olddb.tableName;
INSERT newdb.tableName SELECT * FROM olddb.tableName;

I tend to use a program called SQLyog - it's as simple as right clicking on a table and choose 'Copy to another database' :)
0
 
gopher_49Author Commented:
I exported all and imported all.  Then deleted the unneeded ones. It seemed to work.  Is my method and / syntax posted an okay option too?
0
 
Chris StanyonCommented:
It's been a while since I've used the command prompt, so not sure. Looks OK but run some test and see. And make sure you new table has the correct permissions setup - as I said before, you don't really want your application accessing your server with root credentials.
0
 
gopher_49Author Commented:
I used root to export / import.  The app uses different creds.  We'll test and reply back shortly.

Thanks
0
 
gopher_49Author Commented:
This solution works, however, it was easier for me to backup/export the entire mysql DB..  Restored as a new DB and delete wasn't needed.

Thanks.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now