AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Programmierung allgemein Datenbanken Delphi per MySQL direct komplette Datenbank lesen und speichern?

per MySQL direct komplette Datenbank lesen und speichern?

Ein Thema von Deltachaos · begonnen am 2. Mai 2008 · letzter Beitrag vom 4. Mai 2008
Antwort Antwort
Benutzerbild von Deltachaos
Deltachaos

Registriert seit: 20. Feb 2008
Ort: Berlin
195 Beiträge
 
Delphi 7 Personal
 
#1

per MySQL direct komplette Datenbank lesen und speichern?

  Alt 2. Mai 2008, 19:33
Datenbank: MySQL • Zugriff über: MySQL direct (Delphi)
Hallo kan ich per MySQL Direct die komplette Datenbank exportiren/denn inhalt igendwie Speichern?

Ich kann schon eine Verbindung aufbauen.

Hier mein Codeansatz:

Delphi-Quellcode:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient,
  IdFTP, StdCtrls, ComCtrls, inifiles, umysqlvio, uMysqlCT, uMysqlClient, uMysqlHelpers;

{$I mysqlinc.inc}

type
  TForm1 = class(TForm)
    IdFTP1: TIdFTP;
    TrackBar1: TTrackBar;
    Button1: TButton;
    Memo1: TMemo;
    hostname: TEdit;
    port: TEdit;
    username: TEdit;
    password: TEdit;
    Button2: TButton;
    Button3: TButton;
    mysqlhost: TEdit;
    mysqlport: TEdit;
    mysqlusername: TEdit;
    mysqlpassword: TEdit;
    mysqldatenbankname: TEdit;
    Label1: TLabel;
    Label2: TLabel;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
  private
    FMysql: TMysqlClient;
    FResult: TMysqlResult;
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

var log, sett: TIniFile;
    Present: TDateTime;
    Year, Month, Day, Hour, Min, Sec, MSec: Word;
Damitt sich die Buchstaben "von selbst tippen"
Delphi-Quellcode:
procedure dos(Eingabe: String; sleeper: integer);
var I:Integer;
const
  U = #13 + #10;
begin
  for I:=1 to Length(Eingabe) do
    begin
      form1.Memo1.Text:=form1.Memo1.Text+Eingabe[I];
      form1.Memo1.Refresh;
      Sleep(sleeper)
    end;
  form1.Memo1.Text:=form1.Memo1.Text + u;
end;
Kleine Spielerei, Fenster Transparent machen
Delphi-Quellcode:
procedure TForm1.Button1Click(Sender: TObject);
var trans: integer;
begin
  Present:= Now;
  DecodeDate(Present, Year, Month, Day);
  DecodeTime(Present, Hour, Min, Sec, MSec);
  trans:= form1.TrackBar1.Position * 2;
  trans:= trans div 5;
  log.WriteString(inttostr(day)+'.'+inttostr(month)+'.'+inttostr(Year), inttostr(hour) +':'+ inttostr(min) +':'+ inttostr(sec), '>>> Ändere Programmtransparentz auf: '+ inttostr(trans) + '%');
  alphablendvalue:=form1.TrackBar1.Position;
  Alphablend:=true;
