Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

linux下导入、导出mysql数据库命令 #27

Open
hehongwei44 opened this issue Oct 30, 2015 · 1 comment
Open

linux下导入、导出mysql数据库命令 #27

hehongwei44 opened this issue Oct 30, 2015 · 1 comment

Comments

@hehongwei44
Copy link
Owner

导出数据库用mysqldump命令(注意mysql的安装路径,即此命令的路径):

  1. 导出数据和表结构:

    mysqldump -u用户名 -p密码 数据库名 > 数据库名.sql

    #/usr/local/mysql/bin/   mysqldump -uroot -p abc > abc.sql
    

    敲回车后会提示输入密码

  2. 只导出表结构

    mysqldump -u用户名 -p密码 -d 数据库名 > 数据库名.sql

    #/usr/local/mysql/bin/mysqldump -uroot -p -d abc > abc.sql
    

    注:/usr/local/mysql/bin/ ---> mysql的data目录

导入数据库

  1. 首先建空数据库

    mysql>create database abc;
    
  2. 导入数据库

    方法一:

    (1)选择数据库

    mysql>use abc;
    

    (2)设置数据库编码

    mysql>set names utf8;
    

    (3)导入数据(注意sql文件的路径)

    mysql>source /home/abc/abc.sql;
    

    方法二:

    mysql -u用户名 -p密码 数据库名 < 数据库名.sql

    #mysql -uabc_f -p abc < abc.sql
    

    建议使用第二种方法导入。

    注意:有命令行模式,有sql命令

@hehongwei44
Copy link
Owner Author

通过source方法或者管道命令导入SQL文件是个不错的选择。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant