首页 技术 正文
技术 2022年11月21日
0 收藏 511 点赞 4,511 浏览 2092 个字

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

by:授客 QQ1033553122

 

测试环境

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

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,022
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,513
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,359
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,142
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,773
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,851