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.

最新文章

  1. 迭代器模式(Iterator Pattern)
  2. 如何安装Ecshop for linux
  3. C++ WIN32控制台异常关闭回调函数
  4. android textview 设置text 字体
  5. Windows驱动开发(中间层)
  6. Squid Proxy Server 3.1
  7. spring @Autowired或@Resource 的区别
  8. Go笔记-指针
  9. 《Self-Attention Generative Adversarial Networks》里的注意力计算
  10. net-snmp开发教程
  11. 【OpenFOAM案例】03 Docker安装OpenFOAM
  12. Autofac与AOP功能例子
  13. SharePoint Web应用程序管理-PowerShell
  14. JS前端数据多条件筛选(商品搜索)
  15. Linux-软件包管理-yum在线管理-光盘yum源
  16. Android中的线程池概述
  17. 【BZOJ1912】[Apio2010]patrol 巡逻 树形DP
  18. bzoj3224Treap
  19. sizeof运用
  20. php命令行查看扩展信息

热门文章

  1. ffmpeg调试相关知识点
  2. 《JavaScript 闯关记》之变量和数据类型
  3. (ZZ)WPF经典编程模式-MVVM示例讲解
  4. HTTP状态码搜集
  5. 解决rsync 同步auth failed on module问题
  6. synchronized 方式实现监控器中数据成员的同步
  7. Android code wiki
  8. Eloquent ORM 之关联查询
  9. OpenLayers 3加载本地Google切片地图
  10. 两阶段提交及JTA