前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >MySql 利用mysql&mysqldum导入导出数据

MySql 利用mysql&mysqldum导入导出数据

作者头像
授客
发布2019-09-12 13:03:19
1.5K0
发布2019-09-12 13:03:19
举报
文章被收录于专栏:授客的专栏

测试环境

Linux下测试,数据库MySql

工具

mysqldump,该命令位于mysql/bin/目录中:..../mysql/bin/mysqldump

步骤

1.cd 命令进入到mysqldump所在目录下。

首先得知道mysql命令或mysqldump命令的完整路径,可以使用find命令查找

如:查找mysqldump命令的完整路径,这里/usr/local/mysql是MySql数据库的安装路径

find / -name mysql -print

cd /usr/local/mysql/bin

2.导出指定数据库中的所有数据,把导出数据命名为hdlogsys.sql,存放与/usr目录下

/usr/local/mysql/bin# mysqldump -u root -p hdlogsys > /usr/hdlogsys.sql

-bash: mysqldump: command not found

解决办法:

1)首先考虑系统环境变量。

2)在环境变量ok的情况下,进行如下操作。

把mysqldump的路径如:/usr/local/mysql/bin/mysqldump,映射一个链接到/usr/bin目录下,相当于建立一个链接文件,如下

/usr/local/mysql/bin# ln -s /usr/local/mysql/bin/mysqldump usr/bin/mysqldump

注意:每次退出后再次使用就又要重新运行该命令

说明:

有时候安装好MySQL程序的时候,直接输入命令mysql或mysqldump会发现提示命令不存在,这是由于系统默认会查找/usr/bin下的命令,如果这个命令不在这个目录下,当然会找不到命令

建立映射链接后,进入映射目录如:/usr/bin或者命令所在实际目录如:/usr/local/mysql/bin/mysqldump

键入上述的mysqldump命令,可以导出数据

4.cd 命令进入到mysqldump所在目录下。

cd /usr/local/mysql/bin

5.把导出的数据导入到指定数据库

【对于mysql命令,如果遇到上述问题,采与上述相同的解决方式。】

builder:/usr/local/mysql/bin# mysql -u root -p

Enter password:

(输入数据库访问密码)

Welcome to the MariaDB monitor. Commands end with ; or \g.

Your MariaDB connection id is 39617

Server version: 5.5.23-MariaDB-log Source distribution

This software comes with ABSOLUTELY NO WARRANTY. This is free software,

and you are welcome to modify and redistribute it under the GPL v2 license

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]>use heidunlog

(这里输use 要导入数据的数据库名)

Reading table information for completion of table and column names

You can turn off this feature to get a quicker startup with -A

Database changed

MariaDB [heidunlog]>source /usr/heidunlog.sql

到这里如果要切换数据库名,则继续输入use语句

或者如下,直接指定数据库名

builder:/usr/local/mysql/bin# mysql -u root -p hdlogsys

Enter password:

(输入数据库访问密码)

Reading table information for completion of table and column names

You can turn off this feature to get a quicker startup with -A

Welcome to the MariaDB monitor. Commands end with ; or \g.

Your MariaDB connection id is 2104

Server version: 5.5.27-MariaDB-log Source distribution

This software comes with ABSOLUTELY NO WARRANTY. This is free software,

and you are welcome to modify and redistribute it under the GPL v2 license

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [hdlogsys]>source /usr/heidunlog.sql

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2014-11-28 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
云数据库 SQL Server
腾讯云数据库 SQL Server (TencentDB for SQL Server)是业界最常用的商用数据库之一,对基于 Windows 架构的应用程序具有完美的支持。TencentDB for SQL Server 拥有微软正版授权,可持续为用户提供最新的功能,避免未授权使用软件的风险。具有即开即用、稳定可靠、安全运行、弹性扩缩等特点。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档