Search

データベース全体を最速ダンプ
#NAME?

unknown

mysqldump --opt データベース名 > 出力ファイル名

戻す場合は、shell> mysql データベース名 < 出力ファイル名

C:\mysql\bin> mysqldump --opt db_User -u root -p > C:\mysql\data\backup-file.sql Enter
Enter password: ***** Enter

C:\mysql\bin>
出力ファイル(backup-file.sql)の内容
-- MySQL dump 9.11
--
-- Host: localhost    Database: db_User
-- ------------------------------------------------------
-- Server version    4.0.26-nt

--
-- Table structure for table `tbl_address`
--

DROP TABLE IF EXISTS tbl_address;
CREATE TABLE tbl_address (
  UserID varchar(4) NOT NULL default '',
  Zip int(11) default NULL,
  Ken varchar(200) NOT NULL default '',
  Addr varchar(200) default NULL,
  PRIMARY KEY  (UserID)
) TYPE=MyISAM;

--
-- Dumping data for table `tbl_address`
--


/*!40000 ALTER TABLE tbl_address DISABLE KEYS */;
LOCK TABLES tbl_address WRITE;
INSERT INTO tbl_address VALUES ('U001',2140012,'神奈川県','川崎市多摩区1-2-3'),('U002',1500012,'東京都','渋谷区広尾3-2-1'),('U003',1660003,'東京都','高円寺南5-6-7'),('U004',2280001,'神奈川県','座間市相模が丘9999'),('U005',1600021,'東京都','新宿区歌舞伎町10-20-30'),('U006',1080071,'東京都','港区白金台1000 白金ヒルズ1-304'),('U007',1900021,'東京都','立川市羽衣町50');
UNLOCK TABLES;
/*!40000 ALTER TABLE tbl_address ENABLE KEYS */;

--
-- Table structure for table `tbl_customer`
--

DROP TABLE IF EXISTS tbl_customer;
CREATE TABLE tbl_customer (
  UserID varchar(4) NOT NULL default '',
  FirstName varchar(32) NOT NULL default '',
  LastName varchar(32) NOT NULL default '',
  Sex char(2) default NULL,
  Age int(11) default NULL,
  PRIMARY KEY  (UserID)
) TYPE=MyISAM;

--
-- Dumping data for table `tbl_customer`
--


/*!40000 ALTER TABLE tbl_customer DISABLE KEYS */;
LOCK TABLES tbl_customer WRITE;
INSERT INTO tbl_customer VALUES ('U001','花子','鈴木','f',21),('U002','太郎','田中','m',30),('U003','一郎','鈴木','m',45),('U004','萌子','山口','f',18),('U005','愛','森永','f',21),('U006','太郎','鈴木','m',22),('U007','花子','佐藤','f',35);
UNLOCK TABLES;
/*!40000 ALTER TABLE tbl_customer ENABLE KEYS */;

データベースやテーブルをダンプ

unknown

mysqldump [OPTIONS] データベース名 [ テーブル名 ] または mysqldump [OPTIONS] --databases [OPTIONS] データベース名1 [データベース名2 ... ] または mysqldump [OPTIONS] --all -databases [OPTIONS]

mysqldumpコマンドのヘルプ表示
-?, --help

unknown

