MySql error: Table “mysql”.“innodb_table_stats” not found

Recently i have faced MySQL error Table “mysql”.“innodb_table_stats” not found
I have implemented below solution that worked to me I am sharing the solution with you.

Login to terminal or phpmyadmin and drop below tables from mysql database:

 innodb_index_stats, innodb_table_stats, slave_master_info, slave_relay_log_info, slave_worker_info

Drop below table from mysql

Go to your mysql database path in mamp

 cd /Applications/MAMP/db/mysql56 

Delete .frm & .ibd files of the above tables.

Run Below query and restart Mysql server

CREATE TABLE `innodb_index_stats` (
  `database_name` varchar(64) COLLATE utf8_bin NOT NULL,
  `table_name` varchar(64) COLLATE utf8_bin NOT NULL,
  `index_name` varchar(64) COLLATE utf8_bin NOT NULL,
  `last_update` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `stat_name` varchar(64) COLLATE utf8_bin NOT NULL,
  `stat_value` bigint(20) unsigned NOT NULL,
  `sample_size` bigint(20) unsigned DEFAULT NULL,
  `stat_description` varchar(1024) COLLATE utf8_bin NOT NULL,
  PRIMARY KEY (`database_name`,`table_name`,`index_name`,`stat_name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin STATS_PERSISTENT=0;

CREATE TABLE `innodb_table_stats` (
  `database_name` varchar(64) COLLATE utf8_bin NOT NULL,
  `table_name` varchar(64) COLLATE utf8_bin NOT NULL,
  `last_update` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `n_rows` bigint(20) unsigned NOT NULL,
  `clustered_index_size` bigint(20) unsigned NOT NULL,
  `sum_of_other_index_sizes` bigint(20) unsigned NOT NULL,
  PRIMARY KEY (`database_name`,`table_name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin STATS_PERSISTENT=0;

CREATE TABLE `slave_master_info` (
  `Number_of_lines` int(10) unsigned NOT NULL COMMENT 'Number of lines in the file.',
  `Master_log_name` text CHARACTER SET utf8 COLLATE utf8_bin NOT NULL COMMENT 'The name of the master binary log currently being read from the master.',
  `Master_log_pos` bigint(20) unsigned NOT NULL COMMENT 'The master log position of the last read event.',
  `Host` char(64) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '' COMMENT 'The host name of the master.',
  `User_name` text CHARACTER SET utf8 COLLATE utf8_bin COMMENT 'The user name used to connect to the master.',
  `User_password` text CHARACTER SET utf8 COLLATE utf8_bin COMMENT 'The password used to connect to the master.',
  `Port` int(10) unsigned NOT NULL COMMENT 'The network port used to connect to the master.',
  `Connect_retry` int(10) unsigned NOT NULL COMMENT 'The period (in seconds) that the slave will wait before trying to reconnect to the master.',
  `Enabled_ssl` tinyint(1) NOT NULL COMMENT 'Indicates whether the server supports SSL connections.',
  `Ssl_ca` text CHARACTER SET utf8 COLLATE utf8_bin COMMENT 'The file used for the Certificate Authority (CA) certificate.',
  `Ssl_capath` text CHARACTER SET utf8 COLLATE utf8_bin COMMENT 'The path to the Certificate Authority (CA) certificates.',
  `Ssl_cert` text CHARACTER SET utf8 COLLATE utf8_bin COMMENT 'The name of the SSL certificate file.',
  `Ssl_cipher` text CHARACTER SET utf8 COLLATE utf8_bin COMMENT 'The name of the cipher in use for the SSL connection.',
  `Ssl_key` text CHARACTER SET utf8 COLLATE utf8_bin COMMENT 'The name of the SSL key file.',
  `Ssl_verify_server_cert` tinyint(1) NOT NULL COMMENT 'Whether to verify the server certificate.',
  `Heartbeat` float NOT NULL,
  `Bind` text CHARACTER SET utf8 COLLATE utf8_bin COMMENT 'Displays which interface is employed when connecting to the MySQL server',
  `Ignored_server_ids` text CHARACTER SET utf8 COLLATE utf8_bin COMMENT 'The number of server IDs to be ignored, followed by the actual server IDs',
  `Uuid` text CHARACTER SET utf8 COLLATE utf8_bin COMMENT 'The master server uuid.',
  `Retry_count` bigint(20) unsigned NOT NULL COMMENT 'Number of reconnect attempts, to the master, before giving up.',
  `Ssl_crl` text CHARACTER SET utf8 COLLATE utf8_bin COMMENT 'The file used for the Certificate Revocation List (CRL)',
  `Ssl_crlpath` text CHARACTER SET utf8 COLLATE utf8_bin COMMENT 'The path used for Certificate Revocation List (CRL) files',
  `Enabled_auto_position` tinyint(1) NOT NULL COMMENT 'Indicates whether GTIDs will be used to retrieve events from the master.',
  PRIMARY KEY (`Host`,`Port`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 STATS_PERSISTENT=0 COMMENT='Master Information';

CREATE TABLE `slave_relay_log_info` (
  `Number_of_lines` int(10) unsigned NOT NULL COMMENT 'Number of lines in the file or rows in the table. Used to version table definitions.',
  `Relay_log_name` text CHARACTER SET utf8 COLLATE utf8_bin NOT NULL COMMENT 'The name of the current relay log file.',
  `Relay_log_pos` bigint(20) unsigned NOT NULL COMMENT 'The relay log position of the last executed event.',
  `Master_log_name` text CHARACTER SET utf8 COLLATE utf8_bin NOT NULL COMMENT 'The name of the master binary log file from which the events in the relay log file were read.',
  `Master_log_pos` bigint(20) unsigned NOT NULL COMMENT 'The master log position of the last executed event.',
  `Sql_delay` int(11) NOT NULL COMMENT 'The number of seconds that the slave must lag behind the master.',
  `Number_of_workers` int(10) unsigned NOT NULL,
  `Id` int(10) unsigned NOT NULL COMMENT 'Internal Id that uniquely identifies this record.',
  PRIMARY KEY (`Id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 STATS_PERSISTENT=0 COMMENT='Relay Log Information';

CREATE TABLE `slave_worker_info` (
  `Id` int(10) unsigned NOT NULL,
  `Relay_log_name` text CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
  `Relay_log_pos` bigint(20) unsigned NOT NULL,
  `Master_log_name` text CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
  `Master_log_pos` bigint(20) unsigned NOT NULL,
  `Checkpoint_relay_log_name` text CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
  `Checkpoint_relay_log_pos` bigint(20) unsigned NOT NULL,
  `Checkpoint_master_log_name` text CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
  `Checkpoint_master_log_pos` bigint(20) unsigned NOT NULL,
  `Checkpoint_seqno` int(10) unsigned NOT NULL,
  `Checkpoint_group_size` int(10) unsigned NOT NULL,
  `Checkpoint_group_bitmap` blob NOT NULL,
  PRIMARY KEY (`Id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 STATS_PERSISTENT=0 COMMENT='Worker Information';


Note: Don’t forget to restart your mysql Server.

Update node from ajax and model popup Drupal 7

I have seen a couple of question-related to “How to edit node in ajax model popup ? and How to edit node while embedding it in ctool”. I have found two way to approach this. I am giving complete code here so it can help others as well.

First Approach

In this implementation, I will open the embedded node in popup using ajax, will save the node and close the popup.

We need to create a custom button to the form.


<?php


$form['actions']['edit'] = array(
  '#type' => 'submit',
  '#value' => t('Edit Embedded Photo'),
  '#ajax' => array(
  'callback' => 'getEditContent',
      'event' => 'click',
  ),
  '#attributes' => array(
    'selected_node_id' => $entity->nid),
  );

// Now we need to create a callback method.


function getEditContent($js = NULL,$form){
// we are checking for Js as well because if JS is not there the flow should not break , it will open page in new URL
  if (!$js) {
      return drupal_goto('node/'.$form['buttons'][2]['#attributes']['selected_node_id'].'/edit/');
    }
    $force_page_reload = FALSE;
    $node = node_load($form['buttons'][2]['#attributes']['selected_node_id']);
    $type_name = node_type_get_name($node);
    $title = t('<em>Edit @type</em> @title', array('@type' => $type_name, '@title' => $node->title));

// implementing hook_node_form here. so when you are using this, replace my_module with your module name.
    my_module_node_form($node, $title, $force_page_reload);
}

// opening node in the popup to edit
// We can do all this code in ajax callback method (above one) but keeping this separate so we can use it somewhere else if needed.

function my_module_node_form($node, $title, $force_page_reload = FALSE) {
  $commands = array();
  ctools_include('node.pages', 'node', '');
  ctools_include('modal');
  ctools_include('ajax');
  $form_state = array(
    'title' => $title,
    'ajax'  => TRUE,
    'build_info' => array(
      'args'  => array($node),
    ),
  );
  variable_set("embedded_photo_node_id",$node->nid);
  form_load_include($form_state, 'inc', 'node', 'node.pages');
  $commands = ctools_modal_form_wrapper($node->type . '_node_form', $form_state);
 
  // add CSS class to Modal-Frame  if we need to provide some extra style 
  $commands[] = ajax_command_invoke('#modalContent', 'addClass', array('custom-module-node', 'custom-module-node-form'));
  print ajax_render($commands);
  exit;

}

?>

By applying above embedded node will open in new pop in edit mode, you can edit this and save this. Once you will click on save button node will get updated but the opened popup will not close. To close this opened popup we need to make one more changes:


<?php

// implementing  hook_node_update()

function my_module_node_update($node){

$updated_node_id = variable_get("embedded_photo_node_id") ?? 0;
if (($updated_node_id !=0) && ($node->nid === $updated_node_id) && ($node->type === 'embedded node type')){
    drupal_add_js(drupal_get_path('module', 'my_module') . '/js/js_utility.js');
    variable_del('embedded_photo_node_id');
}
}
?> 

create a new file with the name ‘js_utility.js’ under your module folder and js folder. so the complete path will be

yourprojectpath/module/contrib/mymodule/js/js_utility.js

Add below code in the js file

(function ($) {
    Drupal.CTools.Modal.dismiss();
})(jQuery);

Clear your Drupal cache and Enjoy!

Second Approach

In this approach, we will not open the node edit form in a popup, instead of popup we will open this in the existing embedded popup.

In the same as first, with ajax callback

<?php
$form['edit'] = array(
   '#type' => 'submit',
   '#value' => t('Edit Embedded Photo'),
   '#ajax' => array(
   'callback' => 'getEditContent',
   'event' => 'click',
           'wrapper'=> 'edit-entity',
   ),
   '#attributes' => array(
   'selected_node_id' => $entity->nid),
);


// Ajax callback

function getEditContent($form){
  $node = node_load($form['edit']['#attributes']['selected_node_id']);
  $type_name = node_type_get_name($node);
//  drupal_set_title(t('<em>Edit @type</em> @title', array('@type' => $type_name, '@title' => $node->title)), PASS_THROUGH);

// Render the form
$form_state = array();
$form_state['build_info']['args'] = array($node);

form_load_include($form_state, 'inc', 'node', 'node.pages');
return drupal_build_form($node->type . '_node_form', $form_state);

}

function mymodule_asaf_form_ajax_commands_alter(&$commands, $form, &$form_state, $form_id) {
  foreach($commands as $key => $command) {
      if ($command['command'] == 'asafRedirect' || 'asafRefresh') {
        unset($commands[$key]);
        break;
      }
    }

}

?>

To make the above solution completely, we need a contributed module Asaf (ajax submit for any form) (https://www.drupal.org/project/asaf) otherwise after form save our popup will get close and will get redirect to the Home page of your application. Setting $form_state[‘redirection’] would not work.

After installing the above module we need to add this form id there. Please see the image.