zoukankan      html  css  js  c++  java
  • mysql备份与恢复


    accept

    To export

    If it's an entire DB, then:

    $ mysqldump -u [uname] -p[pass] db_name > db_backup.sql

    If it's all DBs, then:

    $ mysqldump -u [uname] -p[pass] --all-databases > all_db_backup.sql

    If it's specific tables within a DB, then:

    $ mysqldump -u [uname] -p[pass] db_name table1 table2 > table_backup.sql

    You can even go as far as auto-compressing the output using gzip (if your DB is very big):

    $ mysqldump -u [uname] -p[pass] db_name | gzip > db_backup.sql.gz

    If you want to do this remotely and you have the access to the server in question, then the following would work (presuming the MySQL server is on port 3306):

    $ mysqldump -P 3306 -h [ip_address] -u [uname] -p[pass] db_name > db_backup.sql

    To import

    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 sat as username:

    $ mysql -u sat -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

    Refer: http://dev.mysql.com/doc/refman/5.6/en/mysqldump.html

    If you want a GUI tool then you could probably use SQLyog

    问题用上述方法恢复的时候我遇到了 Lost connection to MySQL server during query

    解决办法:mysql -u game -pwawagamepw game --max-allowed-packet=16777216 --net-buffer-length=16384  < game.sql

    但是这个又太慢了。

    解决办法: 如果已经在运行SQL shell,则可以使用source命令导入数据:

    use databasename;
    source data.sql;
  • 相关阅读:
    坑爹的微信支付v3,其实没有那么坑
    Mysql探究之null与not null
    Mysql的空值与NULL的区别
    Java编程思想(第4版) 中文清晰PDF完整版
    URI和URL的区别
    html 文本输入框效果大汇集
    HTTP状态码大全
    Silverlight ModelView中调用UI进程
    appium部分api
    appium元素定位
  • 原文地址:https://www.cnblogs.com/sy-liu/p/8919852.html
Copyright © 2011-2022 走看看