mysqldump [-? | --help]
C:\mysql\bin> mysql --help Enter
mysql  Ver 12.22 Distrib 4.0.26, for Win32 (ia32)
Copyright (C) 2002 MySQL AB
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL license
Usage: mysql [OPTIONS] [database]
  -?, --help          Display this help and exit.
  --auto-rehash       Enable automatic rehashing. One doesn't need to use
                      'rehash' to get table and field completion, but startup
                      and reconnecting may take a longer time. Disable with
                      --disable-auto-rehash.
  -A, --no-auto-rehash
                      No automatic rehashing. One has to use 'rehash' to get
                      table and field completion. This gives a quicker start of
                      mysql and disables rehashing on reconnect. WARNING:
                      options deprecated; use --disable-auto-rehash instead.
  -B, --batch         Print results with a tab as separator, each row on new
                      line. Doesn't use history file.
  --character-sets-dir=name
                      Directory where character sets are.
  --default-character-set=name
                      Set the default character set.
  -C, --compress      Use compression in server/client protocol.
  -D, --database=name Database to use.
  -e, --execute=name  Execute command and quit. (Output like with --batch).
  -E, --vertical      Print the output of a query (rows) vertically.
  -f, --force         Continue even if we get an sql error.
  -g, --no-named-commands
                      Named commands are disabled. Use \* form only, or use
                      named commands only in the beginning of a line ending
                      with a semicolon (;) Since version 10.9 the client now
                      starts with this option ENABLED by default! Disable with
                      '-G'. Long format commands still work from the first
                      line. WARNING: option deprecated; use
                      --disable-named-commands instead.
  -G, --named-commands
                      Enable named commands. Named commands mean this program's
                      internal commands; see mysql> help . When enabled, the
                      named commands can be used from any line of the query,
                      otherwise only from the first line, before an enter.
                      Disable with --disable-named-commands. This option is
                      disabled by default.
  -i, --ignore-spaces Ignore space after function names.
  --local-infile      Enable/disable LOAD DATA LOCAL INFILE.
  -b, --no-beep       Turn off beep on error.
  -h, --host=name     Connect to host.
  -H, --html          Produce HTML output.
  -X, --xml           Produce XML output
  --line-numbers      Write line numbers for errors.
  -L, --skip-line-numbers
                      Don't write line number for errors. WARNING: -L is
                      deprecated, use long version of this option instead.
  --no-tee            Disable outfile. See interactive help (\h) also. WARNING:
                      option deprecated; use --disable-tee instead
  -n, --unbuffered    Flush buffer after each query.
  --column-names      Write column names in results.
  -N, --skip-column-names
                      Don't write column names in results. WARNING: -N is
                      deprecated, use long version of this options instead.
  -O, --set-variable=name
                      Change the value of a variable. Please note that this
                      option is deprecated; you can set variables directly with
                      --variable-name=value.
  -o, --one-database  Only update the default database. This is useful for
                      skipping updates to other database in the update log.
  -p, --password[=name]
                      Password to use when connecting to server. If password is
                      not given it's asked from the tty.
  -W, --pipe          Use named pipes to connect to server.
  -P, --port=#        Port number to use for connection.
  --prompt=name       Set the mysql prompt to this value.
  -q, --quick         Don't cache result, print it row by row. This may slow
                      down the server if the output is suspended. Doesn't use
                      history file.
  -r, --raw           Write fields without conversion. Used with --batch
  -s, --silent        Be more silent.
  -S, --socket=name   Socket file to use for connection.
  -t, --table         Output in table format.
  -T, --debug-info    Print some debug info at exit.
  --tee=name          Append everything into outfile. See interactive help (\h)
                      also. Does not work in batch mode.
  -u, --user=name     User for login if not current user.
  -U, --safe-updates  Only allow UPDATE and DELETE that uses keys.
  -U, --i-am-a-dummy  Synonym for option --safe-updates, -U.
  -v, --verbose       Write more. (-v -v -v gives the table output format)
  -V, --version       Output version information and exit.
  -w, --wait          Wait and retry if connection is down.
  --connect_timeout=#
  --max_allowed_packet=#
  --net_buffer_length=#
  --select_limit=#
  --max_join_size=#

Default options are read from the following files in the given order:
C:\WINDOWS\my.ini C:\WINDOWS\my.cnf C:\my.ini C:\my.cnf
The following groups are read: mysql client
The following options may be given as the first argument:
--print-defaults        Print the program argument list and exit
--no-defaults           Don't read default options from any options file
--defaults-file=#       Only read default options from the given file #
--defaults-extra-file=# Read this file after the global files are read

Variables (--variable-name=value)
and boolean options {FALSE|TRUE}  Value (after reading options)
--------------------------------- -----------------------------
auto-rehash                       TRUE
character-sets-dir                (No default value)
default-character-set             sjis
compress                          FALSE
database                          (No default value)
vertical                          FALSE
force                             FALSE
named-commands                    FALSE
local-infile                      FALSE
no-beep                           FALSE
host                              (No default value)
html                              FALSE
xml                               FALSE
line-numbers                      TRUE
unbuffered                        FALSE
column-names                      TRUE
port                              3306
prompt                            mysql>
quick                             FALSE
raw                               FALSE
socket                            (No default value)
table                             FALSE
debug-info                        FALSE
user                              (No default value)
safe-updates                      FALSE
i-am-a-dummy                      FALSE
connect_timeout                   0
max_allowed_packet                16777216
net_buffer_length                 16384
select_limit                      1000
max_join_size                     1000000

C:\mysql\bin>

全データベースのバックアップをファイル出力
#NAME?

unknown

mysqldump --all-databases > 出力ファイル名
C:\mysql\bin> mysqldump --all-databases -u root -p > c:\mysql\data\all_databases.sql Enter
Enter password: ***** Enter

C:\mysql\bin>
出力ファイル(all_databases.sql)の内容
-- MySQL dump 9.11
--
-- Host: localhost    Database: 
-- ------------------------------------------------------
-- Server version    4.0.26-nt

--
-- Current Database: bk
--

CREATE DATABASE /*!32312 IF NOT EXISTS*/ bk;

USE bk;

--
-- Current Database: db_pet
--