end;
Verbindung zur MySQL Datenbank;
Delphi-Quellcode:
procedure vermysql;
begin
  Present:= Now;
  DecodeDate(Present, Year, Month, Day);
  DecodeTime(Present, Hour, Min, Sec, MSec);
  log.WriteString(inttostr(day)+'.'+inttostr(month)+'.'+inttostr(Year), inttostr(hour) +':'+ inttostr(min) +':'+ inttostr(sec), 'Setze MySQL-Port auf ' + form1.mysqlport.Text);
  dos('['+ inttostr(hour) +':'+ inttostr(min) +':'+ inttostr(sec) +'] Setze MySQL-Port auf ' + form1.mysqlport.Text, 60);
  log.WriteString(inttostr(day)+'.'+inttostr(month)+'.'+inttostr(Year), inttostr(hour) +':'+ inttostr(min) +':'+ inttostr(sec), 'Verbinde zu MySQL-Host ['+form1.mysqlhost.Text+']...');
  dos('['+ inttostr(hour) +':'+ inttostr(min) +':'+ inttostr(sec) +'] Verbinde zu MySQL-Host ['+form1.mysqlhost.Text+']...', 60);
  form1.FMysql.Host := form1.mysqlhost.Text;
  form1.FMysql.port := strtoint(form1.mysqlport.text);

  Present:= Now;
  DecodeTime(Present, Hour, Min, Sec, MSec);
  log.WriteString(inttostr(day)+'.'+inttostr(month)+'.'+inttostr(Year), inttostr(hour) +':'+ inttostr(min) +':'+ inttostr(sec), 'Sende MySQL-Username ['+ form1.mysqlusername.Text +']');
  dos('['+ inttostr(hour) +':'+ inttostr(min) +':'+ inttostr(sec) +'] Sende MySQL-Username ['+ form1.mysqlusername.Text +']...', 60);
  form1.FMysql.user := form1.mysqlusername.Text;

  Present:= Now;
  DecodeTime(Present, Hour, Min, Sec, MSec);
  log.WriteString(inttostr(day)+'.'+inttostr(month)+'.'+inttostr(Year), inttostr(hour) +':'+ inttostr(min) +':'+ inttostr(sec), 'Sende MySQL-Username ['+ form1.mysqlpassword.Text +']');
  dos('['+ inttostr(hour) +':'+ inttostr(min) +':'+ inttostr(sec) +'] Sende MySQL-Password ['+ form1.mysqlpassword.Text +']...', 60);
  form1.FMysql.password := form1.mysqlpassword.Text;

  form1.FMysql.UnixSocket := '';
  Present:= Now;
  DecodeTime(Present, Hour, Min, Sec, MSec);
  log.WriteString(inttostr(day)+'.'+inttostr(month)+'.'+inttostr(Year), inttostr(hour) +':'+ inttostr(min) +':'+ inttostr(sec), 'Öffne MySQL-Datenbank ['+form1.mysqldatenbankname.Text+'...');
  dos('['+ inttostr(hour) +':'+ inttostr(min) +':'+ inttostr(sec) +'] Öffne MySQL-Datenbank ['+ form1.mysqldatenbankname.Text +'...', 60);
  form1.FMysql.Db := form1.mysqldatenbankname.Text; // Datenbank auf dem Server

  form1.FMysql.UseNamedPipe := false;
  form1.FMysql.UseSSL := false;
  form1.FMysql.Compress := true;
  form1.FMysql.TrySockets := false;
  if form1.FMysql.Connect then
    begin
      Present:= Now;
      DecodeDate(Present, Year, Month, Day);
      DecodeTime(Present, Hour, Min, Sec, MSec);
      log.WriteString(inttostr(day)+'.'+inttostr(month)+'.'+inttostr(Year), inttostr(hour) +':'+ inttostr(min) +':'+ inttostr(sec), 'Verbindung zu MySQL-Datenbank erfolgreich!');
      dos('['+ inttostr(hour) +':'+ inttostr(min) +':'+ inttostr(sec) +'] Verbindung zu MySQL-Datenbank erfolgreich!', 60)
    end
  else
    begin
      Present:= Now;
      DecodeDate(Present, Year, Month, Day);
      DecodeTime(Present, Hour, Min, Sec, MSec);
      dos('['+ inttostr(hour) +':'+ inttostr(min) +':'+ inttostr(sec) +'] Verbindung zu MySQL-Datenbank felgeschlagen!', 60);
      log.WriteString(inttostr(day)+'.'+inttostr(month)+'.'+inttostr(Year), inttostr(hour) +':'+ inttostr(min) +':'+ inttostr(sec), 'Verbindung zu MySQL-Datenbank felgeschlagen!');
    end;
