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

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

by:授客 QQ1033553122

 

测试环境

Linux下测试,数据库MySql

 

工具

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

 

步骤

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

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

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

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程序的时候,直接输入命令mysqlmysqldump会发现提示命令不存在,这是由于系统默认会查找/usr/bin下的命令如果这个命令不在这个目录下,当然会找不到命令

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

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

 

4cd 命令进入到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

 

原文地址:https://www.cnblogs.com/shouke/p/10158024.html