CREATE DATABASE /*!32312 IF NOT EXISTS*/ db_pet;

USE db_pet;

--
-- Table structure for table `tbl_pet`
--

CREATE TABLE tbl_pet (
  PetID varchar(4) NOT NULL default '',
  Name varchar(32) NOT NULL default '',
  Species varchar(20) NOT NULL default '',
  Birth date default NULL,
  Sex char(2) default NULL,
  PRIMARY KEY  (PetID)
) TYPE=MyISAM;

--
-- Dumping data for table `tbl_pet`
--


--
-- Current Database: db_user
--

CREATE DATABASE /*!32312 IF NOT EXISTS*/ db_user;

USE db_user;

--
-- Table structure for table `tbl_address`
--

CREATE TABLE tbl_address (
  UserID varchar(4) NOT NULL default '',
  Zip int(11) default NULL,
  Ken varchar(200) NOT NULL default '',
  Addr varchar(200) default NULL,
  PRIMARY KEY  (UserID)
) TYPE=MyISAM;

--
-- Dumping data for table `tbl_address`
--

INSERT INTO tbl_address VALUES ('U001',2140012,'神奈川県','川崎市多摩区1-2-3');
INSERT INTO tbl_address VALUES ('U002',1500012,'東京都','渋谷区広尾3-2-1');
INSERT INTO tbl_address VALUES ('U003',1660003,'東京都','高円寺南5-6-7');
INSERT INTO tbl_address VALUES ('U004',2280001,'神奈川県','座間市相模が丘9999');
INSERT INTO tbl_address VALUES ('U005',1600021,'東京都','新宿区歌舞伎町10-20-30');
INSERT INTO tbl_address VALUES ('U006',1080071,'東京都','港区白金台1000 白金ヒルズ1-304');
INSERT INTO tbl_address VALUES ('U007',1900021,'東京都','立川市羽衣町50');

--
-- Table structure for table `tbl_customer`
--

CREATE TABLE tbl_customer (
  UserID varchar(4) NOT NULL default '',
  FirstName varchar(32) NOT NULL default '',
  LastName varchar(32) NOT NULL default '',
  Sex char(2) default NULL,
  Age int(11) default NULL,
  PRIMARY KEY  (UserID)
) TYPE=MyISAM;

--
-- Dumping data for table `tbl_customer`
--

INSERT INTO tbl_customer VALUES ('U001','花子','鈴木','f',21);
INSERT INTO tbl_customer VALUES ('U002','太郎','田中','m',30);
INSERT INTO tbl_customer VALUES ('U003','一郎','鈴木','m',45);
INSERT INTO tbl_customer VALUES ('U004','萌子','山口','f',18);
INSERT INTO tbl_customer VALUES ('U005','愛','森永','f',21);
INSERT INTO tbl_customer VALUES ('U006','太郎','鈴木','m',22);
INSERT INTO tbl_customer VALUES ('U007','花子','佐藤','f',35);

--
-- Current Database: mysql
--

CREATE DATABASE /*!32312 IF NOT EXISTS*/ mysql;

USE mysql;

--
-- Table structure for table `columns_priv`
--

CREATE TABLE columns_priv (
  Host char(60) binary NOT NULL default '',
  Db char(64) binary NOT NULL default '',
  User char(16) binary NOT NULL default '',
  Table_name char(64) binary NOT NULL default '',
  Column_name char(64) binary NOT NULL default '',
  Timestamp timestamp(14) NOT NULL,
  Column_priv set('Select','Insert','Update','References') NOT NULL default '',
  PRIMARY KEY  (Host,Db,User,Table_name,Column_name)
) TYPE=MyISAM COMMENT='Column privileges';

--
-- Dumping data for table `columns_priv`
--


--
-- Table structure for table `db`
--

CREATE TABLE db (
  Host char(60) binary NOT NULL default '',
  Db char(64) binary NOT NULL default '',
  User char(16) binary NOT NULL default '',
  Select_priv enum('N','Y') NOT NULL default 'N',
  Insert_priv enum('N','Y') NOT NULL default 'N',
  Update_priv enum('N','Y') NOT NULL default 'N',
  Delete_priv enum('N','Y') NOT NULL default 'N',
  Create_priv enum('N','Y') NOT NULL default 'N',
  Drop_priv enum('N','Y') NOT NULL default 'N',
  Grant_priv enum('N','Y') NOT NULL default 'N',
  References_priv enum('N','Y') NOT NULL default 'N',
  Index_priv enum('N','Y') NOT NULL default 'N',
  Alter_priv enum('N','Y') NOT NULL default 'N',
  Create_tmp_table_priv enum('N','Y') NOT NULL default 'N',
  Lock_tables_priv enum('N','Y') NOT NULL default 'N',
  PRIMARY KEY  (Host,Db,User),
  KEY User (User)
) TYPE=MyISAM COMMENT='Database privileges';

