{"id":10435,"date":"2019-10-25T11:13:14","date_gmt":"2019-10-25T11:13:14","guid":{"rendered":"https:\/\/mpgico.com\/new\/?page_id=10435"},"modified":"2019-10-25T11:13:14","modified_gmt":"2019-10-25T11:13:14","slug":"mysql","status":"publish","type":"page","link":"https:\/\/mpgico.com\/new\/mysql\/","title":{"rendered":"Mysql"},"content":{"rendered":"<section class=\"wpb-content-wrapper\"><p>[vc_row][vc_column][vc_column_text]<\/p>\n<h1>Understanding the MySQL Information Schema Database<\/h1>\n<p>The INFORMATION_SCHEMA database is where each MySQL instance stores information about all the other databases that the MySQL server maintains.\u00a0 Also sometimes referred to as the data dictionary and system catalog, it&#8217;s the ideal place to lookup information such as the name of a database or table, the data type of a column, or access privileges. Today&#8217;s article will provide an overview of the INFORMATION_SCHEMA database as well as some practical examples of its many uses.<\/p>\n<h2>The METADATA Databases<\/h2>\n<p>As of MySQL 5, the information_schema is now listed in the database list when you execute the\u00a0<em>show databases\u00a0<\/em>command:<\/p>\n<p>mysql&gt; show databases;<\/p>\n<pre style=\"background: white;\"><span style=\"font-family: 'Verdana','sans-serif'; color: black;\">+--------------------+ <\/span><\/pre>\n<pre style=\"background: white;\"><span style=\"font-family: 'Verdana','sans-serif'; color: black;\">\u00a0| Database\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0| <\/span><\/pre>\n<pre style=\"background: white;\"><span style=\"font-family: 'Verdana','sans-serif'; color: black;\">\u00a0+--------------------+ <\/span><\/pre>\n<pre style=\"background: white;\"><span style=\"font-family: 'Verdana','sans-serif'; color: black;\">\u00a0| business_contacts\u00a0 |<\/span><\/pre>\n<pre style=\"background: white;\"><span style=\"font-family: 'Verdana','sans-serif'; color: black;\"> | company\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 |<\/span><\/pre>\n<pre style=\"background: white;\"><span style=\"font-family: 'Verdana','sans-serif'; color: black;\"> | customers\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 |<\/span><\/pre>\n<pre style=\"background: white;\"><span style=\"font-family: 'Verdana','sans-serif'; color: black;\"> | information_schema |<\/span><\/pre>\n<pre style=\"background: white;\"><span style=\"font-family: 'Verdana','sans-serif'; color: black;\"> | mysql\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 |<\/span><\/pre>\n<pre style=\"background: white;\"><span style=\"font-family: 'Verdana','sans-serif'; color: black;\"> | performance_schema |<\/span><\/pre>\n<pre style=\"background: white;\"><span style=\"font-family: 'Verdana','sans-serif'; color: black;\"> | sonar\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 |<\/span><\/pre>\n<pre style=\"background: white;\"><span style=\"font-family: 'Verdana','sans-serif'; color: black;\"> +--------------------+ <\/span><\/pre>\n<p>You&#8217;ll also notice the mysql and performance_schema databases, which also store database metadata.<\/p>\n<p>Likewise, issuing a show tables command on the information_schema database will give you a list of all its tables:<\/p>\n<p>mysql&gt; use information_schema; mysql&gt; show tables;<\/p>\n<pre style=\"background: white;\"><span style=\"font-family: 'Verdana','sans-serif'; color: black;\">\u00a0+---------------------------------------+<\/span><\/pre>\n<pre style=\"background: white;\"><span style=\"font-family: 'Verdana','sans-serif'; color: black;\"> | Tables_in_information_schema\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 |<\/span><\/pre>\n<pre style=\"background: white;\"><span style=\"font-family: 'Verdana','sans-serif'; color: black;\"> +---------------------------------------+<\/span><\/pre>\n<pre style=\"background: white;\"><span style=\"font-family: 'Verdana','sans-serif'; color: black;\"> | CHARACTER_SETS\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 |<\/span><\/pre>\n<pre style=\"background: white;\"><span style=\"font-family: 'Verdana','sans-serif'; color: black;\"> | COLLATIONS\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 |<\/span><\/pre>\n<pre style=\"background: white;\"><span style=\"font-family: 'Verdana','sans-serif'; color: black;\"> | COLLATION_CHARACTER_SET_APPLICABILITY |<\/span><\/pre>\n<pre style=\"background: white;\"><span style=\"font-family: 'Verdana','sans-serif'; color: black;\"> | COLUMNS\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 |<\/span><\/pre>\n<pre style=\"background: white;\"><span style=\"font-family: 'Verdana','sans-serif'; color: black;\"> | COLUMN_PRIVILEGES\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 |<\/span><\/pre>\n<pre style=\"background: white;\"><span style=\"font-family: 'Verdana','sans-serif'; color: black;\"> | KEY_COLUMN_USAGE\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0|<\/span><\/pre>\n<pre style=\"background: white;\"><span style=\"font-family: 'Verdana','sans-serif'; color: black;\"> | PROFILING\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 |<\/span><\/pre>\n<pre style=\"background: white;\"><span style=\"font-family: 'Verdana','sans-serif'; color: black;\"> | ROUTINES\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 |<\/span><\/pre>\n<pre style=\"background: white;\"><span style=\"font-family: 'Verdana','sans-serif'; color: black;\"> | SCHEMATA\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 |<\/span><\/pre>\n<pre style=\"background: white;\"><span style=\"font-family: 'Verdana','sans-serif'; color: black;\"> | SCHEMA_PRIVILEGES\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 |<\/span><\/pre>\n<pre style=\"background: white;\"><span style=\"font-family: 'Verdana','sans-serif'; color: black;\"> | STATISTICS\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 |<\/span><\/pre>\n<pre style=\"background: white;\"><span style=\"font-family: 'Verdana','sans-serif'; color: black;\"> | TABLES\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u00a0\u00a0|<\/span><\/pre>\n<pre style=\"background: white;\"><span style=\"font-family: 'Verdana','sans-serif'; color: black;\"> | TABLE_CONSTRAINTS\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 |<\/span><\/pre>\n<pre style=\"background: white;\"><span style=\"font-family: 'Verdana','sans-serif'; color: black;\"> | TABLE_PRIVILEGES\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 |<\/span><\/pre>\n<pre style=\"background: white;\"><span style=\"font-family: 'Verdana','sans-serif'; color: black;\"> | TRIGGERS\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 |<\/span><\/pre>\n<pre style=\"background: white;\"><span style=\"font-family: 'Verdana','sans-serif'; color: black;\"> | USER_PRIVILEGES\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 |<\/span><\/pre>\n<pre style=\"background: white;\"><span style=\"font-family: 'Verdana','sans-serif'; color: black;\"> | VIEWS\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 |<\/span><\/pre>\n<pre style=\"background: white;\"><span style=\"font-family: 'Verdana','sans-serif'; color: black;\"> +---------------------------------------+<\/span><\/pre>\n<p>In actuality, these tables are read-only views.\u00a0 Hence, you cannot change its structure or modify its data. Their sole purpose is to provide information about the database system. In fact, all tables in the INFORMATION_SCHEMA database are stored directly in memory as MEMORY storage engine tables. Thus, when mysqld is shutdown, all information_schema tables are dropped. Then, when MySQL (mysqld) is restarted, all information_schema tables are recreated as TEMPORARY tables and repopulated with metadata for every table.<\/p>\n<h2>Removing the Metadata Databases from Query Results<\/h2>\n<p>Most of the time, when querying the INFORMATION_SCHEMA database, you&#8217;ll only be interested in your own databases, not the metadata ones.\u00a0 To remove them, include this filter in the where clause:<\/p>\n<p>AND information_schema.TABLES.table_schema \u00a0\u00a0\u00a0\u00a0 NOT IN(&#8216;information_schema&#8217;,&#8217;mysql&#8217;,&#8217;performance_schema&#8217;);<\/p>\n<p>It&#8217;s present in most of the following examples\u2026<\/p>\n<h2>Example #1: List All Tables without Primary Key<\/h2>\n<p>Here&#8217;s a query that uses the TABLE_CONSTRAINTS view to check for table names whose constraint_name field is null:<\/p>\n<p>SELECT CONCAT(t.table_schema,&#8217;.&#8217;,t.table_name) as table_nameFROM information_schema.TABLES tLEFT JOIN information_schema.TABLE_CONSTRAINTS tcON t.table_schema = tc.table_schemaAND t.table_name = tc.table_nameAND tc.constraint_type = &#8216;PRIMARY KEY&#8217;WHERE tc.constraint_name IS NULLAND t.table_type = &#8216;BASE TABLE&#8217;AND t.table_schema not in(&#8216;information_schema&#8217;,&#8217;mysql&#8217;,&#8217;performance_schema&#8217;);<\/p>\n<pre style=\"background: white;\"><span style=\"font-family: 'Verdana','sans-serif'; color: black;\">+----------------------------------+<\/span><\/pre>\n<pre style=\"background: white;\"><span style=\"font-family: 'Verdana','sans-serif'; color: black;\"> | table_name\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 | <\/span><\/pre>\n<pre style=\"background: white;\"><span style=\"font-family: 'Verdana','sans-serif'; color: black;\">\u00a0+----------------------------------+<\/span><\/pre>\n<pre style=\"background: white;\"><span style=\"font-family: 'Verdana','sans-serif'; color: black;\">| customers.orders\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 |<\/span><\/pre>\n<pre style=\"background: white;\"><span style=\"font-family: 'Verdana','sans-serif'; color: black;\">| business_contacts.company_info\u00a0\u00a0 |<\/span><\/pre>\n<pre style=\"background: white;\"><span style=\"font-family: 'Verdana','sans-serif'; color: black;\"> | sonar.schema_migrations\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 |<\/span><\/pre>\n<pre style=\"background: white;\"><span style=\"font-family: 'Verdana','sans-serif'; color: black;\">| sonar.resource_index\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 |<\/span><\/pre>\n<pre style=\"background: white;\"><span style=\"font-family: 'Verdana','sans-serif'; color: black;\">| sonar.groups_users\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 |<\/span><\/pre>\n<pre style=\"background: white;\"><span style=\"font-family: 'Verdana','sans-serif'; color: black;\">| sonar.duplications_index\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 |<\/span><\/pre>\n<pre style=\"background: white;\"><span style=\"font-family: 'Verdana','sans-serif'; color: black;\">| sonar.characteristic_edges\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 |<\/span><\/pre>\n<pre style=\"background: white;\"><span style=\"font-family: 'Verdana','sans-serif'; color: black;\">| sonar.action_plans_reviews\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 |<\/span><\/pre>\n<pre style=\"background: white;\"><span style=\"font-family: 'Verdana','sans-serif'; color: black;\"> +----------------------------------+<\/span><\/pre>\n<p>Example #2: Display Tables with More Than a Given Number of Rows<\/p>\n<p>Sometimes it&#8217;s useful to see which tables&#8217; size exceeds a given number of rows.\u00a0 That may signal the time to archive some of the older data for performance reasons.\u00a0 The following SQL statement returns all the tables in your user databases that contain more than one thousand rows:<\/p>\n<p>SELECT CONCAT(table_schema,&#8217;.&#8217;,table_name) as table_name,\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 table_rowsFROM\u00a0\u00a0 information_schema.tables \u00a0WHERE table_rows &gt; 1000 AND table_schema not in(&#8216;information_schema&#8217;,&#8217;mysql&#8217;,&#8217;performance_schema&#8217;);ORDER BY table_rows desc;<\/p>\n<pre style=\"background: white;\"><span style=\"font-family: 'Verdana','sans-serif'; color: black;\">+----------------------------------+------------+ <\/span><\/pre>\n<pre style=\"background: white;\"><span style=\"font-family: 'Verdana','sans-serif'; color: black;\">\u00a0| table_name\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 | table_rows | <\/span><\/pre>\n<pre style=\"background: white;\"><span style=\"font-family: 'Verdana','sans-serif'; color: black;\">\u00a0+----------------------------------+------------+ <\/span><\/pre>\n<pre style=\"background: white;\"><span style=\"font-family: 'Verdana','sans-serif'; color: black;\">\u00a0| customers.orders\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 | 2007\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 | <\/span><\/pre>\n<pre style=\"background: white;\"><span style=\"font-family: 'Verdana','sans-serif'; color: black;\">\u00a0| customers.contact_info\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0| 1245\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 | <\/span><\/pre>\n<pre style=\"background: white;\"><span style=\"font-family: 'Verdana','sans-serif'; color: black;\">\u00a0| customers.rewards_points\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 | 2147\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 | <\/span><\/pre>\n<pre style=\"background: white;\"><span style=\"font-family: 'Verdana','sans-serif'; color: black;\">\u00a0| business_contacts.company_info\u00a0\u00a0 | 1340\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 | <\/span><\/pre>\n<pre style=\"background: white;\"><span style=\"font-family: 'Verdana','sans-serif'; color: black;\">\u00a0| business_contacts.phone_numbers\u00a0 | 1712\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 | <\/span><\/pre>\n<pre style=\"background: white;\"><span style=\"font-family: 'Verdana','sans-serif'; color: black;\">\u00a0| sonar.project_measures \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0| 178618\u00a0\u00a0\u00a0\u00a0 |<\/span><\/pre>\n<pre style=\"background: white;\"><span style=\"font-family: 'Verdana','sans-serif'; color: black;\">| sonar.resource_index \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0| 110328\u00a0\u00a0\u00a0\u00a0 |<\/span><\/pre>\n<pre style=\"background: white;\"><span style=\"font-family: 'Verdana','sans-serif'; color: black;\">| sonar.rule_failures \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0| 40793\u00a0\u00a0\u00a0\u00a0\u00a0 |<\/span><\/pre>\n<pre style=\"background: white;\"><span style=\"font-family: 'Verdana','sans-serif'; color: black;\"> +----------------------------------+------------+ <\/span><\/pre>\n<p>For greater flexibility, this query can be placed in a stored procedure.\u00a0 That way, you can provide the number of rows via an input parameter:<\/p>\n<p>CREATE PROCEDURE `pr_display_tables_with_more_than_n_rows`\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 (IN `numberOfRows` BIGINT)LANGUAGE SQLNOT DETERMINISTICREADS SQL DATASQL SECURITY DEFINERCOMMENT &#8216;Displays tables with more than given number of rows.&#8217;BEGIN\u00a0 SELECT CONCAT(table_schema,&#8217;.&#8217;,table_name) as table_name,\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 table_rows\u00a0 FROM\u00a0\u00a0 information_schema.tables \u00a0\u00a0WHERE table_rows &gt; 1000\u00a0 AND table_schema not in(&#8216;information_schema&#8217;,&#8217;mysql&#8217;,&#8217;performance_schema&#8217;);\u00a0 ORDER BY table_rows desc;END<\/p>\n<h2>Example #3: Display Access Privileges<\/h2>\n<p>You can use the INFORMATION_SCHEMA to review users&#8217; privileges in order to help you decide which rights to grant or revoke. Moreover, the INFORMATION_SCHEMA database can provide views at varying levels of granularity. \u00a0While the SHOW PRIVILEGES command shows the system privileges the server\u00a0<em>supports<\/em>, the INFORMATION_SCHEMA.SCHEMA_PRIVILEGES view lists which database users have been\u00a0<em>assigned<\/em>\u00a0those system privileges:<\/p>\n<p>SELECT grantee, \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0privilege_type, \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0is_grantableFROM\u00a0\u00a0 information_schema.schema_privilegesWHERE\u00a0 table_schema = &#8216;sonar&#8217;;<\/p>\n<pre style=\"background: white;\"><span style=\"font-family: 'Verdana','sans-serif'; color: black;\">+---------------------+-------------------------+--------------+<\/span><\/pre>\n<pre style=\"background: white;\"><span style=\"font-family: 'Verdana','sans-serif'; color: black;\">| grantee\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 | privilege_type\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 | is_grantable |<\/span><\/pre>\n<pre style=\"background: white;\"><span style=\"font-family: 'Verdana','sans-serif'; color: black;\">+---------------------+-------------------------+--------------+<\/span><\/pre>\n<pre style=\"background: white;\"><span style=\"font-family: 'Verdana','sans-serif'; color: black;\">| 'sonar'@'localhost' | SELECT\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 | NO\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 |<\/span><\/pre>\n<pre style=\"background: white;\"><span style=\"font-family: 'Verdana','sans-serif'; color: black;\">| 'sonar'@'localhost' | INSERT\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 | NO\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 |<\/span><\/pre>\n<pre style=\"background: white;\"><span style=\"font-family: 'Verdana','sans-serif'; color: black;\">| 'sonar'@'localhost' | UPDATE\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 | NO\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 |<\/span><\/pre>\n<pre style=\"background: white;\"><span style=\"font-family: 'Verdana','sans-serif'; color: black;\">| 'sonar'@'localhost' | DELETE\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 | NO\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 |<\/span><\/pre>\n<pre style=\"background: white;\"><span style=\"font-family: 'Verdana','sans-serif'; color: black;\">| 'sonar'@'localhost' | CREATE\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 | NO\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 |<\/span><\/pre>\n<pre style=\"background: white;\"><span style=\"font-family: 'Verdana','sans-serif'; color: black;\">| 'sonar'@'localhost' | DROP\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 | NO\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 |<\/span><\/pre>\n<pre style=\"background: white;\"><span style=\"font-family: 'Verdana','sans-serif'; color: black;\">| 'sonar'@'localhost' | REFERENCES\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 | NO\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 |<\/span><\/pre>\n<pre style=\"background: white;\"><span style=\"font-family: 'Verdana','sans-serif'; color: black;\">| 'sonar'@'localhost' | INDEX\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 | NO\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 |<\/span><\/pre>\n<pre style=\"background: white;\"><span style=\"font-family: 'Verdana','sans-serif'; color: black;\">| 'sonar'@'localhost' | ALTER\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 | NO\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 |<\/span><\/pre>\n<pre style=\"background: white;\"><span style=\"font-family: 'Verdana','sans-serif'; color: black;\">| 'sonar'@'localhost' | CREATE TEMPORARY TABLES | NO\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 |<\/span><\/pre>\n<pre style=\"background: white;\"><span style=\"font-family: 'Verdana','sans-serif'; color: black;\">| 'sonar'@'localhost' | LOCK TABLES\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 | NO\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 |<\/span><\/pre>\n<pre style=\"background: white;\"><span style=\"font-family: 'Verdana','sans-serif'; color: black;\">| 'sonar'@'localhost' | EXECUTE\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 | NO\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 |<\/span><\/pre>\n<pre style=\"background: white;\"><span style=\"font-family: 'Verdana','sans-serif'; color: black;\">| 'sonar'@'localhost' | CREATE VIEW\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 | NO\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 |<\/span><\/pre>\n<pre style=\"background: white;\"><span style=\"font-family: 'Verdana','sans-serif'; color: black;\">| 'sonar'@'localhost' | SHOW VIEW\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 | NO\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 |<\/span><\/pre>\n<pre style=\"background: white;\"><span style=\"font-family: 'Verdana','sans-serif'; color: black;\">| 'sonar'@'localhost' | CREATE ROUTINE\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 | NO\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 |<\/span><\/pre>\n<pre style=\"background: white;\"><span style=\"font-family: 'Verdana','sans-serif'; color: black;\">| 'sonar'@'localhost' | ALTER ROUTINE\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 | NO\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 |<\/span><\/pre>\n<pre style=\"background: white;\"><span style=\"font-family: 'Verdana','sans-serif'; color: black;\">| 'sonar'@'localhost' | EVENT\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 | NO\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 |<\/span><\/pre>\n<pre style=\"background: white;\"><span style=\"font-family: 'Verdana','sans-serif'; color: black;\">| 'sonar'@'localhost' | TRIGGER\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 | NO\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 |<\/span><\/pre>\n<pre style=\"background: white;\"><span style=\"font-family: 'Verdana','sans-serif'; color: black;\">+---------------------+-------------------------+--------------+<\/span><\/pre>\n<h2>Example #4: Find Long Running Queries<\/h2>\n<p>In version 5.1, MySQL added the pocesslist to the INFORMATION_SCHEMA database. It shows information on all the currently running processes:<\/p>\n<p>Show processlist;<\/p>\n<p>&nbsp;<\/p>\n<pre style=\"background: white;\"><span style=\"font-family: 'Verdana','sans-serif'; color: black;\">+----+----------+----------------+------+---------+------+-------+-------------------+<\/span><\/pre>\n<pre style=\"background: white;\"><span style=\"font-family: 'Verdana','sans-serif'; color: black;\">| Id | User\u00a0\u00a0\u00a0\u00a0 |Host\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 | db\u00a0\u00a0 | Command | Time | State | Info\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 |<\/span><\/pre>\n<pre style=\"background: white;\"><span style=\"font-family: 'Verdana','sans-serif'; color: black;\">+----+----------+----------------+------+---------+------+-------+-------------------+<\/span><\/pre>\n<pre style=\"background: white;\"><span style=\"font-family: 'Verdana','sans-serif'; color: black;\">| 1\u00a0 | root\u00a0\u00a0\u00a0\u00a0 | localhost:1715 |\u00a0\u00a0\u00a0\u00a0\u00a0 | Sleep\u00a0\u00a0 | 73\u00a0\u00a0 |\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 |\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 |<\/span><\/pre>\n<pre style=\"background: white;\"><span style=\"font-family: 'Verdana','sans-serif'; color: black;\">| 2\u00a0 | root\u00a0\u00a0\u00a0\u00a0 | localhost:1716 | test | Query\u00a0\u00a0 | 0\u00a0\u00a0\u00a0 |\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 | show processlist\u00a0 |<\/span><\/pre>\n<pre style=\"background: white;\"><span style=\"font-family: 'Verdana','sans-serif'; color: black;\">| 5\u00a0 | sonar\u00a0\u00a0\u00a0 | localhost:1835 | test | Sleep\u00a0\u00a0 | 2359 |\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 |\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 |<\/span><\/pre>\n<pre style=\"background: white;\"><span style=\"font-family: 'Verdana','sans-serif'; color: black;\">+----+----------+----------------+------+---------+------+-------+-------------------+<\/span><\/pre>\n<p>We can query the processlist to find long running queries.\u00a0 The Time field is in seconds, so we can fetch all the queries that are running for over10 minutes by comparing it to the expression of sixty seconds times ten:<\/p>\n<p>SELECT * FROM information_schema.processlist WHERE COMMAND = &#8216;Query&#8217;\u00a0 AND\u00a0\u00a0 time\u00a0\u00a0\u00a0 &gt; 60 * 10;<\/p>\n<h2>Conclusion<\/h2>\n<p>There are still many more excellent uses for INFORMATION_SCHEMA that will have to wait until another day.\u00a0 Until then, you can run a SELECT * on any of the INFORMATION_SCHEMA views to see what information is contained therein.<\/p>\n<p>[\/vc_column_text]<p class=\"wpcf7-contact-form-not-found\"><strong>Error:<\/strong> Contact form not found.<\/p>[\/vc_column][\/vc_row]<\/p>\n<\/section>","protected":false},"excerpt":{"rendered":"<p>[vc_row][vc_column][vc_column_text] Understanding the MySQL Information Schema Database The INFORMATION_SCHEMA database is where each MySQL instance stores information about all the other databases that the MySQL server maintains.\u00a0 Also sometimes referred to as the data dictionary and system catalog, it&#8217;s the ideal place to lookup information such as the name of a database or table, the [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-10435","page","type-page","status-publish","hentry","wd-post "],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.3 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>MPGICO, Digital Advertising Solutions Lebanon,Web development Lebanon, Advertising and Marketing solutions Lebanon, web solutions Lebanon, SEO Lebanon, Mobile Applications Lebanon, Web development Qatar, Advertising and Marketing solutions Qatar, web solutions Qatar, SEO Doha Qatar, Mobile Applications Qatar<\/title>\n<meta name=\"description\" content=\"Digital Advertising Solutions Lebanon,Web development Lebanon, Advertising and Marketing solutions Lebanon, web solutions Lebanon, SEO Lebanon\" \/>\n<meta name=\"robots\" content=\"noindex, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"MPGICO, Digital Advertising Solutions Lebanon,Web development Lebanon, Advertising and Marketing solutions Lebanon, web solutions Lebanon, SEO Lebanon, Mobile Applications Lebanon, Web development Qatar, Advertising and Marketing solutions Qatar, web solutions Qatar, SEO Doha Qatar, Mobile Applications Qatar\" \/>\n<meta property=\"og:description\" content=\"Digital Advertising Solutions Lebanon,Web development Lebanon, Advertising and Marketing solutions Lebanon, web solutions Lebanon, SEO Lebanon\" \/>\n<meta property=\"og:url\" content=\"https:\/\/mpgico.com\/new\/mysql\/\" \/>\n<meta property=\"og:site_name\" content=\"mpgico\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/mpgico.com\\\/new\\\/mysql\\\/\",\"url\":\"https:\\\/\\\/mpgico.com\\\/new\\\/mysql\\\/\",\"name\":\"MPGICO, Digital Advertising Solutions Lebanon,Web development Lebanon, Advertising and Marketing solutions Lebanon, web solutions Lebanon, SEO Lebanon, Mobile Applications Lebanon, Web development Qatar, Advertising and Marketing solutions Qatar, web solutions Qatar, SEO Doha Qatar, Mobile Applications Qatar\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/mpgico.com\\\/new\\\/#website\"},\"datePublished\":\"2019-10-25T11:13:14+00:00\",\"description\":\"Digital Advertising Solutions Lebanon,Web development Lebanon, Advertising and Marketing solutions Lebanon, web solutions Lebanon, SEO Lebanon\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/mpgico.com\\\/new\\\/mysql\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/mpgico.com\\\/new\\\/mysql\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/mpgico.com\\\/new\\\/mysql\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/mpgico.com\\\/new\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Mysql\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/mpgico.com\\\/new\\\/#website\",\"url\":\"https:\\\/\\\/mpgico.com\\\/new\\\/\",\"name\":\"mpgico\",\"description\":\"mpgico\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/mpgico.com\\\/new\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"MPGICO, Digital Advertising Solutions Lebanon,Web development Lebanon, Advertising and Marketing solutions Lebanon, web solutions Lebanon, SEO Lebanon, Mobile Applications Lebanon, Web development Qatar, Advertising and Marketing solutions Qatar, web solutions Qatar, SEO Doha Qatar, Mobile Applications Qatar","description":"Digital Advertising Solutions Lebanon,Web development Lebanon, Advertising and Marketing solutions Lebanon, web solutions Lebanon, SEO Lebanon","robots":{"index":"noindex","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"og_locale":"en_US","og_type":"article","og_title":"MPGICO, Digital Advertising Solutions Lebanon,Web development Lebanon, Advertising and Marketing solutions Lebanon, web solutions Lebanon, SEO Lebanon, Mobile Applications Lebanon, Web development Qatar, Advertising and Marketing solutions Qatar, web solutions Qatar, SEO Doha Qatar, Mobile Applications Qatar","og_description":"Digital Advertising Solutions Lebanon,Web development Lebanon, Advertising and Marketing solutions Lebanon, web solutions Lebanon, SEO Lebanon","og_url":"https:\/\/mpgico.com\/new\/mysql\/","og_site_name":"mpgico","twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/mpgico.com\/new\/mysql\/","url":"https:\/\/mpgico.com\/new\/mysql\/","name":"MPGICO, Digital Advertising Solutions Lebanon,Web development Lebanon, Advertising and Marketing solutions Lebanon, web solutions Lebanon, SEO Lebanon, Mobile Applications Lebanon, Web development Qatar, Advertising and Marketing solutions Qatar, web solutions Qatar, SEO Doha Qatar, Mobile Applications Qatar","isPartOf":{"@id":"https:\/\/mpgico.com\/new\/#website"},"datePublished":"2019-10-25T11:13:14+00:00","description":"Digital Advertising Solutions Lebanon,Web development Lebanon, Advertising and Marketing solutions Lebanon, web solutions Lebanon, SEO Lebanon","breadcrumb":{"@id":"https:\/\/mpgico.com\/new\/mysql\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/mpgico.com\/new\/mysql\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/mpgico.com\/new\/mysql\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/mpgico.com\/new\/"},{"@type":"ListItem","position":2,"name":"Mysql"}]},{"@type":"WebSite","@id":"https:\/\/mpgico.com\/new\/#website","url":"https:\/\/mpgico.com\/new\/","name":"mpgico","description":"mpgico","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/mpgico.com\/new\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"}]}},"_links":{"self":[{"href":"https:\/\/mpgico.com\/new\/wp-json\/wp\/v2\/pages\/10435","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mpgico.com\/new\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/mpgico.com\/new\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/mpgico.com\/new\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mpgico.com\/new\/wp-json\/wp\/v2\/comments?post=10435"}],"version-history":[{"count":1,"href":"https:\/\/mpgico.com\/new\/wp-json\/wp\/v2\/pages\/10435\/revisions"}],"predecessor-version":[{"id":10436,"href":"https:\/\/mpgico.com\/new\/wp-json\/wp\/v2\/pages\/10435\/revisions\/10436"}],"wp:attachment":[{"href":"https:\/\/mpgico.com\/new\/wp-json\/wp\/v2\/media?parent=10435"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}