end;
Verbinde zum FTP-Server (Soll ja mal ein Hompagebackupprogramm werden)
Delphi-Quellcode:
procedure dlord;
begin
  form1.Show;
  form1.IdFTP1.Port:=strtoint(form1.port.Text);
  Present:= Now;
  DecodeDate(Present, Year, Month, Day);
  DecodeTime(Present, Hour, Min, Sec, MSec);
  log.WriteString(inttostr(day)+'.'+inttostr(month)+'.'+inttostr(Year), inttostr(hour) +':'+ inttostr(min) +':'+ inttostr(sec), 'Setze FTP-Port auf '+ form1.port.Text +'...');
  dos('['+ inttostr(hour) +':'+ inttostr(min) +':'+ inttostr(sec) +'] Setze FTP-Port auf '+ form1.port.Text +'...', 60);
  sleep(100);

  form1.IdFTP1.Username:=form1.username.Text;
  Present:= Now;
  DecodeTime(Present, Hour, Min, Sec, MSec);
  log.WriteString(inttostr(day)+'.'+inttostr(month)+'.'+inttostr(Year), inttostr(hour) +':'+ inttostr(min) +':'+ inttostr(sec), 'Übertrage FTP-Username ['+ form1.username.Text +']...');
  dos('['+ inttostr(hour) +':'+ inttostr(min) +':'+ inttostr(sec) +'] Übertrage FTP-Username ['+ form1.username.Text +']...', 60);
  sleep(100);

  form1.IdFTP1.Username:=form1.username.Text;
  Present:= Now;
  DecodeTime(Present, Hour, Min, Sec, MSec);
  log.WriteString(inttostr(day)+'.'+inttostr(month)+'.'+inttostr(Year), inttostr(hour) +':'+ inttostr(min) +':'+ inttostr(sec), 'Übertrage FTP-Password ['+ form1.password.Text +']...');
  dos('['+ inttostr(hour) +':'+ inttostr(min) +':'+ inttostr(sec) +'] Übertrage FTP-Password ['+ form1.password.Text +']...', 60);
  sleep(100);

  form1.IdFTP1.Password:=form1.password.Text;
  Present:= Now;
  DecodeTime(Present, Hour, Min, Sec, MSec);
  log.WriteString(inttostr(day)+'.'+inttostr(month)+'.'+inttostr(Year), inttostr(hour) +':'+ inttostr(min) +':'+ inttostr(sec), 'Verbinde mit FTP-Host ['+ form1.hostname.Text +']...');
  dos('['+ inttostr(hour) +':'+ inttostr(min) +':'+ inttostr(sec) +'] Verbinde mit FTP-Host ['+ form1.hostname.Text +']...', 60);
  sleep(100);

  form1.IdFTP1.Host:=form1.hostname.Text;
  Present:= Now;
  DecodeTime(Present, Hour, Min, Sec, MSec);
  log.WriteString(inttostr(day)+'.'+inttostr(month)+'.'+inttostr(Year), inttostr(hour) +':'+ inttostr(min) +':'+ inttostr(sec), 'Warte auf FTP-Server...');
  dos('['+ inttostr(hour) +':'+ inttostr(min) +':'+ inttostr(sec) +'] Warte auf FTP-Server...', 60);
  try
  form1.IdFTP1.Connect;
  if form1.IdFTP1.Connected then
    begin
      Present:= Now;
      DecodeTime(Present, Hour, Min, Sec, MSec);
      log.WriteString(inttostr(day)+'.'+inttostr(month)+'.'+inttostr(Year), inttostr(hour) +':'+ inttostr(min) +':'+ inttostr(sec), 'FTP-Verbindung Hergestellt.');
      dos('['+ inttostr(hour) +':'+ inttostr(min) +':'+ inttostr(sec) +'] FTP-Verbindung Hergestellt.', 60);
    end;
  except
    Present:= Now;
    DecodeTime(Present, Hour, Min, Sec, MSec);
    log.WriteString(inttostr(day)+'.'+inttostr(month)+'.'+inttostr(Year), inttostr(hour) +':'+ inttostr(min) +':'+ inttostr(sec), 'FTP-Verbindung konnte nicht Hergestellt werdern.');
    dos('['+ inttostr(hour) +':'+ inttostr(min) +':'+ inttostr(sec) +'] FTP-Verbindung konnte nicht Hergestellt werdern.', 60);
  end;