--
-- Dumping data for table `db`
--

INSERT INTO db VALUES ('%','test','','Y','Y','Y','Y','Y','Y','N','Y','Y','Y','Y','Y');
INSERT INTO db VALUES ('%','test\\_%','','Y','Y','Y','Y','Y','Y','N','Y','Y','Y','Y','Y');
INSERT INTO db VALUES ('localhost','db_customer','coco','Y','Y','Y','Y','Y','Y','N','Y','Y','Y','Y','Y');

--
-- Table structure for table `func`
--

CREATE TABLE func (
  name char(64) binary NOT NULL default '',
  ret tinyint(1) NOT NULL default '0',
  dl char(128) NOT NULL default '',
  type enum('function','aggregate') NOT NULL default 'function',
  PRIMARY KEY  (name)
) TYPE=MyISAM COMMENT='User defined functions';

--
-- Dumping data for table `func`
--


--
-- Table structure for table `host`
--

CREATE TABLE host (
  Host char(60) binary NOT NULL default '',
  Db char(64) binary NOT NULL default '',
  Select_priv enum('N','Y') NOT NULL default 'N',
  Insert_priv enum('N','Y') NOT NULL default 'N',
  Update_priv enum('N','Y') NOT NULL default 'N',
  Delete_priv enum('N','Y') NOT NULL default 'N',
  Create_priv enum('N','Y') NOT NULL default 'N',
  Drop_priv enum('N','Y') NOT NULL default 'N',
  Grant_priv enum('N','Y') NOT NULL default 'N',
  References_priv enum('N','Y') NOT NULL default 'N',
  Index_priv enum('N','Y') NOT NULL default 'N',
  Alter_priv enum('N','Y') NOT NULL default 'N',
  Create_tmp_table_priv enum('N','Y') NOT NULL default 'N',
  Lock_tables_priv enum('N','Y') NOT NULL default 'N',
  PRIMARY KEY  (Host,Db)
) TYPE=MyISAM COMMENT='Host privileges;  Merged with database privileges';

--
-- Dumping data for table `host`
--


--
-- Table structure for table `tables_priv`
--

CREATE TABLE tables_priv (
  Host char(60) binary NOT NULL default '',
  Db char(64) binary NOT NULL default '',
  User char(16) binary NOT NULL default '',
  Table_name char(64) binary NOT NULL default '',
  Grantor char(77) NOT NULL default '',
  Timestamp timestamp(14) NOT NULL,
  Table_priv set('Select','Insert','Update','Delete','Create','Drop','Grant','References','Index','Alter') NOT NULL default '',
  Column_priv set('Select','Insert','Update','References') NOT NULL default '',
  PRIMARY KEY  (Host,Db,User,Table_name),
  KEY Grantor (Grantor)
) TYPE=MyISAM COMMENT='Table privileges';

--
-- Dumping data for table `tables_priv`
--


--
-- Table structure for table `user`
--

CREATE TABLE user (
  Host varchar(60) binary NOT NULL default '',
  User varchar(16) binary NOT NULL default '',
  Password varchar(16) binary NOT NULL default '',
  Select_priv enum('N','Y') NOT NULL default 'N',
  Insert_priv enum('N','Y') NOT NULL default 'N',
  Update_priv enum('N','Y') NOT NULL default 'N',
  Delete_priv enum('N','Y') NOT NULL default 'N',
  Create_priv enum('N','Y') NOT NULL default 'N',
  Drop_priv enum('N','Y') NOT NULL default 'N',
  Reload_priv enum('N','Y') NOT NULL default 'N',
  Shutdown_priv enum('N','Y') NOT NULL default 'N',
  Process_priv enum('N','Y') NOT NULL default 'N',
  File_priv enum('N','Y') NOT NULL default 'N',
  Grant_priv enum('N','Y') NOT NULL default 'N',
  References_priv enum('N','Y') NOT NULL default 'N',
  Index_priv enum('N','Y') NOT NULL default 'N',
  Alter_priv enum('N','Y') NOT NULL default 'N',
  Show_db_priv enum('N','Y') NOT NULL default 'N',
  Super_priv enum('N','Y') NOT NULL default 'N',
  Create_tmp_table_priv enum('N','Y') NOT NULL default 'N',
  Lock_tables_priv enum('N','Y') NOT NULL default 'N',
  Execute_priv enum('N','Y') NOT NULL default 'N',
  Repl_slave_priv enum('N','Y') NOT NULL default 'N',
  Repl_client_priv enum('N','Y') NOT NULL default 'N',
  ssl_type enum('','ANY','X509','SPECIFIED') NOT NULL default '',
  ssl_cipher blob NOT NULL,
  x509_issuer blob NOT NULL,
  x509_subject blob NOT NULL,
  max_questions int(11) unsigned NOT NULL default '0',
  max_updates int(11) unsigned NOT NULL default '0',
  max_connections int(11) unsigned NOT NULL default '0',
  PRIMARY KEY  (Host,User)
) TYPE=MyISAM COMMENT='Users and global privileges';

