+ Reply to Thread
Results 1 to 10 of 10

Thread: Database MySQL

  1. #1
    Brandon Guest

    Database MySQL

    Does anyone know how to transfer the contents from one MySql database to another on the same server? Can some one give me the code to do it in Cron?

  2. #2
    Brandon Guest

    Re: Database MySQL

    Ahh... Im paying 50 points.

  3. #3
    Chris S's Avatar
    Chris S is offline Retired Chris S is an unknown quantity at this point
    Join Date
    Mar 2005
    Posts
    1,036

    Re: Database MySQL

    Ok, I am going to take a stab in the dark and have you try this code
    PHP Code:
    <?
    /*  Database Information - Required!!  */
    /* -- Configure the Variables Below --*/
    $dbhost 'localhost';
    $dbusername 'enigma_meh';
    $dbpasswd '******';
    $database_name 'saxattac_users';

    $tablename_backup "xxxxxx"//talbe you want to backup
    $tablename_restore "xxxxxx"//if you want to restore it to a different table 
                      //you do have to fill this in
    $backupfile "xxxxxx"// the file you want to restore and create the backup into

    /* Database Stuff, do not modify below this line */

    $connection mysql_pconnect("$dbhost","$dbusername","$dbpasswd")
        or die (
    "Couldn't connect to server.");

    $db mysql_select_db("$database_name"$connection)
        or die(
    "Couldn't select database.");
    ?>
    backup.php
    PHP Code:
    <?php
    $tableName 
    "$tablename_restore";
    $backupFile "$backupfile";
    $query "SELECT * INTO OUTFILE '$backupFile' FROM $tableName";
    $result mysql_query($query);
    ?>
    restore.php
    PHP Code:
    <?php

    $tableName 
    "$tablename_restore";
    $backupFile "$backupfile";
    $query "LOAD DATA INFILE "$backupFile" INTO TABLE $tableName";
    $result mysql_query($query);

    ?>
    Last edited by Chris S; 02-22-2006 at 11:44 AM.

    I would love to change the world, but they won't give me the source code

  4. #4
    Corey's Avatar
    Corey is online now VPS Migration Professional Corey is a glorious beacon of lightCorey is a glorious beacon of light
    Join Date
    Dec 2004
    Location
    Northfield, NH
    Posts
    17,152

    Re: Database MySQL

    Use PHPAdmin ;) You can export tables and the such, and just import the info my using the SQL feature of PHPMyAdmin on the other account.

    -Corey

  5. #5
    Jake's Avatar
    Jake is offline Developer Jake is an unknown quantity at this point
    Join Date
    Apr 2005
    Location
    Winona, MN
    Posts
    2,084

    Re: Database MySQL

    think he wanted it automatic, well you can use a script like above, should work well with cron, becasue there is no way to export the file in phpmyadmin every day, unless by hand...
    Jake Omann | Developer
    █ 888-X10-9668 - jake[@]x10hosting.com
    x10Hosting - Giving Away Hosting Since 2004
    Premium Hosting | VPS Services

  6. #6
    Chris S's Avatar
    Chris S is offline Retired Chris S is an unknown quantity at this point
    Join Date
    Mar 2005
    Posts
    1,036

    Re: Database MySQL

    does it work?

    I would love to change the world, but they won't give me the source code

  7. #7
    Chris S's Avatar
    Chris S is offline Retired Chris S is an unknown quantity at this point
    Join Date
    Mar 2005
    Posts
    1,036

    Re: Database MySQL

    it shouldn't because i made some mistakes

    (i was in a rush and trying to hide it from the media center people)

    backup.php
    PHP Code:
    <?php
    include ('db.php');
    $tableName "$tablename_restore";
    $backupFile "$backupfile";
    $query "SELECT * INTO OUTFILE '$backupFile' FROM $tableName";
    $result mysql_query($query);
    ?>
    restore.php
    PHP Code:
    <?php
    include ('db.php');
    $tableName "$tablename_restore";
    $backupFile "$backupfile";
    $query "LOAD DATA INFILE "$backupFile" INTO TABLE $tableName";
    $result mysql_query($query);

    ?>
    and name the first file db.php

    I would love to change the world, but they won't give me the source code

  8. #8
    chitwa is offline x10Hosting Member chitwa is an unknown quantity at this point
    Join Date
    Apr 2005
    Location
    Kenya
    Posts
    64

    Re: Database MySQL

    if you want to use cron, use something like this

    Code:
    #/bin/sh
    mysql -u <mysql username> -p<mysql password> -e "<mysql query>" <mysql database>
    Save the above code as a file in your cgi-bin as "dcopy.sh"
    Remember to Insert your info between the <>. All that remains is the query to copy database. Unfortunately, i dont know it!
    Create a cron job to point to it and it will be executed at the times you set.

    NOw that I ve taken you halfway there how about 25 points :-)
    Last edited by chitwa; 03-06-2006 at 09:19 AM.

  9. #9
    Chris S's Avatar
    Chris S is offline Retired Chris S is an unknown quantity at this point
    Join Date
    Mar 2005
    Posts
    1,036

    Re: Database MySQL

    if you see, I've taken him all the way there except I did just notice that I have made another error in my code.

    backup.php:
    PHP Code:
    <?php
    include ('db.php');
    $tableName "$tablename_backup";
    $backupFile "$backupfile";
    $query "SELECT * INTO OUTFILE "$backupFile" FROM $tableName";
    $result mysql_query($query);
    ?>
    that should be right FINALLY

    I would love to change the world, but they won't give me the source code

  10. #10
    Brandon Guest

    Re: Database MySQL

    Thanks works.

+ Reply to Thread

Similar Threads

  1. [PHP] MySQL and PHP
    By Bryon in forum Tutorials
    Replies: 43
    Last Post: 03-24-2011, 07:27 AM
  2. PHP BB 2.0.16 Manual instalation
    By GFIV in forum Free Hosting
    Replies: 8
    Last Post: 09-14-2005, 12:40 PM
  3. I cant restore a mysql database
    By Revolution in forum Free Hosting
    Replies: 3
    Last Post: 07-24-2005, 01:27 PM
  4. Could not connect to MySQL database?
    By chiamingen in forum Free Hosting
    Replies: 4
    Last Post: 03-16-2005, 07:12 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers