Export / Import MySQL database

Posted on 2012-08-11
Last Modified: 2012-08-13
I have a MySQL database on a web server with about 30 tables. I need to export it and import it into another database. The new database has a different name than the old database.

I exported the database to my local machine using phpmyadmin, selecting ALL tables.

See attached as the first part of the exported SQL file.

Can I just import that file into the other (empty, no tables) database & change Database: `db203755816` in the first line to the new database name?

Question by:Richard Korts
    LVL 17

    Accepted Solution

    You should be able to do that. There is no need to change Database: `db203755816', as that is just a comment.
    LVL 23

    Expert Comment

    Is it a linux machine that is running MySQL?  If so you can EASILY export/import like so:

    Export the database:

    mysqldump -u root -p *dbname* > outputfile.sql

    Of course replace *dbname* with the name of the database and you can call the output file whatever you like.

    Import the database:
    Copy the output.sql file to other server and run command:

    mysql  -u root -p *dbname* < outputfile.sql

    Same as above, use the new database name that you want to import to.
    LVL 30

    Expert Comment

    by:Marco Gasi
    You can simply use PhpMyAdmin to import the whole database: i did it svereal times.

    LVL 12

    Expert Comment

    by:Mohamed Abowarda
    There are many way you can use, you can use PhpMyAdmin, or you can use a custom PHP script, you might also be able to use cPanel if you have cPanel installed.

    To use a custom PHP script:

    To use PhpMyAdmin:
    LVL 49

    Expert Comment

    by:Julian Hansen
    Just a note - the script you posted is incomplete and will fail on the last line. It looks like the file was truncated.

    The only things to watch out for (assuming a complete script) are

    a) Use database statements - remove if moving to another DB
    b) Views and stored procedures need to be exported and imported correctly

    Also there is no drop table statements in the script so if the tables already exist this will generate an error but the data should still be imported.

    Author Closing Comment

    by:Richard Korts
    Worked like a charm.


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    As a database administrator, you may need to audit your table(s) to determine whether the data types are optimal for your real-world data needs.  This Article is intended to be a resource for such a task. Preface The other day, I was involved …
    Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
    Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
    The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now