--
-- Dumping data for table `user`
--

INSERT INTO user VALUES ('localhost','root','43e9a4ab75570f5b','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','','','','',0,0,0);
INSERT INTO user VALUES ('localhost','','','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','','','','',0,0,0);
INSERT INTO user VALUES ('localhost','coco','','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','N','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','','','','',0,0,0);

--
-- Current Database: sample
--

CREATE DATABASE /*!32312 IF NOT EXISTS*/ sample;

USE sample;

指定した複数のデータベースのバックアップをファイル出力
#NAME?

unknown

mysqldump --databases データベース名1 [データベース名2 ... ] > 出力ファイル名
C:\mysql\bin> mysqldump --databases db_User db_Pet -u root -p > c:\mysql\data\my_databases.sql Enter
Enter password: ***** Enter

C:\mysql\bin>
出力ファイル(my_databases.sql)の内容
-- MySQL dump 9.11
--
-- Host: localhost    Database: db_User
-- ------------------------------------------------------
-- Server version    4.0.26-nt

--
-- Current Database: db_User
--

CREATE DATABASE /*!32312 IF NOT EXISTS*/ db_User;

USE db_User;

--
-- Table structure for table `tbl_address`
--

CREATE TABLE tbl_address (
  UserID varchar(4) NOT NULL default '',
  Zip int(11) default NULL,
  Ken varchar(200) NOT NULL default '',
  Addr varchar(200) default NULL,
  PRIMARY KEY  (UserID)
) TYPE=MyISAM;

--
-- Dumping data for table `tbl_address`
--

INSERT INTO tbl_address VALUES ('U001',2140012,'神奈川県','川崎市多摩区1-2-3');
INSERT INTO tbl_address VALUES ('U002',1500012,'東京都','渋谷区広尾3-2-1');
INSERT INTO tbl_address VALUES ('U003',1660003,'東京都','高円寺南5-6-7');
INSERT INTO tbl_address VALUES ('U004',2280001,'神奈川県','座間市相模が丘9999');
INSERT INTO tbl_address VALUES ('U005',1600021,'東京都','新宿区歌舞伎町10-20-30');
INSERT INTO tbl_address VALUES ('U006',1080071,'東京都','港区白金台1000 白金ヒルズ1-304');
INSERT INTO tbl_address VALUES ('U007',1900021,'東京都','立川市羽衣町50');

--
-- Table structure for table `tbl_customer`
--

CREATE TABLE tbl_customer (
  UserID varchar(4) NOT NULL default '',
  FirstName varchar(32) NOT NULL default '',
  LastName varchar(32) NOT NULL default '',
  Sex char(2) default NULL,
  Age int(11) default NULL,
  PRIMARY KEY  (UserID)
) TYPE=MyISAM;

--
-- Dumping data for table `tbl_customer`
--

INSERT INTO tbl_customer VALUES ('U001','花子','鈴木','f',21);
INSERT INTO tbl_customer VALUES ('U002','太郎','田中','m',30);
INSERT INTO tbl_customer VALUES ('U003','一郎','鈴木','m',45);
INSERT INTO tbl_customer VALUES ('U004','萌子','山口','f',18);
INSERT INTO tbl_customer VALUES ('U005','愛','森永','f',21);
INSERT INTO tbl_customer VALUES ('U006','太郎','鈴木','m',22);
INSERT INTO tbl_customer VALUES ('U007','花子','佐藤','f',35);

--
-- Current Database: db_Pet
--

CREATE DATABASE /*!32312 IF NOT EXISTS*/ db_Pet;

USE db_Pet;

--
-- Table structure for table `tbl_pet`
--

CREATE TABLE tbl_pet (
  PetID varchar(4) NOT NULL default '',
  Name varchar(32) NOT NULL default '',
  Species varchar(20) NOT NULL default '',
  Birth date default NULL,
  Sex char(2) default NULL,
  PRIMARY KEY  (PetID)
) TYPE=MyISAM;

--
-- Dumping data for table `tbl_pet`
--

指定したデータベースのバックアップをファイル出力

unknown

mysqldump データベース名 > 出力ファイル名
C:\mysql\bin> mysqldump db_User -u root -p > c:\mysql\data\db_user_bk.sql Enter
Enter password: ***** Enter

