{"id":433,"date":"2018-11-20T10:58:16","date_gmt":"2018-11-20T10:58:16","guid":{"rendered":"https:\/\/blogs.ua.es\/jpm33\/?p=433"},"modified":"2018-11-20T10:58:16","modified_gmt":"2018-11-20T10:58:16","slug":"mysql-query-log","status":"publish","type":"post","link":"https:\/\/blogs.ua.es\/jpm33\/2018\/11\/20\/mysql-query-log\/","title":{"rendered":"MySQL Query Log"},"content":{"rendered":"<h1>Introducci\u00f3n<\/h1>\n<p>En ocasiones queremos depurar qu\u00e9 consulta se ejecuta de forma efectiva en la base de datos (por ejemplo al usar consultas preparadas o un ORM) y la forma de hacer cuando usamos como SGBD MySQL es activar el General Query Log.<\/p>\n<p>Este Log es un registro de las consultas que va ejecutando el servidor MySQL. Adem\u00e1s, hay que tener presente que este log se debe activar s\u00f3lo cuando estamos depurando una funcionalidad puntual pues en servidores muy activos puede crecer hasta alcanzar un gran tama\u00f1o.<\/p>\n<h1>Uso de General Query Log<\/h1>\n<p>Lo primero es editar el firchero my.cnf\u00a0 (o my.ini en windows) y buscar la secci\u00f3n [mysqld]. En ella pondremos las opciones:<\/p>\n<pre><code>general_log_file = \/path\/to\/query.log\r\ngeneral_log      = 1<\/code><\/pre>\n<p>Tras reiniciar el servidor mysql, podemos abrir el fichero de log y ejecutar varias consultas:<\/p>\n<pre><code>$ mysql -uroot mysql\r\nWelcome to the MySQL monitor.  Commands end with ; or \\g.\r\nYour MySQL connection id is 212\r\nServer version: 5.7.21 MySQL Community Server (GPL)\r\n\r\nCopyright (c) 2000, 2018, Oracle and\/or its affiliates. All rights reserved.\r\n\r\nOracle is a registered trademark of Oracle Corporation and\/or its\r\naffiliates. Other names may be trademarks of their respective\r\nowners.\r\n\r\nType 'help;' or '\\h' for help. Type '\\c' to clear the current input statement.\r\nmysql&gt; select User, Host from user;\r\n+---------------+-----------+\r\n| User          | Host      |\r\n+---------------+-----------+\r\n| tienda        | %         |\r\n| mysql.session | localhost |\r\n| mysql.sys     | localhost |\r\n| root          | localhost |\r\n+---------------+-----------+\r\n4 rows in set (0.00 sec)\r\n<\/code><\/pre>\n<p>El fichero de log generado por el servidor contiene:<\/p>\n<pre><code>\r\nwampmysqld, Version: 5.7.21-log (MySQL Community Server (GPL)). started with:\r\nTCP Port: 3306, Named Pipe: \/tmp\/mysql.sock\r\nTime                 Id Command    Argument\r\n2018-11-20T10:55:09.930402Z\t    2 Connect\troot@localhost on mysql using TCP\/IP\r\n2018-11-20T10:55:09.934477Z\t    2 Query\tselect @@version_comment limit 1\r\n2018-11-20T10:55:20.218671Z\t    2 Query\tselect User, Host from user\r\n2018-11-20T10:55:21.721707Z\t    2 Quit\t\r\n<\/code><\/pre>\n<p>Y estas son las sentencias que se ejecutan en MySQL.<\/p>\n<h1>Referencias<\/h1>\n<ul>\n<li><a href=\"https:\/\/dev.mysql.com\/doc\/refman\/5.6\/en\/query-log.html\">https:\/\/dev.mysql.com\/doc\/refman\/5.6\/en\/query-log.html<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Introducci\u00f3n En ocasiones queremos depurar qu\u00e9 consulta se ejecuta de forma efectiva en la base de datos (por ejemplo al usar consultas preparadas o un ORM) y la forma de hacer cuando usamos como SGBD MySQL es activar el General &hellip; <a href=\"https:\/\/blogs.ua.es\/jpm33\/2018\/11\/20\/mysql-query-log\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":3080,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[676],"tags":[],"class_list":["post-433","post","type-post","status-publish","format-standard","hentry","category-sin-categoria"],"_links":{"self":[{"href":"https:\/\/blogs.ua.es\/jpm33\/wp-json\/wp\/v2\/posts\/433","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogs.ua.es\/jpm33\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.ua.es\/jpm33\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.ua.es\/jpm33\/wp-json\/wp\/v2\/users\/3080"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.ua.es\/jpm33\/wp-json\/wp\/v2\/comments?post=433"}],"version-history":[{"count":3,"href":"https:\/\/blogs.ua.es\/jpm33\/wp-json\/wp\/v2\/posts\/433\/revisions"}],"predecessor-version":[{"id":437,"href":"https:\/\/blogs.ua.es\/jpm33\/wp-json\/wp\/v2\/posts\/433\/revisions\/437"}],"wp:attachment":[{"href":"https:\/\/blogs.ua.es\/jpm33\/wp-json\/wp\/v2\/media?parent=433"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.ua.es\/jpm33\/wp-json\/wp\/v2\/categories?post=433"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.ua.es\/jpm33\/wp-json\/wp\/v2\/tags?post=433"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}