当前位置:主页 > Office办公 > SQL数据库

SQL数据库

公司有一台很重要SQL数据库,如何实现数据库实时同步?
公司有一台很重要SQL数据库,如何实现数据库实时同步?

客户现在有一个需求,公司有一台很重要SQL数据库,怕有一天服务器或者系统崩溃,导致所有SQL数据库数据丢失,客户想把数据库数据,通过某种方式将数库进行实时同步到另外一台服务器上,这样可以做个backup。那客户这个需求如何实现呢?解决方案:通过分析与研究,使用的是SQL自带的发布与订阅功能,旧的SQL Server版本是2008,新安装一个SQL Server 2014版本,通过旧SQL Serer发布,再通过SQL Server2014订阅,来同步数据库数据。实现过程3.1、发布发布前准备:首先两个服务器之间要能相互通讯,也就是能ping命令能通。平时我们连接数据库时,经常都是用的ip登陆,但是发布的时候不能这样,必须用服务器名称。如果在不同网段的两台数据库服务器,可以在两台服务器hosts文件中添加对应的IP地址和主机名。在旧服务器上,打开SQL Server数据库软件,进行发布SQL数据库。1、旧服务器上,找到复制--本地发布,右击新建发布。

249 次浏览
MySQL 数据库碎片优化、整理方法详细步骤图解教程
MySQL 数据库碎片优化、整理方法详细步骤图解教程

起因:查看线上数据库中Table Information时发现有一个日志表数据大小和索引大小有915M,但实际行数只有92行。该表需要频繁插入并且会定时去删掉旧的记录。表类型为Myisam,已建立一个索引,所以应该是产生了大量碎片,使用 Optimize table 表名 优化后大小变为2.19M,少了很多, 同时可以看出该表上的索引建的多余,因为插入操作比查询操作要多很多,而且查询不多,查询的数据量也一般比较小。借此延伸下MYSQL中Myisam、InnoDB碎片优化方式:Myisam清理碎片 OPTIMIZE TABLE table_nameInnoDB碎片优化 if you frequently delete rows (or update rows with variable-length data types), you can end up with a lot of wasted space in your data file(s), similar to filesystem fragmentation.If you’re not using the innodb_file_per_table option, the only thing you can do about it is export and import the database, a time-and-disk-intensive procedure.But if you are using innodb_file_per_table, you can identify and reclaim this space!Prior to 5.1.21, the free space counter is available from the table_comment column of information_schema.tables. Here is some SQL to identify tables with at least 100M (actually 97.65M) of free space:SELECT table_schema, table_name, table_comment FROM information_schema.tables WHERE engine LIKE ‘InnoDB’ AND table_comment RLIKE ‘InnoDB free: ([0-9]{6,}).*‘;Starting with 5.1.21, this was moved to the data_free column (a much more appropriate place):SELECT table_schema, table_name, data_free/1024/1024 AS data_free_MB FROM information_schema.tables WHERE engine LIKE ‘InnoDB’ AND data_free > 100*1024*1024;

447 次浏览