C:\mysql\bin>
出力ファイル(db_user_bk.sql)の内容
-- MySQL dump 9.11
--
-- Host: localhost    Database: db_User
-- ------------------------------------------------------
-- Server version    4.0.26-nt

--
-- Table structure for table `tbl_address`
--

CREATE TABLE tbl_address (
  UserID varchar(4) NOT NULL default '',
  Zip int(11) default NULL,
  Ken varchar(200) NOT NULL default '',
  Addr varchar(200) default NULL,
  PRIMARY KEY  (UserID)
) TYPE=MyISAM;

--
-- Dumping data for table `tbl_address`
--

INSERT INTO tbl_address VALUES ('U001',2140012,'神奈川県','川崎市多摩区1-2-3');
INSERT INTO tbl_address VALUES ('U002',1500012,'東京都','渋谷区広尾3-2-1');
INSERT INTO tbl_address VALUES ('U003',1660003,'東京都','高円寺南5-6-7');
INSERT INTO tbl_address VALUES ('U004',2280001,'神奈川県','座間市相模が丘9999');
INSERT INTO tbl_address VALUES ('U005',1600021,'東京都','新宿区歌舞伎町10-20-30');
INSERT INTO tbl_address VALUES ('U006',1080071,'東京都','港区白金台1000 白金ヒルズ1-304');
INSERT INTO tbl_address VALUES ('U007',1900021,'東京都','立川市羽衣町50');

--
-- Table structure for table `tbl_customer`
--

CREATE TABLE tbl_customer (
  UserID varchar(4) NOT NULL default '',
  FirstName varchar(32) NOT NULL default '',
  LastName varchar(32) NOT NULL default '',
  Sex char(2) default NULL,
  Age int(11) default NULL,
  PRIMARY KEY  (UserID)
) TYPE=MyISAM;

--
-- Dumping data for table `tbl_customer`
--

INSERT INTO tbl_customer VALUES ('U001','花子','鈴木','f',21);
INSERT INTO tbl_customer VALUES ('U002','太郎','田中','m',30);
INSERT INTO tbl_customer VALUES ('U003','一郎','鈴木','m',45);
INSERT INTO tbl_customer VALUES ('U004','萌子','山口','f',18);
INSERT INTO tbl_customer VALUES ('U005','愛','森永','f',21);
INSERT INTO tbl_customer VALUES ('U006','太郎','鈴木','m',22);
INSERT INTO tbl_customer VALUES ('U007','花子','佐藤','f',35);

指定したテーブルのバックアップをファイル出力

unknown

mysqldump データベース名 テーブル名 > 出力ファイル名
C:\mysql\bin> mysqldump db_Pet tbl_Pet -u root -p > c:\mysql\data\tbl_pet.sql Enter
Enter password: ***** Enter

C:\mysql\bin>
出力ファイル(tbl_pet.sql)の内容
-- MySQL dump 9.11
--
-- Host: localhost    Database: db_Pet
-- ------------------------------------------------------
-- Server version    4.0.26-nt

--
-- Table structure for table `tbl_Pet`
--

CREATE TABLE tbl_pet (
  PetID varchar(4) NOT NULL default '',
  Name varchar(32) NOT NULL default '',
  Species varchar(20) NOT NULL default '',
  Birth date default NULL,
  Sex char(2) default NULL,
  PRIMARY KEY  (PetID)
) TYPE=MyISAM;

--
-- Dumping data for table `tbl_Pet`
--

指定した基本的なオプションのバックアップをファイル出力

unknown

mysqldump --opt -c -u ユーザー名 -p データベース名 [テーブル名] > 出力ファイル名
C:\mysql\bin> mysqldump --opt -c -u root -p db_Pet tbl_Pet > c:\mysql\data\tbl_pet_opt.sql Enter
Enter password: ***** Enter

C:\mysql\bin>
出力ファイル(tbl_pet_opt.sql)の内容
-- MySQL dump 9.11
--
-- Host: localhost    Database: db_Pet
-- ------------------------------------------------------
-- Server version    4.0.26-nt

--
-- Table structure for table `tbl_Pet`
--

DROP TABLE IF EXISTS tbl_Pet;
CREATE TABLE tbl_pet (
  PetID varchar(4) NOT NULL default '',
  Name varchar(32) NOT NULL default '',
  Species varchar(20) NOT NULL default '',
  Birth date default NULL,
  Sex char(2) default NULL,
  PRIMARY KEY  (PetID)
) TYPE=MyISAM;

--
-- Dumping data for table `tbl_Pet`
--


/*!40000 ALTER TABLE tbl_Pet DISABLE KEYS */;
LOCK TABLES tbl_Pet WRITE;
UNLOCK TABLES;
/*!40000 ALTER TABLE tbl_Pet ENABLE KEYS */;

