- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在寻找一种使用 PhpMyAdmin 跨不同环境(本地和生产环境)同步 MySql 数据库的方法。因此寻找找到差异然后应用我们想要的差异的能力。
由于内置同步功能已停用。在 PhpMyAdmin 中执行此操作的最佳方法是什么?
即使通过 sql 查询也可以。
谢谢。
最佳答案
你可以在 php 中很容易地做到这一点......这是我使用的脚本
正在同步
$account_tables = $Db_stage->run("SELECT table_name, table_rows FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = '".$Init->container["Config"]->dbName."' ORDER BY table_name");
$production_tables = $Db_production->run("SELECT table_name, table_rows FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = '".$dbName."' ORDER BY table_name");
foreach ($account_tables as $account_table){
$dbDrop = "/usr/bin/mysql -u ".$Init->container["Config"]->dbUser." -p".$Init->container["Config"]->dbPassword." ".$Init->container["Config"]->dbName." -e 'drop table `".$account_table["table_name"]."`'";
echo "DROP ".$account_table["table_name"]."<br/>";
//echo $dbDrop."<br/>";
exec($dbDrop);
flush();
}
foreach ($production_tables as $production_table){
echo "SETUP ".$production_table["table_name"].'<br/>';
$dbDump = '/usr/bin/mysqldump --lock-tables=false --single-transaction --skip-add-locks -h '.$dbHost.' -u '.$dbUser.' -p'.$dbPassword.' '.$dbName.' '.$production_table["table_name"].' > '.$Init->container["Config"]->dirPublic.'system/sync/db/'.$production_table["table_name"].'.sql';
//echo $dbDump."<br/>";
exec($dbDump);
exec('/usr/bin/mysql --user='.$Init->container["Config"]->dbUser.' --password='.$Init->container["Config"]->dbPassword.' '.$Init->container["Config"]->dbName.' < '.$Init->container["Config"]->dirPublic.'system/sync/db/'.$production_table["table_name"].'.sql');
flush();
}
与差异
$account_tables = $Init->container["Db"]->run("SELECT table_name, table_rows FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = '".$Init->container["Config"]->dbName."' ORDER BY table_name");
$production_tables = $Db_production->run("SELECT table_name, table_rows FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = '".$dbName."' ORDER BY table_name");
$tables = array();
$table_rows = array();
foreach ($production_tables as $temp){
$tables[] = $temp["table_name"];
$table_rows[$temp["table_name"]]["production"] = $temp["table_rows"];
}
foreach ($account_tables as $temp){
if (!in_array($temp["table_name"], $tables)){
$tables[] = $temp["table_name"];
}
$table_rows[$temp["table_name"]]["account"] = $temp["table_rows"];
}
//
// Pull Down Column Data and output
//
$tables_with_discrepencies = array();
foreach ($tables as $table){
$column_diff = "<div id='popup".$table."' style='display:none;'>";
$account_columns = $Init->container["Db"]->run("select column_name, data_type from information_schema.columns where table_name = '".$table."'");
$production_columns = $Db_production->run("select column_name, data_type from information_schema.columns where table_name = '".$table."'");
$all_columns = array();
$account_columns_verified = array();
$production_columns_verified = array();
$account_columns_verified_type = array();
$production_columns_verified_type = array();
foreach ($account_columns as $temp){
$all_columns[] = $temp["column_name"];
$account_columns_verified[] = $temp["column_name"];
$account_columns_verified_type[$temp["column_name"]] = $temp["data_type"];
}
foreach ($production_columns as $temp){
if (!in_array($temp["column_name"],$all_columns)){
$all_columns[] = $temp["column_name"];
}
$production_columns_verified[] = $temp["column_name"];
$production_columns_verified_type[$temp["column_name"]] = $temp["data_type"];
}
$column_diff .= "<table border=1 cellpading='10'><tr><td>Column Name</td><td>Exists On Both</td><td>Data Type The Same</td></tr>";
$difference_between_columns_found = false;
foreach($all_columns as $column){
$column_diff .= "<tr><td>".$column."</td>";
if (in_array($column, $account_columns_verified) AND in_array($column, $production_columns_verified)){
$column_diff .= "<td>YES</td>";
} else if (in_array($column, $account_columns_verified)){
$difference_between_columns_found = true;
$column_diff .= "<td style='font-weight:bold;'>***Missing From Production***</td>";
} else if (in_array($column, $production_columns_verified)){
$column_diff .= "<td style='font-weight:bold;'>***Missing From Account***</td>";
$difference_between_columns_found = true;
}
if ($account_columns_verified_type[$column] == $production_columns_verified_type[$column]){
$column_diff .= "<td>YES</td>";
} else {
$column_diff .= "<td style='font-weight:bold;'>***Data Types Different***</td>";
$difference_between_columns_found = true;
}
$column_diff .= "</tr>";
}
$column_diff .= "</table>";
$column_diff .= "</div>";
echo $column_diff;
if ($difference_between_columns_found == true){
$tables_with_discrepencies[] = $table;
}
}
//
// Generate Table Report
//
$table_diff = "<table border=1 cellpading='10'><tr><td>Table Name</td><td>Exists On Both</td><td>Column Differences</td><td>Rows on Production</td><td>Rows on Account</td></tr>";
$difference_between_tables_found = false;
foreach($tables as $table){
$table_diff .= "<tr><td><span style='font-weight:bold;' onmouseover=\"this.style.cursor='pointer';\" onclick=\"tablePopup('".$table."');\">".$table."</span></td>";
if (isset($table_rows[$table]["production"]) AND $table_rows[$table]["production"] != 0 AND isset($table_rows[$table]["account"]) AND $table_rows[$table]["account"] != 0){
$table_diff .= "<td>EXISTS</td>";
} else if ((!isset($table_rows[$table]["production"]) || $table_rows[$table]["production"] == 0) AND (!isset($table_rows[$table]["account"]) || $table_rows[$table]["account"] == 0)){
$table_diff .= "<td style='font-weight:bold;'>***BOTH EMPTY***</td>";
} else if (isset($table_rows[$table]["production"]) AND $table_rows[$table]["production"] != 0){
$table_diff .= "<td style='font-weight:bold;'>***MISSING ON ACCOUNT***</td>";
$difference_between_tables_found = true;
} else {
$table_diff .= "<td style='font-weight:bold;'>***MISSING ON PRODUCTION***</td>";
$difference_between_tables_found = true;
}
if (in_array($table,$tables_with_discrepencies)){
$table_diff .= "<td style='font-weight:bold;'>***YES***</td>";
} else {
$table_diff .= "<td>No</td>";
}
if ($table_rows[$table]["production"]){
$table_diff .= "<td>".($table_rows[$table]["production"])."</td>";
} else {
$table_diff .= "<td>0</td>";
}
if ($table_rows[$table]["account"]){
$table_diff .= "<td>".($table_rows[$table]["account"])."</td>";
} else {
$table_diff .= "<td>0</td>";
}
}
$table_diff .= "</table>";
//
// Display report
//
echo "<h1>Database Comparision</h1>";
echo "Account Tables = ".count($account_tables)."<br/>";
echo "Production Tables = ".count($production_tables)."<br/>";
if ($difference_between_tables_found == true){
echo "Table Differences Found : True<br/>";
} else {
echo "Table Differences Found : False<br/>";
}
if (count($tables_with_discrepencies) > 0){
echo "Column Differences Found : True<br/>";
} else {
echo "Column Differences Found : False<br/>";
}
echo "<br/><a href='../index.php'>[ <- Back ]</a><br/><br/>";
echo $table_diff;
?>
<script>
function tablePopup(tableName){
$( "#popup"+tableName ).dialog({
autoOpen: false,
height: 600,
width: 650,
modal: false,
Close: function() {
$( this ).dialog( "close" );
}
});
$( "#popup"+tableName ).dialog( "open" );
}
</script>
关于php - 使用 PhpMyAdmin 同步数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18725809/
我正在实现 IMAP 客户端,但 IMAP 邮箱同步出现问题。 首先,可以从 IMAP 服务器获取新邮件,但我不知道如何从邮箱中查找已删除的邮件。 我是否应该从服务器获取所有消息并将其与本地数据进行比
我研究线程同步。当我有这个例子时: class A { public synchronized void methodA(){ } public synchronized void met
嗨,我做了一个扩展线程的东西,它添加了一个包含 IP 的对象。然后我创建了该线程的两个实例并启动它们。他们使用相同的列表。 我现在想使用 Synchronized 来阻止并发更新问题。但它不起作用,我
我正在尝试使用 FTP 定期将小数据文件从程序上传到服务器。用户从使用 javascript XMLHttpRequest 函数读取数据的网页访问数据。这一切似乎都有效,但我正在努力解决由 FTP 和
我不知道如何同步下一个代码: javascript: (function() { var s2 = document.createElement('script'); s2.src =
关闭。这个问题需要更多focused .它目前不接受答案。 想改进这个问题吗? 更新问题,使其只关注一个问题 editing this post . 关闭 7 年前。 Improve this qu
一 点睛 1 Message 在基于 Message 的系统中,每一个 Event 也可以被称为 Message,Message 是对 Event 更高一个层级的抽象,每一个 Message 都有一个
一 点睛 1 Message 在基于 Message 的系统中,每一个 Event 也可以被称为 Message,Message 是对 Event 更高一个层级的抽象,每一个 Message 都有一个
目标:我所追求的是每次在数据库中添加某些内容时(在 $.ajax 到 Submit_to_db.php 之后),从数据库获取数据并刷新 main.php(通过 draw_polygon 更明显)。 所
我有一个重复动画,需要与其他一些 transient 动画同步。重复动画是一条在屏幕上移动 4 秒的扫描线。当它经过下面的图像时,这些图像需要“闪烁”。 闪烁的图像可以根据用户的意愿来来去去和移动。它
我有 b 个块,每个块有 t 个线程。 我可以用 __syncthreads() 同步特定块中的线程。例如 __global__ void aFunction() { for(i=0;i #
我正在使用azure表查询来检索分配给用户的所有错误实体。 此外,我更改了实体的属性以声明该实体处于处理模式。 处理完实体后,我将从表中删除该实体。 当我进行并行测试时,可能会发生查询期间,一个实体已
我想知道 SQLite 是如何实现它的。它基于文件锁定吗?当然,并不是每个访问它的用户都锁定了整个数据库;那效率极低。它是基于多个文件还是仅基于一个大文件? 如果有人能够简要概述一下 sqlite 中
我想post到php,当id EmpAgree1时,然后它的post变量EmpAgree=1;当id为EmpAgree2时,则后置变量EmpAgree=2等。但只是读取i的最后一个值,为什么?以及如何
CUBLAS 文档提到我们在读取标量结果之前需要同步: “此外,少数返回标量结果的函数,例如 amax()、amin、asum()、rotg()、rotmg()、dot() 和 nrm2(),通过引用
我知道下面的代码中缺少一些内容,我的问题是关于 RemoteImplementation 中的同步机制。我还了解到该网站和其他网站上有几个关于 RMI 和同步的问题;我在这里寻找明确的确认/矛盾。 我
我不太确定如何解决这个问题......所以我可能需要几次尝试才能正确回答这个问题。我有一个用于缓存方法结果的注释。我的代码目前是一个私有(private)分支,但我正在处理的部分从这里开始: http
我对 Java 非常失望,因为它不允许以下代码尽可能地并发移动。当没有同步时,两个线程会更频繁地切换,但是当尝试访问同步方法时,在第二个线程获得锁之前以及在第一个线程获得锁之前再次花费太长时间(比如
过去几周我一直在研究java多线程。我了解了synchronized,并理解synchronized避免了多个线程同时访问相同的属性。我编写此代码是为了在同一线程中运行两个线程。 val gate =
我有一个关于 Java 同步的简单问题。 请假设以下代码: public class Test { private String address; private int age;
我是一名优秀的程序员,十分优秀!