zoukankan      html  css  js  c++  java
  • How can I move a MySQL database from one server to another?

    My favorite way is to pipe a sqldump command to a sql command. You can do all databases or a specific one. So, for instance,

    mysqldump -uuser -ppassword myDatabase | mysql -hremoteserver -uremoteuser -premoteserverpassword 

    You can do all databases with

    mysqldump --all-databases -uuser -ppassword | mysql -hremoteserver -uremoteuser -premoteserver 

    The only problem is when the database is too big and the pipe collapses. In that case, you can do table by table or any of the other methods mentioned below.

    =======================

    I recently moved a 30GB database with the following stragegy:

    Old Server

    • Stop mysql server
    • Copy contents of datadir to another location on disk (~/mysqldata/*)
    • Start mysql server again (downtime was 10-15 minutes)
    • compress the data (tar -czvf mysqldata.tar.gz ~/mysqldata)
    • copy the compressed file to new server

    New Server

    • install mysql (don't start)
    • unzip compressed file (tar -xzvf mysqldata.tar.gz)
    • move contents of mysqldata to the datadir
    • Make sure your innodb_log_file_size is same on new server, or if it's not, don't copy the old log files (mysql will generate these)
    • Start mysql

    =======================

    You don't even need mysqldump if you're moving a whole database schema, and you're willing to stop the first database (so it's consistent when being transfered)

    1. Stop the database (or lock it)
    2. Go to the directory where the mysql data files are.
    3. Transfer over the folder (and its contents) over to the new server's mysql data directory
    4. Start back up the database
    5. On the new server, issue a 'create database' command.'
    6. Re-create the users & grant permissions.

    I can't remember if mysqldump handles users and permissions, or just the data ... but even if it does, this is way faster than doing a dump & running it. I'd only use that if I needed to dump a mysql database to then re-insert into some other RDBMS, if I needed to change storage options (innodb vs. myisam), or maybe if I was changing major versins of mysql (but I think I've done this between 4 & 5, though)

    =======================

    =======================

    REF:

    https://dba.stackexchange.com/questions/174/how-can-i-move-a-database-from-one-server-to-another

  • 相关阅读:
    fastapi教程进阶
    fastapi快速入门
    Linux yum安装PostgreSQL9.6
    harbor helm仓库使用
    Dockfile文件解析
    K8S概念理解
    转载---Beats:如何使用Filebeat将MySQL日志发送到Elasticsearch
    Elasticsearch中text与keyword的区别
    filebeat知识点
    logstash知识点
  • 原文地址:https://www.cnblogs.com/emanlee/p/10081209.html
Copyright © 2011-2022 走看看