データをカンマ区切りでファイル出力
--fields-terminated-by=, --fields-optionally-enclosed-by=\"

unknown

mysqldump -T 出力先ディレクトリパス --fields-terminated-by=, --fields-optionally-enclosed-by=\" データベース名

指定した出力ディレクトリパスに、「テーブル名.sql」というファイルが生成されます。

C:\mysql\bin> mysqldump -T c:\mysql\data --fields-terminated-by=, --fields-optionally-enclosed-by=\" -u root -p db_Pet Enter
Enter password: ***** Enter

C:\mysql\bin>
出力ファイル(tbl_pet.sql)の内容
-- MySQL dump 9.11
--
-- Host: localhost    Database: db_Pet
-- ------------------------------------------------------
-- Server version    4.0.26-nt

--
-- Table structure for table `tbl_pet`
--

CREATE TABLE tbl_pet (
  PetID varchar(4) NOT NULL default '',
  Name varchar(32) NOT NULL default '',
  Species varchar(20) NOT NULL default '',
  Birth date default NULL,
  Sex char(2) default NULL,
  PRIMARY KEY  (PetID)
) TYPE=MyISAM;

WHERE条件指定のバックアップをファイル出力
mysqldump -w"条件式"

unknown

mysqldump -w"条件式" データベース名 テーブル名 > 出力ファイル名

指定した条件に一致するデータのみ出力されます。

# 条件:女性(Sex='f')のユーザーのみバックアップ
C:\mysql\bin> mysqldump -w"Sex='f'" db_User tbl_Customer -u root -p > c:\mysql\data\female.sql Enter
Enter password: ***** Enter

C:\mysql\bin>
出力ファイル(female.sql)の内容
-- MySQL dump 9.11
--
-- Host: localhost    Database: db_User
-- ------------------------------------------------------
-- Server version    4.0.26-nt

--
-- Table structure for table `tbl_Customer`
--

CREATE TABLE tbl_customer (
  UserID varchar(4) NOT NULL default '',
  FirstName varchar(32) NOT NULL default '',
  LastName varchar(32) NOT NULL default '',
  Sex char(2) default NULL,
  Age int(11) default NULL,
  PRIMARY KEY  (UserID)
) TYPE=MyISAM;

--
-- Dumping data for table `tbl_Customer`
--
-- WHERE:  Sex='f'

INSERT INTO tbl_Customer VALUES ('U001','花子','鈴木','f',21);
INSERT INTO tbl_Customer VALUES ('U004','萌子','山口','f',18);
INSERT INTO tbl_Customer VALUES ('U005','愛','森永','f',21);
INSERT INTO tbl_Customer VALUES ('U007','花子','佐藤','f',35);

INSERT文のみファイル出力
mysqldump -t

unknown

mysqldump -t データベース名 > 出力ファイル名 または mysqldump --opt -t データベース名 > 出力ファイル名

指定した出力ディレクトリパスに、「テーブル名.sql」というファイルが生成されます。

C:\mysql\bin> mysqldump -t db_User -u root -p > c:\mysql\data\db_user_insert.sql Enter
Enter password: ***** Enter

C:\mysql\bin>

または

C:\mysql\bin> mysqldump --opt -t db_User -u root -p > c:\mysql\data\db_user_insert.sql Enter
Enter password: ***** Enter

C:\mysql\bin>
出力ファイル(db_user_insert.sql)の内容
-- MySQL dump 9.11
--
-- Host: localhost    Database: db_User
-- ------------------------------------------------------
-- Server version    4.0.26-nt

--
-- Dumping data for table `tbl_address`
--

INSERT INTO tbl_address VALUES ('U001',2140012,'神奈川県','川崎市多摩区1-2-3');
INSERT INTO tbl_address VALUES ('U002',1500012,'東京都','渋谷区広尾3-2-1');
INSERT INTO tbl_address VALUES ('U003',1660003,'東京都','高円寺南5-6-7');
INSERT INTO tbl_address VALUES ('U004',2280001,'神奈川県','座間市相模が丘9999');
INSERT INTO tbl_address VALUES ('U005',1600021,'東京都','新宿区歌舞伎町10-20-30');
INSERT INTO tbl_address VALUES ('U006',1080071,'東京都','港区白金台1000 白金ヒルズ1-304');
INSERT INTO tbl_address VALUES ('U007',1900021,'東京都','立川市羽衣町50');

--
-- Dumping data for table `tbl_customer`
--

