msc*_*ett 14 mysql mariadb laravel
每次我尝试将中等大小的JSON对象同步到我的数据库时,我都遇到了这个问题,因此我们可以对它进行一些报告.通过研究可能导致它的原因,我在这个问题上遇到了这些联系.
http://blog.corrlabs.com/2013/04/mysql-prepared-statement-needs-to-be-re.html http://bugs.mysql.com/bug.php?id=42041
两者似乎都指向了table_definition_cache的方向.但是,这就是说问题是由于服务器上同时发生了mysqldump.我可以向你保证,事实并非如此.此外,我将查询精简到一次只插入一个对象.
public function fire($job, $data)
{
foreach (unserialize($data['message']) as $org)
{
// Ignore ID 33421 this will time out.
// It contains all users in the system.
if($org->id != 33421) {
$organization = new Organization();
$organization->orgsync_id = $org->id;
$organization->short_name = $org->short_name;
$organization->long_name = $org->long_name;
$organization->category = $org->category->name;
$organization->save();
$org_groups = $this->getGroupsInOrganization($org->id);
if (!is_int($org_groups))
{
foreach ($org_groups as $group)
{
foreach($group->account_ids as $account_id)
{
$student = Student::where('orgsync_id', '=', $account_id)->first();
if (is_object($student))
{
$student->organizations()->attach($organization->id, array('is_officer' => ($group->name == 'Officers')));
}
}
}
}
}
}
$job->delete();
}
Run Code Online (Sandbox Code Playgroud)
这是抛出错误时运行的代码.通常以形式出现.
SQLSTATE[HY000]: General error: 1615 Prepared statement needs to be re-prepared (SQL: insert into `organization_student` (`is_officer`, `organization_id`, `student_id`) values (0, 284, 26))
Run Code Online (Sandbox Code Playgroud)
然后重复3次此错误.
SQLSTATE[HY000]: General error: 1615 Prepared statement needs to be re-prepared (SQL: insert into `organizations` (`orgsync_id`, `short_name`, `long_name`, `category`, `updated_at`, `created_at`) values (24291, SA, Society of American, Professional, 2014-09-15 16:26:01, 2014-09-15 16:26:01))
Run Code Online (Sandbox Code Playgroud)
如果有人能指出我正确的方向,我将非常感激.我对实际触发错误的内容更加好奇,然后查找此特定问题的原因.在使用ORM时,在laravel应用程序中似乎也有些常见.
虽然mysqldump是常见的原因,但并不是唯一的原因.
在我的情况下运行工匠:在任何数据库上迁移也会为同一服务器上的不同数据库触发此错误.
http://bugs.mysql.com/bug.php?id=42041 提到将在mysqldump中调用的表锁/刷新,因此值得检查是否有同时发生的迁移,锁定或刷新.
没有尝试将准备切换为模拟.
'options' => [
\PDO::ATTR_EMULATE_PREPARES => true
]
Run Code Online (Sandbox Code Playgroud)
当 mysqldump 正在进行时会出现此错误。正在进行哪个数据库转储并不重要。等待转储完成,此错误就会消失。
问题在于表定义被转储,从而导致此错误。
是的,我尝试更改这些 mysql 设置,但有时它仍然会发生(主要是在晚上运行大量 mysql 备份/转储时)。
表打开缓存 128=>16384
表定义缓存 1024=>16384
| 归档时间: |
|
| 查看次数: |
12211 次 |
| 最近记录: |