首页 > 数据库 >How can I move a MySQL database from one server to another?

How can I move a MySQL database from one server to another?

时间:2023-11-06 14:32:35浏览次数:41  
标签:tar database move server mysql new mysqldata

 

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

 



标签:tar,database,move,server,mysql,new,mysqldata
From: https://blog.51cto.com/emanlee/8207374

相关文章

  • Centos 7 官网下载安装mysql server 5.6
    Centos7官网下载安装mysqlserver#wgethttp://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm#rpm-ivhmysql-community-release-el7-5.noarch.rpm#yuminstallmysql-community-server安装成功后重启mysql服务。#servicemysqldrestart初次安装mysql,root......
  • Human disease database
      https://www.malacards.org/    https://www.uniprot.org/uniprot/ https://www.genome.jp/kegg/disease/ ......
  • jumpserver设置sftp默认路径
    jumpserver官网JumpServer是广受欢迎的开源堡垒机,是符合4A规范的专业运维安全审计系统。JumpServer帮助企业以更安全的方式管控和登录所有类型的资产,实现事前授权、事中监察、事后审计,满足等保合规要求。当我们通过jumpserver对服务器进行管理时,需要上传或下载服务器上的......
  • smtp-server: 526 Authentication failure[0]
    报错内容:smtp-server:526Authenticationfailure[0]"/root/dead.letter"11/313...messagenotsent.官方解释:526Authenticationfailure:请您检查发信服务器需要身份验证是否勾选解决办法:另外就是账号密码的问题,这里的密码包括第三方....所以建议是把这个东西关掉,或者......
  • SQL Server中字符串函数LEN 和 DATALENGTH比对
    LEN:返回指定字符串表达式的字符(而不是字节)数,其中不包含尾随空格。DATALENGTH:返回用于表示任何表达式的字节数。示例1:(相同,返回结果都为5): select LEN ('sssss')  select DATALENGTH('sssss')  示例2:(不相同,DATALENGTH是LEN的两倍):  select LEN(N'sssss')  sel......
  • Vue3 echarts 组件化使用 resizeObserver
    点击查看代码constresizeObserver=ref(null);//进行初始化和监听窗口变化onMounted(async()=>{awaitnextTick(()=>{initChart();setOptions(options.value,opts.value??true);});window.addEventListener('resize',handleResize);resizeO......
  • Kubernetes:kube-apiserver 和 etcd 的交互
    kubernetes:kube-apiserver系列文章:Kubernetes:kube-apiserver之scheme(一)Kubernetes:kube-apiserver之scheme(二)Kubernetes:kube-apiserver之启动流程(一)Kubernetes:kube-apiserver之启动流程(二)0.前言上几篇文章介绍了kubernetes的核心数据结构scheme......
  • SQL server experts
    Personalsitehttps://medium.com/munchy-bytes/microsoft-sql-server-gurus-you-should-follow-2fce3e5120e4https://www.brentozar.com/blitz/https://ola.hallengren.com/sql-server-index-and-statistics-maintenance.htmlgithubhttps://github.com/BrentOzarULTD/SQ......
  • C++11语法——std::move()
    std::move()在C++中,std::move()用于将对象转换为右值引用。关于左值、左值引用、右值、右值引用左值是一个表示数据的表达式(比如变量名或者解引用的指针),程序可以获取其地址传统的C++引用,即是左值引用。C++11新增右值引用,用&&表示。右值是可出现在赋值表达式的右边,但不......
  • sqlserver查询库中所有表的字段并进行拼接
    --查询库中所有表的字段信息SELECTTABLE_NAME,COLUMN_NAME,DATA_TYPEFROMINFORMATION_SCHEMA.COLUMNSWHERETABLE_SCHEMA='dbo'ORDERBYTABLE_NAME,ORDINAL_POSITION;--查询库中所有表的字段并进行拼接SELECTTABLE_NAME,STUFF((SELECT','+COLUMN_N......