INSERT INTO tbl_customer VALUES ('U001','花子','鈴木','f',21);
INSERT INTO tbl_customer VALUES ('U002','太郎','田中','m',30);
INSERT INTO tbl_customer VALUES ('U003','一郎','鈴木','m',45);
INSERT INTO tbl_customer VALUES ('U004','萌子','山口','f',18);
INSERT INTO tbl_customer VALUES ('U005','愛','森永','f',21);
INSERT INTO tbl_customer VALUES ('U006','太郎','鈴木','m',22);
INSERT INTO tbl_customer VALUES ('U007','花子','佐藤','f',35);

CREATE TABLE文のみファイル出力
mysqldump -d

unknown

mysqldump -d データベース名 > 出力ファイル名

指定したデータベースにある全テーブルのCREATE文が出力されます。

C:\mysql\bin> mysqldump -d db_User -u root -p > c:\mysql\data\db_user_create.sql Enter
Enter password: ***** Enter

C:\mysql\bin>
出力ファイル(db_user_create.sql)の内容
-- MySQL dump 9.11
--
-- Host: localhost    Database: db_User
-- ------------------------------------------------------
-- Server version    4.0.26-nt

--
-- Table structure for table `tbl_address`
--

CREATE TABLE tbl_address (
  UserID varchar(4) NOT NULL default '',
  Zip int(11) default NULL,
  Ken varchar(200) NOT NULL default '',
  Addr varchar(200) default NULL,
  PRIMARY KEY  (UserID)
) TYPE=MyISAM;

--
-- Table structure for table `tbl_customer`
--

CREATE TABLE tbl_customer (
  UserID varchar(4) NOT NULL default '',
  FirstName varchar(32) NOT NULL default '',
  LastName varchar(32) NOT NULL default '',
  Sex char(2) default NULL,
  Age int(11) default NULL,
  PRIMARY KEY  (UserID)
) TYPE=MyISAM;

このページで使用しているサンプルデータ

unknown

サンプルデータ
# データベース(db_Pet)作成
CREATE DATABASE IF NOT EXISTS db_Pet;

#データベース選択
USE db_Pet;

# テーブル(tbl_Pet)作成
CREATE TABLE tbl_Pet(
PetID VARCHAR(4) NOT NULL PRIMARY KEY,
Name VARCHAR(32) NOT NULL,
Species Varchar(20) NOT NULL,
Birth DATE DEFAULT NULL,
Sex CHAR(2) DEFAULT NULL
);

# データ挿入
INSERT INTO tbl_Pet (PetID,Name,Species,Birth,Sex) VALUES
('P001','ポチ','dog','2001-2-5','m'),
('P002','タマ','cat','2000-5-20','f'),
('P003','ショコラ','dog','2005-3-2','m'),
('P004','シャロン','cat','2007-2-7','f'),
('P005','小次郎','bird','2001-12-22','m'),
('P006','ガーコ','bird','2004-10-26','f'),
('P007','シロ','dog','2005-9-29','m');



# データベース(db_User)作成
CREATE DATABASE IF NOT EXISTS db_User;

#データベース選択
USE db_User;

# テーブル(tbl_Customer)作成
CREATE TABLE tbl_Customer(
UserID VARCHAR(4) NOT NULL PRIMARY KEY,
FirstName VARCHAR(32) NOT NULL,
LastName VARCHAR(32) NOT NULL,
Sex CHAR(2) DEFAULT NULL,
Age INTEGER DEFAULT NULL
);

# データ挿入
INSERT INTO tbl_Customer (UserID,FirstName,LastName,Sex,Age) VALUES
('U001','花子','鈴木','f',21),
('U002','太郎','田中','m',30),
('U003','一郎','鈴木','m',45),
('U004','萌子','山口','f',18),
('U005','愛','森永','f',21),
('U006','太郎','鈴木','m',22),
('U007','花子','佐藤','f',35);

# テーブル(tbl_Address)作成
CREATE TABLE tbl_Address(
UserID VARCHAR(4) NOT NULL PRIMARY KEY,
Zip INTEGER DEFAULT NULL,
Ken VARCHAR(200) NOT NULL,
Addr VARCHAR(200) DEFAULT NULL
);

# データ挿入
INSERT INTO tbl_Address (UserID,Zip,Ken,Addr) VALUES
('U001',2140012,'神奈川県','川崎市多摩区1-2-3'),
('U002',1500012,'東京都','渋谷区広尾3-2-1'),
('U003',1660003,'東京都','高円寺南5-6-7'),
('U004',2280001,'神奈川県','座間市相模が丘9999'),
('U005',1600021,'東京都','新宿区歌舞伎町10-20-30'),
('U006',1080071,'東京都','港区白金台1000 白金ヒルズ1-304'),
('U007',1900021,'東京都','立川市羽衣町50');

関連コンテンツ

Q. このサイトの情報はお役に立ちましたでしょうか?

投票する 投票結果を見る

管理人に【web拍手】を送るweb拍手(1行メッセージも送れます♪)

pagetop

polarized women