end;
Zum Conecten und speicher des Feld Inhaltes
Delphi-Quellcode:
procedure TForm1.Button2Click(Sender: TObject);
begin
  dlord;
  vermysql;
  
  sett.WriteString('FTP', 'Hostname', form1.hostname.Text);
  sett.WriteString('FTP', 'Port', form1.port.Text);
  sett.WriteString('FTP', 'Username', form1.username.Text);
  sett.WriteString('FTP', 'Password', form1.password.Text);

  sett.WriteString('MySQL', 'Hostname', form1.mysqlhost.Text);
  sett.WriteString('MySQL', 'Port', form1.mysqlport.Text);
  sett.WriteString('MySQL', 'Username', form1.mysqlusername.Text);
  sett.WriteString('MySQL', 'Password', form1.mysqlpassword.Text);
  sett.WriteString('MySQL', 'Datenbankname', form1.mysqldatenbankname.Text);

  form1.Button2.Enabled:= false;
  form1.Button3.Enabled:= true;
end;
Zum Disconnecten
Delphi-Quellcode:
procedure TForm1.Button3Click(Sender: TObject);
begin
  Present:= Now;
  DecodeDate(Present, Year, Month, Day);
  DecodeTime(Present, Hour, Min, Sec, MSec);
  dos('['+ inttostr(hour) +':'+ inttostr(min) +':'+ inttostr(sec) +'] Trenne Verbindung...', 60);
  log.WriteString(inttostr(day)+'.'+inttostr(month)+'.'+inttostr(Year), inttostr(hour) +':'+ inttostr(min) +':'+ inttostr(sec), 'Trenne Verbindung...');
  if FMysql.Connected then
     FMysql.close;
  if form1.IdFTP1.Connected then
     form1.IdFTP1.Disconnect;
  Present:= Now;
  DecodeTime(Present, Hour, Min, Sec, MSec);
  dos('['+ inttostr(hour) +':'+ inttostr(min) +':'+ inttostr(sec) +'] Verbindung getrennt!', 60);
  log.WriteString(inttostr(day)+'.'+inttostr(month)+'.'+inttostr(Year), inttostr(hour) +':'+ inttostr(min) +':'+ inttostr(sec), 'Verbindung getrennt!');
  form1.Button3.Enabled:= false;
  form1.Button2.Enabled:= true;
end;

Lesen der Voreinstellungen der settings.ini
Delphi-Quellcode:
procedure TForm1.FormCreate(Sender: TObject);
begin
  FMysql := TMysqlClient.create;
  sett:= TiniFile.Create(ExtractFilePath(ParamStr(0))+
                         'settings.ini');
  log:= TiniFile.Create(ExtractFilePath(ParamStr(0))+
                        'log.txt');
  Present:= Now;
  DecodeDate(Present, Year, Month, Day);
  DecodeTime(Present, Hour, Min, Sec, MSec);
  log.WriteString(inttostr(day)+'.'+inttostr(month)+'.'+inttostr(Year), inttostr(hour) +':'+ inttostr(min) +':'+ inttostr(sec), '>>> Programmstart');
  form1.hostname.Text:= sett.ReadString('FTP', 'Hostname', 'FTP-Hostname');
  form1.port.Text:= sett.ReadString('FTP', 'Port', 'FTP-Port');
  form1.username.Text:= sett.ReadString('FTP', 'Username', 'FTP-Username');
  form1.password.Text:= sett.ReadString('FTP', 'Password', 'FTP-Password');

  form1.mysqlhost.Text:= sett.ReadString('MySQL', 'Hostname', 'MySQL-Hostname');
  form1.mysqlport.Text:= sett.ReadString('MySQL', 'Port', 'MySQL-Port');
  form1.mysqlusername.Text:= sett.ReadString('MySQL', 'Username', 'MySQL-Username');
  form1.mysqlpassword.Text:= sett.ReadString('MySQL', 'Password', 'MySQL-Password');
  form1.mysqldatenbankname.Text:= sett.ReadString('MySQL', 'Datenbankname', 'MySQL-Datenbankname');
end;
Delphi-Quellcode:
procedure TForm1.FormDestroy(Sender: TObject);
begin
  Present:= Now;
  DecodeDate(Present, Year, Month, Day);
  DecodeTime(Present, Hour, Min, Sec, MSec);
  log.WriteString(inttostr(day)+'.'+inttostr(month)+'.'+inttostr(Year), inttostr(hour) +':'+ inttostr(min) +':'+ inttostr(sec), '>>> Programmende');
  FMysql.Free;
  if FResult<>nil then
    FResult.free;
end;

