{"id":570,"date":"2016-06-27T02:40:44","date_gmt":"2016-06-27T00:40:44","guid":{"rendered":"https:\/\/www.dereckson.be\/blog\/?p=570"},"modified":"2017-02-09T02:44:08","modified_gmt":"2017-02-09T01:44:08","slug":"a-laravel-command-to-run-a-sql-console-a-la-phabricator","status":"publish","type":"post","link":"https:\/\/www.dereckson.be\/blog\/2016\/06\/27\/a-laravel-command-to-run-a-sql-console-a-la-phabricator\/","title":{"rendered":"A Laravel command to run a SQL console \u00e0 la Phabricator"},"content":{"rendered":"<p>Phabricator offers a <code>bin\/storage shell<\/code> command. It allows to run the <code>mysql<\/code> client with the options from the application configuration.<\/p>\n<p>That&#8217;s useful in a modern distributed environment, when it&#8217;s not always straightforward to know what server contains what databases and what credentials to use. In a Docker container, for example, that could be a linked container or a dedicated bare metal instance.<\/p>\n<p>As Laravel offers standardisation of the configuration, we can provide such a command not only for MySQL but also for PostGreSQL, SQLite and SQL Server.<\/p>\n<p>The only requirement is to get the relevant client installed on the machine.<\/p>\n<p>To implement it into your application, you can drop <a href=\"https:\/\/github.com\/nasqueron\/auth-grove\/blob\/master\/app\/Console\/Commands\/DatabaseShell.php\">DatabaseShell.php<\/a> to your <code>app\/Console\/Commands\/<\/code> folder. (<a href=\"https:\/\/github.com\/nasqueron\/auth-grove\/blob\/699661550c8a3437a76a67bd755f417bbad8c9f7\/app\/Console\/Commands\/DatabaseShell.php\">last commit at post writing<\/a>)<\/p>\n<p>To run it, use <code>php artisan db:shell<\/code>.<\/p>\n<pre>$ shell docker nasqueron-auth-grove\r\napp@0c62f2315807:\/var\/wwwroot\/default$ php artisan db:shell\r\nReading table information for completion of table and column names\r\nYou can turn off this feature to get a quicker startup with -A\r\n\r\nWelcome to the MySQL monitor. Commands end with ; or \\g.\r\nYour MySQL connection id is 9643865\r\nServer version: 5.7.17 MySQL Community Server (GPL)\r\n\r\nCopyright (c) 2000, 2016, 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\n\r\nmysql&gt;\r\n<\/pre>\n<p><em>This post has been last updated 2017-02-09.<\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Phabricator offers a bin\/storage shell command. It allows to run the mysql client with the options from the application configuration. That&#8217;s useful in a modern distributed environment, when it&#8217;s not always straightforward to know what server contains what databases and what credentials to use. In a Docker container, for example, that could be a linked [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[49],"tags":[302,300,304,17],"class_list":["post-570","post","type-post","status-publish","format-standard","hentry","category-dev","tag-cli","tag-laravel","tag-mysql","tag-php"],"_links":{"self":[{"href":"https:\/\/www.dereckson.be\/blog\/wp-json\/wp\/v2\/posts\/570","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.dereckson.be\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.dereckson.be\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.dereckson.be\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.dereckson.be\/blog\/wp-json\/wp\/v2\/comments?post=570"}],"version-history":[{"count":4,"href":"https:\/\/www.dereckson.be\/blog\/wp-json\/wp\/v2\/posts\/570\/revisions"}],"predecessor-version":[{"id":628,"href":"https:\/\/www.dereckson.be\/blog\/wp-json\/wp\/v2\/posts\/570\/revisions\/628"}],"wp:attachment":[{"href":"https:\/\/www.dereckson.be\/blog\/wp-json\/wp\/v2\/media?parent=570"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.dereckson.be\/blog\/wp-json\/wp\/v2\/categories?post=570"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.dereckson.be\/blog\/wp-json\/wp\/v2\/tags?post=570"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}