导出数据库

  1.  
    -- 导出dbname表结构
  2.  
    mysqldump -uroot -p123456 -d dbname > dbname.sql
  3.  
     
  4.  
    -- 导出dbname表数据
  5.  
    mysqldump -uroot -p123456 -t dbname > dbname.sql
  6.  
     
  7.  
    -- 导出dbname表结构和数据
  8.  
    mysqldump -uroot -p123456 dbname > dbname.sql

导出数据库中指定表

  1.  
    -- 导出dbname下的test表结构
  2.  
    mysqldump -uroot -p123456 -d dbname test > test.sql
  3.  
     
  4.  
    -- 导出dbname下的test表数据
  5.  
    mysqldump -uroot -p123456 -t dbname test > test.sql
  6.  
     
  7.  
    -- 导出dbname下的test表结构和数据
  8.  
    mysqldump -uroot -p123456 dbname test > test.sql

还原

  1.  
    -- 创建数据库
  2.  
    CREATE DATABASE dbname DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
  3.  
     
  4.  
    -- 还原数据库
  5.  
    mysql -uroot -p123456 dbname < /path/dbname.sql
  6.  
     
  7.  
    -- 还原数据库
  8.  
    source dbname.sql
  9.  
     
  10.  
    -- 查看表结构
  11.  
    desc wp_users;
  12.  
    show create table wp_users \G;

SELECT INTO OUTFILE导出

  1.  
    SELECT * INTO OUTFILE 'temp.txt'
  2.  
    FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' LINES TERMINATED BY '\n'
  3.  
    FROM table_name
  4.  
    WHERE createtime < 1382716800;

LOAD DATA 导入

  1.  
    LOAD DATA INFILE '/home/temp.txt'
  2.  
    INTO TABLE table_name
  3.  
    FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' LINES TERMINATED BY '\n'
  4.  
    (product_id,uuid,mac,monitor,win_version,ip,createtime) ;

注: 从本地导入远程服务器需使用LOAD DATA LOCAL INFILE

确保local_infile打开且有权限的情况下LOAD DATA若报错:message:The used command is not allowed with this MySQL version

1.mysql_connect指定第五个参数128测试,即mysql_connect($host, $user, $pwd, false, CLIENT_LOCAL_FILES)

2.PHP中mysql扩展版本(待确认)

posted on 2020-01-10 15:29  赵羴  阅读(34920)  评论(0编辑  收藏  举报