end.
Dass funktionirt ja auch so weit ich weis nur nicht weiter mit dem Backup!
Angehängte Dateien
Dateityp: rar back_191.rar (317,3 KB, 2x aufgerufen)
Maximilian Ruta
  Mit Zitat antworten Zitat
marabu

Registriert seit: 6. Apr 2005
10.109 Beiträge
 
#2

Re: per MySQL direct komplette Datenbank lesen und speichern

  Alt 2. Mai 2008, 21:54
Hallo Maximilian,

je nachdem, ob du eine Datenbank als Ganzes (mysqldump, mysqlhotcopy) oder alle Tabellen einzeln (LOCK TABLES; SELECT INTO OUTFILE) sichern möchtest, musst du anders vorgehen.

Lies dir dazu mal das Kapitel "Database Administration :: Backup and Recovery" in der MySQL Dokumentation durch.

Gute Nacht
  Mit Zitat antworten Zitat
Benutzerbild von Deltachaos
Deltachaos

Registriert seit: 20. Feb 2008
Ort: Berlin
195 Beiträge
 
Delphi 7 Personal
 
#3

Re: per MySQL direct komplette Datenbank lesen und speichern

  Alt 3. Mai 2008, 08:34
Zitat von marabu:
Hallo Maximilian,

je nachdem, ob du eine Datenbank als Ganzes (mysqldump, mysqlhotcopy) oder alle Tabellen einzeln (LOCK TABLES; SELECT INTO OUTFILE) sichern möchtest, musst du anders vorgehen.

Lies dir dazu mal das Kapitel "Database Administration :: Backup and Recovery" in der MySQL Dokumentation durch.

Gute Nacht
Ich wies nich genau was einfacher ist.
Aufjedenfall sollte das Bakup wieder aufspielbar sein. entweder über das Programm oder über PHPmyAdmin
Maximilian Ruta
  Mit Zitat antworten Zitat
Benutzerbild von Deltachaos
Deltachaos

Registriert seit: 20. Feb 2008
Ort: Berlin
195 Beiträge
 
Delphi 7 Personal
 
#4

Re: per MySQL direct komplette Datenbank lesen und speichern

  Alt 3. Mai 2008, 14:15
Noch wer da?
Maximilian Ruta
  Mit Zitat antworten Zitat
Benutzerbild von Deltachaos
Deltachaos

Registriert seit: 20. Feb 2008
Ort: Berlin
195 Beiträge
 
Delphi 7 Personal
 
#5

Re: per MySQL direct komplette Datenbank lesen und speichern

  Alt 4. Mai 2008, 13:53
Ich denckemal alle tabellen eizeln da der MySQl Benutzer nicht die rechte hat eine neue Datenbank zu erstellen. sagt auf jedenfall PHPmyAdmin

Ich hab mir das etz mal durchgelesen.

Zitat:
Another technique for backing up a database is to use the mysqldump program or the mysqlhotcopy script. mysqldump is more general because it can back up all kinds of tables. mysqlhotcopy works only with some storage engines. (See Section 4.5.4, “mysqldump — A Database Backup Program”, and Section 4.6.8, “mysqlhotcopy — A Database Backup Program”.)

Create a full backup of your database:

shell> mysqldump --tab=/path/to/some/dir --opt db_name

Or:

shell> mysqlhotcopy db_name /path/to/some/dir

You can also create a binary backup simply by copying all table files (*.frm, *.MYD, and *.MYI files), as long as the server isn't updating anything. The mysqlhotcopy script uses this method. (But note that these methods do not work if your database contains InnoDB tables. InnoDB does not necessarily store table contents in database directories, and mysqlhotcopy works only for MyISAM and ISAM tables.)

For InnoDB tables, it is possible to perform an online backup that takes no locks on tables; see Section 4.5.4, “mysqldump — A Database Backup Program”.
meine Frage ist jetzt funktionirt das auch mit MySQL Direct oder besser: kann man mit MySQL direct wol jeden von der Datenbank unterstützen Befehl ausfüren?? wen ja wehre das Ja toll
Maximilian Ruta
  Mit Zitat antworten Zitat
Themen-Optionen Thema durchsuchen
Thema durchsuchen:

Erweiterte Suche
Ansicht

Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 03:02 Uhr.
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz