How can I import a MySQL dumpfile into my database? I'm using CentOS Linux 5 server. My old hosting provider gave me a data.sql file and I do have access to my Unix / Linux server via ssh. So How do I restore my data using command line over the ssh session?
You can easily restore or import MySQL data with the mysql command itself. First you need to login to your system using ssh or putty client.

Step #1: Upload File To MySQL Server

You can upload data.sql file using the sftp or scp command, enter:
$ scp data.sql vivek@example.cyberciti.biz:/home/vivek
The data.sql file will be uploaded to /home/vivek directory. Avoid using /tmp or Apache document directory such as /var/www/html as anyone can see your data on the remote server.

Step #2: Login To Remote Server

Type the following command at the shell prompt:
$ ssh loginname@example.cyberciti.biz
Replace example.cyberciti.biz with actual server name or an IP address.

Step#3: Import Datafile

Type the following command to import sql data file:
$ mysql -u username -p -h localhost DATA-BASE-NAME < data.sql
In this example, import 'data.sql' file into 'blog' database using vivek as username:
$ mysql -u vivek -p -h localhost blog < data.sql

If you have a dedicated database server, replace localhost hostname with with actual server name or IP address as follows:
$ mysql -u username -p -h 202.54.1.10 databasename < data.sql
OR use hostname such as mysql.cyberciti.biz
$ mysql -u username -p -h mysql.cyberciti.biz database-name < data.sql

If you do not know the database name or database name is included in sql dump you can try out something as follows:
$ mysql -u username -p -h 202.54.1.10 < data.sql

A Note About Creating A New Database and Importing Data

In this example create a mysql database called foo and import data from bar.sql.gz as follows:

mysql -u root -p -h localhost

Sample outputs:

mysql> create database foo;
mysql> exit;

Import bar.sql.gz:

gunzip bar.sql.gz
ls -l
mysql -u root -p -h localhost foo <bar.sql

You can also create a username and password for foo database using the following syntax:

  mysql -u root -p -h localhost  

Sample outputs:

mysql> GRANT ALL ON foo.* TO NEW-USERNAME-HERE@localhost IDENTIFIED BY 'YOUR-PASSWORD-HERE';
### allow access from 192.168.1.5 too ##
mysql> GRANT ALL ON foo.* TO NEW-USERNAME-HERE@192.168.1.5 IDENTIFIED BY 'YOUR-PASSWORD-HERE';
mysql> quit;

Page last updated at 4:37 PM, January 6, 2012.

Import MySQL Dumpfile, SQL Datafile Into My Database的更多相关文章

  1. Mysql错误:Ignoring query to other database解决方法

    Mysql错误:Ignoring query to other database解决方法 今天登陆mysql show databases出现Ignoring query to other datab ...

  2. MySQL:MySQL和SQL Server的区别

    导读:接下来的网上商城的项目,需要用到MySQL数据库了.这个对于我来说,是一个新接触的东西,按照惯例,在刚开始学习一个东西的时候,先从宏观上去了解它.本篇博客,先介绍SQL Server的基本内容, ...

  3. mysql之sql语句导入与导出讲解

    导出SQL:mysqldump -u root -p 数据库名 [表名1 表名2] > 输出地址其中表名可选 本机测试实例:

  4. 使用 Oracle GoldenGate 在 Microsoft SQL Server 和 Oracle Database 之间复制事务

    使用 Oracle GoldenGate 在 Microsoft SQL Server 和 Oracle Database 之间复制事务 作者:Nikolay Manchev 分步构建一个跨这些平台的 ...

  5. mysql 运行sql脚本文件

    #只运行,不导出 mysql> source /home/user/to_run.sql; #导出 $ mysql -h host -u user -ppassword database < ...

  6. MySQL导入sql 文件的5大步骤

    http://database.51cto.com/art/201005/200739.htm 以下的文章主要介绍的是MySQL导入sql 文件,即MySQL数据库导入导出sql 文件的实际操作步骤, ...

  7. MySQL进口.sql文件和常用命令

    MySQL进口.sql文件和常用命令 在MySQL Qurey   Brower中直接导入*.sql脚本,是不能一次运行多条sql命令的.在mysql中运行sql文件的命令: mysql> so ...

  8. sql点滴41—mysql常见sql语法

    原文:sql点滴41-mysql常见sql语法 ALTER TABLE:添加,修改,删除表的列,约束等表的定义. 查看列:desc 表名; 修改表名:alter table t_book rename ...

  9. mysql中SQL执行过程详解与用于预处理语句的SQL语法

    mysql中SQL执行过程详解 客户端发送一条查询给服务器: 服务器先检查查询缓存,如果命中了缓存,则立刻返回存储在缓存中的结果.否则进入下一阶段. 服务器段进行SQL解析.预处理,在优化器生成对应的 ...

随机推荐

  1. poj 3894 System Engineer (二分图最大匹配--匈牙利算法)

    System Engineer Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 507   Accepted: 217 Des ...

  2. 【gcd+数学证明】【HDU1722】 CAKE

    Cake Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submi ...

  3. mysql 5.6

    mysql 5.6的安裝: 1,提前安装依赖的库环境. yum install -y  make bison cmake gcc-c++ ncurses ncurses-devel  git 2,下载 ...

  4. 六步实现Spring.NET 与 NHibernate 的整合

    最近刚完成一个项目,其中对数据库的架构用到的是Spring.NET 与 NHibernate相结合的产物.对于这两项技术,我自己也不是太熟悉,不过好在网上有很多关于这方面的介绍文档,在这里就不多说了. ...

  5. 【常用小命令】解决windows下有些文件文件名识别不了导致删除不了的问题

    在百度上找的解决方案哈,只为自己存档一份. 因为发现现在从csdn上下载的文件都是“.pdf_”格式,下载2个文件,将一个文件格式改成 “.pdf”,另一个文件就扔回不了回收站了, 所以没有办法就找各 ...

  6. SpringMVC的web.xml配置注意

    web.xml需要放过所有资源文件,这个就看自己的系统中有哪些静态文件.一般的都是.js..css..jpg..png.jpeg等等,但是我还用到一些字体文件资源,所以也要过滤,不然前台会找不到. & ...

  7. HTML5动画图片播放器 高端大气

    我们见过很多图片播放插件(焦点图),很多都基于jQuery.今天介绍的HTML5图片播放器很特别,它不仅在图片间切换有过渡动画效果,而且在切换时图片中的元素也将出现动画效果,比如图中的文字移动.打散. ...

  8. CSS display:table属性用法- 轻松实现了三栏等高布局

    display:table:此元素会作为块级表格来显示(类似 <table>); display:table-cell属性指让标签元素以表格单元格的形式呈现,类似于td标签.目前IE8+以 ...

  9. windows中path环境变量即时生效

    修改PATH后,打来CMD命令行,输入 “set PATH=C” (不会真的改变PATH变量值,但会重新读取一次PATH值),关掉CMD窗口再打开.OK 不放心可以 echo %PATH% 检视一下.

  10. 入门指引 - PHP手册笔记

    曾经简单的学习过PHP,看的是<PHP和MySQL Web开发>,还有万能的搜索引擎的帮助.这次准备系统的学习一下,参考资料是PHP Manual. PHP能做什么 PHP主要用于服务端的 ...