Club Delphi  
    FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Bases de datos > MySQL
Registrarse FAQ Miembros Calendario Guía de estilo Temas de Hoy

Respuesta
 
Herramientas Buscar en Tema Desplegado
  #1  
Antiguo 11-10-2010
Avatar de RebeccaGL
RebeccaGL RebeccaGL is offline
Miembro
 
Registrado: ene 2008
Posts: 199
Poder: 17
RebeccaGL Va por buen camino
MySQLDump

buenas,

Cuando hago un backup y un restore con el administrador de MySQL lo hace bien, pero cuando hago un backup y restore con codigo desde delphi lo hace tambien bien.

Pero cuando trato de restaurar el respaldo que hize desde delphi con el administrador de MySQL me arroja este error. porque¿?

http://img40.imageshack.us/img40/2581/49876913.jpg
Responder Con Cita
  #2  
Antiguo 11-10-2010
Avatar de AzidRain
[AzidRain] AzidRain is offline
Miembro Premium
 
Registrado: sep 2005
Ubicación: Córdoba, Veracruz, México
Posts: 2.914
Poder: 21
AzidRain Va camino a la fama
las comillas simples, están a la inversa, de hecho así las genera MySQLdump. Reemplaza todas las comillas simples por dobles antes de lanzar la consulta (") y verás que te funciona
__________________
AKA "El animalito" ||Cordobés a mucha honra||
Responder Con Cita
  #3  
Antiguo 12-10-2010
Avatar de roman
roman roman is offline
Moderador
 
Registrado: may 2003
Ubicación: Ciudad de México
Posts: 20.269
Poder: 10
roman Es un diamante en brutoroman Es un diamante en brutoroman Es un diamante en bruto
Cita:
Empezado por AzidRain Ver Mensaje
Reemplaza todas las comillas simples por dobles antes de lanzar la consulta (") y verás que te funciona
No lo creo. Las comillas inversas no son equivalentes a las dobles (como sí lo son las comillas sencillas). Las primeras se usan para delimitar identificadores, como nombres de columnas, tablas, etc., mientras que las dobles (o sencillas) se usan para valores literales.

Sería bueno saber cómo hace el respaldo con Delphi.

// Saludos
Responder Con Cita
  #4  
Antiguo 12-10-2010
Avatar de RebeccaGL
RebeccaGL RebeccaGL is offline
Miembro
 
Registrado: ene 2008
Posts: 199
Poder: 17
RebeccaGL Va por buen camino
Este es el codigo de mi respaldo, lo uso tambien para conectarme.

Código Delphi [-]
procedure TForm_INIT.Init_MySQL_SERVER_READ;
var
  Init_MySQL: TIniFile;
begin
  // Init_PROGRAM_SYSTEM
  HALT_SYSTEM_PROGRAM := False;
  PROGRAM_Name := UpperCase(ExtractFileName(Application.ExeName));
  PROGRAM_Name := SYSTEM.Copy(PROGRAM_Name, 1, Length(PROGRAM_Name) - 4);
  Label_PROGRAM.Caption := 'Programa: ' + UpperCase(PROGRAM_Name);
  Exec_PATH_PRG := ExtractFilePath(Application.ExeName);
  Exec_PATH_PRG := Copy(Exec_PATH_PRG, 1, Length(Exec_PATH_PRG) - 1);

  // Init_Properties_FILENAMES
  dbf_PWDWIN := LowerCase(PROGRAM_Name) + '_db.pwdwin';
  dbf_PWDDDB := LowerCase(PROGRAM_Name) + '_db.pwdddb';
  dbf_PWDTAB := LowerCase(PROGRAM_Name) + '_db.pwdtab';
  dbf_PWDCAB := LowerCase(PROGRAM_Name) + '_db.pwdcab';

  // Init_Properties_CONNECTOR
  DB_Catalog := LowerCase(PROGRAM_Name) + '_db';
  DB_HostName := 'localhost';
  DB_Password := 'delphi';
  DB_Port := 3306;
  DB_Protocol := 'mysql-5';
  DB_User := LowerCase(PROGRAM_Name) + '_user';
  DB_Tag := 0;

  DB_Root := 'root';

  // Init_Properties_FILENAMES MySQL
  FILE_Backup := Exec_PATH_PRG + '\' + LowerCase(PROGRAM_Name) + '_backup.bat';
  FILE_Restore := Exec_PATH_PRG + '\' + LowerCase(PROGRAM_Name) + '_restore.bat';
  FILE_Data := Exec_PATH_PRG + '\' + LowerCase(PROGRAM_Name) + '_data.sql';

  // Semaphorize_SERVER
  if (MySQL_SERVER_INSTALLED) then
  begin
    // Disconnected DATABASE
    if (ZConnection_SERVER.Connected) then
    begin
      CONNECTION_Server := False;
      ZConnection_SERVER.Connected := False;
      Label_CONECCION_STATUS.Caption := 'Conectado: NO';
      Label_STATUSBAR_PWD.Caption := '';
    end;

    // CREATE >> INI File
    if (not (FileExists(Exec_PATH_PRG + '\' + UpperCase(PROGRAM_Name) + '.INI'))) then
    begin
      // Write_INI
      Init_MySQL := TIniFile.Create(ChangeFileExt(Application.ExeName, '.INI'));
      try
        Init_MySQL.WriteString('MySQL', 'Catalog', DB_Catalog);
        Init_MySQL.WriteString('MySQL', 'HostName', DB_HostName);
        Init_MySQL.WriteString('MySQL', 'Password', DB_Password);
        Init_MySQL.WriteInteger('MySQL', 'Port', DB_Port);
        Init_MySQL.WriteString('MySQL', 'Protocol', DB_Protocol);
        Init_MySQL.WriteString('MySQL', 'User', DB_User);
        Init_MySQL.WriteInteger('MySQL', 'Tag', DB_Tag);
      finally
        Init_MySQL.Free;
      end;
    end;

    // Verify Status DATABASE and TABLES
    Init_MySQL := TIniFile.Create(ChangeFileExt(Application.ExeName, '.INI'));
    try
      ZConnection_SERVER.Tag := Init_MySQL.ReadInteger('MySQL', 'Tag', 0);
    finally
      Init_MySQL.Free;
    end;
    Edit_CONECCION.Text := ZConnection_SERVER.HostName;

    // Database and Tables Found in MySQL Server
    if (ZConnection_SERVER.Tag = 1) then
    begin
      // Connection To Server MySQL
      try
        CONNECTION_Server := True;
        ZConnection_SERVER.Connected := True;
        Label_CONECCION_STATUS.Caption := 'Conectado: SI';
        Label_STATUSBAR_PWD.Caption := 'Conección al Servidor MySQL OK';
      except
        CONNECTION_Server := False;
        ZConnection_SERVER.Connected := False;
        Label_CONECCION_STATUS.Caption := 'Conectado: NO';
        Label_STATUSBAR_PWD.Caption := 'Error: No se puede conectar';
      end;
      Exit;
    end;

    // Read_INI
    Init_MySQL := TIniFile.Create(ChangeFileExt(Application.ExeName, '.INI'));
    try
      // Connection_MySQL Defaul
      ZConnection_SERVER.Catalog := str_NULL;
      ZConnection_SERVER.HostName := DB_HostName;
      ZConnection_SERVER.Password := str_NULL;
      ZConnection_SERVER.Port := DB_Port;
      ZConnection_SERVER.Protocol := DB_Protocol;
      ZConnection_SERVER.User := DB_Root;
      ZConnection_SERVER.Tag := DB_Tag;
      ZConnection_SERVER.Connected := True;

      (*
      // Esto lo puse como comentario porque por esto me salia el error >> 
      // "cant find any matching row in the user table"
      // CREATE >> Root locahost
      ZQuery_DATA.SQL.Clear;
      ZQuery_DATA.SQL.Add('GRANT ALL PRIVILEGES ON *.* TO "root"@"localhost" IDENTIFIED BY "" WITH GRANT OPTION;');
      ZQuery_DATA.ExecSQL;

      // CREATE >> Root All PC's
      ZQuery_DATA.SQL.Clear;
      ZQuery_DATA.SQL.Add('GRANT ALL PRIVILEGES ON *.* TO "root"@"%" IDENTIFIED BY "" WITH GRANT OPTION;');
      ZQuery_DATA.ExecSQL;
      *)
      
      // CREATE >> user locahost
      SQL_CodeMaster := 'GRANT ALL PRIVILEGES ON *.* TO '
                        + '"' + DB_User + '"' + '@' + '"' + DB_HostName + '"'
                        + ' IDENTIFIED BY ' + '"' + DB_Password + '"'
                        + ' WITH GRANT OPTION;';
      ZQuery_DATA.SQL.Clear;
      ZQuery_DATA.SQL.Add(SQL_CodeMaster);
      ZQuery_DATA.ExecSQL;

      // CREATE >> user All PC's
      SQL_CodeMaster := 'GRANT ALL PRIVILEGES ON *.* TO '
                        + '"' + DB_User + '"' + '@' + '"' + '%' + '"'
                        + ' IDENTIFIED BY ' + '"' + DB_Password + '"'
                        + ' WITH GRANT OPTION;';
      ZQuery_DATA.SQL.Clear;
      ZQuery_DATA.SQL.Add(SQL_CodeMaster);
      ZQuery_DATA.ExecSQL;

      // Flush_Privileges
      ZQuery_DATA.SQL.Clear;
      ZQuery_DATA.SQL.Add('FLUSH PRIVILEGES;');
      ZQuery_DATA.ExecSQL;

      // Create_DATABASE
      ZQuery_DATA.SQL.Clear;
      ZQuery_DATA.SQL.Add('CREATE DATABASE IF NOT EXISTS ' + DB_Catalog);
      ZQuery_DATA.ExecSQL;

      // Connection_MySQL Program
      ZConnection_SERVER.Connected := False;
      ZConnection_SERVER.Catalog := Init_MySQL.ReadString('MySQL', 'Catalog', str_NULL);
      ZConnection_SERVER.HostName := Init_MySQL.ReadString('MySQL', 'HostName', str_NULL);
      ZConnection_SERVER.Password := Init_MySQL.ReadString('MySQL', 'Password', str_NULL);
      ZConnection_SERVER.Port := Init_MySQL.ReadInteger('MySQL', 'Port', val_ZERO);
      ZConnection_SERVER.Protocol := Init_MySQL.ReadString('MySQL', 'Protocol', str_NULL);
      ZConnection_SERVER.User := Init_MySQL.ReadString('MySQL', 'User', str_NULL);
      ZConnection_SERVER.Tag := Init_MySQL.ReadInteger('MySQL', 'Tag', val_ZERO);
      Edit_CONECCION.Text := ZConnection_SERVER.HostName;

     // Init BACKUP
      BACKUP_path := REGISTRY_LoadData(HKEY_LOCAL_MACHINE, '\Software\MySQL AB\MySQL Server 5.1\', 'DataLocation')
      + 'bin\mysqldump.exe';
      BACKUP_str := 'cmd /c ' + '"' + BACKUP_path + '"' + ' '
                    + '-h ' + ZConnection_SERVER.HostName + ' '
                    + '-u ' + ZConnection_SERVER.User + ' '
                    + '-p'  + ZConnection_SERVER.Password + ' '
                    + DB_Catalog + ' > '
                    + '"' + FILE_Data + '"';

      // Init RESTORE
      RESTORE_path := REGISTRY_LoadData(HKEY_LOCAL_MACHINE, '\Software\MySQL AB\MySQL Server 5.1\', 'DataLocation')
      + 'bin\mysql.exe';
      RESTORE_str := 'cmd /c ' + '"' + RESTORE_path + '"' + ' '
                    + '-h ' + ZConnection_SERVER.HostName + ' '
                    + '-u ' + ZConnection_SERVER.User + ' '
                    + '-p'  + ZConnection_SERVER.Password + ' '
                    + DB_Catalog + ' < '
                    + '"' + FILE_Data + '"';

      // Create_FILE Backup.bat
      AssignFile(File_, FILE_Backup);
      Rewrite(File_);
      WriteLn(File_, BACKUP_str);
      CloseFile(File_);

      // Create_FILE Restore.bat
      AssignFile(File_, FILE_Restore);
      Rewrite(File_);
      WriteLn(File_, RESTORE_str);
      CloseFile(File_);

      // Backup_DATABASE
      // WinExec(PChar(FILE_Backup), 0);

      // Restore_DATABASE
      if (ZConnection_SERVER.Tag = 0) then
      begin
        WinExec(PChar(FILE_Restore), 0);
        ZConnection_SERVER.Tag := 1;
        Init_MySQL.WriteString('MySQL', 'Catalog', ZConnection_SERVER.Catalog);
        Init_MySQL.WriteString('MySQL', 'HostName', ZConnection_SERVER.HostName);
        Init_MySQL.WriteString('MySQL', 'Password', ZConnection_SERVER.Password);
        Init_MySQL.WriteInteger('MySQL', 'Port', ZConnection_SERVER.Port);
        Init_MySQL.WriteString('MySQL', 'Protocol', ZConnection_SERVER.Protocol);
        Init_MySQL.WriteString('MySQL', 'User', ZConnection_SERVER.User);
        Init_MySQL.WriteInteger('MySQL', 'Tag', ZConnection_SERVER.Tag);
      end;
    finally
      Init_MySQL.Free;
    end;

    // Connection To Server MySQL
    try
      CONNECTION_Server := True;
      ZConnection_SERVER.Connected := True;
      Label_CONECCION_STATUS.Caption := 'Conectado: SI';
      Label_STATUSBAR_PWD.Caption := 'Conección al Servidor MySQL OK';
    except
      CONNECTION_Server := False;
      ZConnection_SERVER.Connected := False;
      Label_CONECCION_STATUS.Caption := 'Conectado: NO';
      Label_STATUSBAR_PWD.Caption := 'Error: No se puede conectar';
    end;
  end;
end;


A lo que me refiero es al respaldo que hago aca en mi programa, no lo reconoce el MySQL administrator.
Se entiende o no??.

Este es el contenido que genero en el archivo ecam_backup.bat

cmd /c "C:\Pascal\MySQL\MySQL Server 5.1\bin\mysqldump.exe" -h localhost -u ecam_user -pdelphi ecam_db > "C:\Pascal\Libprj\Ecam MySQL\System\ecam_data.sql"

Y este el contenido que genero en el archivo ecam_restore.bat

cmd /c "C:\Pascal\MySQL\MySQL Server 5.1\bin\mysql.exe" -h localhost -u ecam_user -pdelphi ecam_db < "C:\Pascal\Libprj\Ecam MySQL\System\ecam_data.sql"

Cuando ejecuto el archivo ecam_restore.bat restaura la base de datos, pero si habro el archivo ecam_data.sql el que contine la base de datos, desde el MySQL administrador este no lo reconoce como valido y no lo restaura, a eso me refiero no hay compatibilidad entre la forma en que creo mi respaldo y como lo crea el administrador MySQL. ¿Como podria resolver este percance??.



Este codigo le servira a muchos.


Saludos

Última edición por RebeccaGL fecha: 12-10-2010 a las 15:50:41.
Responder Con Cita
Respuesta



Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Saltar a Foro

Temas Similares
Tema Autor Foro Respuestas Último mensaje
mysqldump y mysql.exe astarothls Conexión con bases de datos 0 30-12-2008 22:26:22
Ayuda con Mysqldump citlalliDgp Varios 3 19-01-2008 00:43:51
Detalle con el mysqldump Ken_Masters MySQL 2 30-07-2007 02:20:34
Mysqldump y respaldos Ken_Masters MySQL 1 27-07-2007 21:39:18
problema con mysqldump ercrizeporta Conexión con bases de datos 1 28-05-2007 14:57:46


La franja horaria es GMT +2. Ahora son las 16:27:47.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi
Copyright 1996-2007 Club Delphi