天天看點

Mysql資料庫用source指令導入SQL檔案

   今天我們開發在test伺服器上面用phpmyadmin導出了一段SQL語句,讓我導入到beta上面的資料庫裡面,但是beta伺服器上面沒有安裝phpmyadmin軟體,看了裡面還有删除建立資料表的過程,用mysql指令導入肯定是不行的,難道隻能在beta伺服器上面安裝phpmyadmin軟體才能可以導入該SQL語句?該SQL語句如下,我隻是截取了其中一部分:

-- phpMyAdmin SQL Dump

-- version 3.3.9

-- http://www.phpmyadmin.net

--

-- Host: localhost

-- Generation Time: Dec 24, 2011 at 08:44 PM

-- Server version: 5.0.45

-- PHP Version: 5.2.4

SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";

/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;

/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;

/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;

/*!40101 SET NAMES utf8 */;

-- Database: `CMS_Convert_5342`

-- --------------------------------------------------------

-- Table structure for table `wp_commentmeta`

DROP TABLE IF EXISTS `wp_commentmeta`;

CREATE TABLE `wp_commentmeta` (

  `meta_id` bigint(20) unsigned NOT NULL auto_increment,

  `comment_id` bigint(20) unsigned NOT NULL default '0',

  `meta_key` varchar(255) default NULL,

  `meta_value` longtext,

  PRIMARY KEY  (`meta_id`),

  KEY `comment_id` (`comment_id`),

  KEY `meta_key` (`meta_key`)

) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;

-- Dumping data for table `wp_commentmeta`

    登陸MYSQL資料庫順序執行上面的指令肯定也是可以的,但是檔案很大,操作非常繁瑣。最後用help指令發現了source指令式可以完成這項艱巨的任務的。

mysql> help

source    (\.) Execute an SQL script file. Takes a file name as an argument.

    把該SQL語句上傳到伺服器的/tmp目錄,執行下面的指令即可。

mysql> source  /tmp/phpmyadmin.sql

Query OK, 1 row affected (0.00 sec)

本文轉自 sfzhang 51CTO部落格,原文連結:http://blog.51cto.com/sfzhang88/874997,如需轉載請自行聯系原作者