{"id":3952,"date":"2018-10-01T00:21:36","date_gmt":"2018-09-30T21:21:36","guid":{"rendered":"https:\/\/computingforgeeks.com\/?p=3952"},"modified":"2024-04-16T14:09:48","modified_gmt":"2024-04-16T11:09:48","slug":"mycli-mysql-client-autocompletion-ubuntu","status":"publish","type":"post","link":"https:\/\/computingforgeeks.com\/mycli-mysql-client-autocompletion-ubuntu\/","title":{"rendered":"Install mycli MySQL AutoCompletion on Ubuntu \/ Debian"},"content":{"rendered":"\n<p>In this guide, we will do the installation and usage of mycli on Ubuntu or Debian Linux systems. Mycli is a&nbsp;MySQL terminal client written in Python and <a href=\"https:\/\/github.com\/jonathanslenders\/python-prompt-toolkit\/\" target=\"_blank\" rel=\"noreferrer noopener\">Python Prompt Toolkit<\/a> library with AutoCompletion and Syntax Highlighting. It works with MySQL, MariaDB, and Percona database servers.<\/p>\n\n\n\n<p>mycli exist to help you write complex queries easily and faster without the hassle of having to remember the whole query syntax. It uses<strong>&nbsp;REPL (Read, Eval, Print, Loop)&nbsp;<\/strong> which pop up suggestion menu as soon as you start typing.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">1. Features of mycli<\/h2>\n\n\n\n<p>Here is the complete list of mycli features as listed&nbsp;in the official website.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Auto-completion as you type for SQL keywords as well as <strong>tables<\/strong>, <strong>views<\/strong>, and <strong>columns<\/strong> in the database.<\/li>\n\n\n\n<li>Syntax highlighting using Pygments.<\/li>\n\n\n\n<li>Smart-completion (enabled by default) will suggest context-sensitive completion.\n<ul class=\"wp-block-list\">\n<li><code>SELECT * FROM &lt;tab&gt;<\/code>&nbsp;will only show table names.<\/li>\n\n\n\n<li><code>SELECT * FROM users WHERE &lt;tab&gt;<\/code>&nbsp;will only show column names.<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>Support for multiline queries.<\/li>\n\n\n\n<li>Favorite queries with optional positional parameters. Save a query using&nbsp;<code>\\fs alias query<\/code>&nbsp;and execute it with&nbsp;<code>\\f alias<\/code>&nbsp;whenever you need.<\/li>\n\n\n\n<li>The timing of sql statements and table rendering.<\/li>\n\n\n\n<li>Config file is automatically created at&nbsp;<code>~\/.myclirc<\/code>&nbsp;on the first launch.<\/li>\n\n\n\n<li>Log every query and its results to a file (disabled by default).<\/li>\n\n\n\n<li>Pretty prints tabular data (with colors!)<\/li>\n\n\n\n<li>Support for SSL connections<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">2. Installing\u00a0mycli on Ubuntu or Debian<\/h2>\n\n\n\n<p>mycli can be installed using <code>pip<\/code>&nbsp;python package manager or from <code>apt<\/code>&nbsp;repository.<\/p>\n\n\n\n<p><strong>Install mycli from apt repository<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt update &amp;&amp; sudo apt install mycli<\/code><\/pre>\n\n\n\n<p><strong>Installing mycli using pip:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><em><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-purple-color\"># Python 3\n<\/mark><\/em>sudo apt install python3-pip\nsudo pip3 install mycli\n\n<em><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-cyan-blue-color\"># Python 2\n<\/mark><\/em>sudo apt install python-pip\nsudo pip install mycli<\/code><\/pre>\n\n\n\n<p><strong>or install mycli using <code>easy_install<\/code><\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo easy_install mycli<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">3. Using mycli MySQL Client autocompletion tool<\/h2>\n\n\n\n<p>Note that the suggestions are <strong>context sensitive<\/strong> based on the position of the cursor. eg: Only tables are suggested after the <strong>FROM<\/strong> keyword, only column names are suggested after the <strong>WHERE<\/strong> clause.<\/p>\n\n\n\n<p>With Smart Completion <strong>ON<\/strong>, Only table names from the current database are suggested after the <strong>FROM<\/strong> keyword and&nbsp;Column names from the current table are suggested after the <strong>WHERE<\/strong> clause.<\/p>\n\n\n\n<p>To view usage man page, use the command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$<mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-pale-pink-color\"> mycli  --help<\/mark>\nUsage: mycli &#91;OPTIONS] &#91;DATABASE]\n\n  A MySQL terminal client with auto-completion and syntax highlighting.\n\n  Examples:\n    - mycli my_database\n    - mycli -u my_user -h my_host.com my_database\n    - mycli mysql:\/\/my_user@my_host.com:3306\/my_database\n\nOptions:\n  -h, --host TEXT               Host address of the database.\n  -P, --port INTEGER            Port number to use for connection. Honors\n                                $MYSQL_TCP_PORT.\n  -u, --user TEXT               User name to connect to the database.\n  -S, --socket TEXT             The socket file to use for connection.\n  -p, --password TEXT           Password to connect to the database.\n  --pass TEXT                   Password to connect to the database.\n  --ssh-user TEXT               User name to connect to ssh server.\n  --ssh-host TEXT               Host name to connect to ssh server.\n  --ssh-port INTEGER            Port to connect to ssh server.\n  --ssh-password TEXT           Password to connect to ssh server.\n  --ssh-key-filename TEXT       Private key filename (identify file) for the\n                                ssh connection.\n  --ssl-ca PATH                 CA file in PEM format.\n  --ssl-capath TEXT             CA directory.\n  --ssl-cert PATH               X509 cert in PEM format.\n  --ssl-key PATH                X509 key in PEM format.\n  --ssl-cipher TEXT             SSL cipher to use.\n  --ssl-verify-server-cert      Verify server's \"Common Name\" in its cert\n                                against hostname used when connecting. This\n                                option is disabled by default.\n  -V, --version                 Output mycli's version.\n  -v, --verbose                 Verbose output.\n  -D, --database TEXT           Database to use.\n  -d, --dsn TEXT                Use DSN configured into the &#91;alias_dsn]\n                                section of myclirc file.\n  --list-dsn                    list of DSN configured into the &#91;alias_dsn]\n                                section of myclirc file.\n  -R, --prompt TEXT             Prompt format (Default: \"\\t \\u@\\h:\\d&gt; \").\n  -l, --logfile FILENAME        Log every query and its results to a file.\n  --defaults-group-suffix TEXT  Read MySQL config groups with the specified\n                                suffix.\n  --defaults-file PATH          Only read MySQL options from the given file.\n  --myclirc PATH                Location of myclirc file.\n  --auto-vertical-output        Automatically switch to vertical output mode\n                                if the result is wider than the terminal\n                                width.\n  -t, --table                   Display batch output in table format.\n  --csv                         Display batch output in CSV format.\n  --warn \/ --no-warn            Warn before running a destructive query.\n  --local-infile BOOLEAN        Enable\/disable LOAD DATA LOCAL INFILE.\n  --login-path TEXT             Read this path from the login file.\n  -e, --execute TEXT            Execute command and quit.\n  --help                        Show this message and exit.<\/code><\/pre>\n\n\n\n<p>See below example which connect to the local MariaDB database server as&nbsp;a<strong> root&nbsp;<\/strong>user:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-pale-pink-color\">mycli -h localhost -u root<\/mark> <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-purple-color\">-p<\/mark>\nConnecting to socket \/var\/run\/mysqld\/mysqld.sock, owned by user mysql\nPassword: \nMariaDB 10.6.7\nmycli 1.24.3\nHome: http:\/\/mycli.net\nBug tracker: https:\/\/github.com\/dbcli\/mycli\/issues\nThanks to the contributor - Jakub Boukal\nMariaDB root@localhost:(none)&gt;<\/code><\/pre>\n\n\n\n<p>Typing&nbsp;<strong>SHOW&nbsp;<\/strong>and space shows valid options<\/p>\n\n\n\n<figure class=\"wp-block-image is-resized\"><a href=\"https:\/\/computingforgeeks.com\/wp-content\/uploads\/2018\/10\/mycli-tab-completion-01-min.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"253\" src=\"https:\/\/computingforgeeks.com\/wp-content\/uploads\/2018\/10\/mycli-tab-completion-01-min-1024x253.png\" alt=\"\" class=\"wp-image-3954\" title=\"\" srcset=\"https:\/\/computingforgeeks.com\/wp-content\/uploads\/2018\/10\/mycli-tab-completion-01-min-1024x253.png 1024w, https:\/\/computingforgeeks.com\/wp-content\/uploads\/2018\/10\/mycli-tab-completion-01-min-300x74.png 300w, https:\/\/computingforgeeks.com\/wp-content\/uploads\/2018\/10\/mycli-tab-completion-01-min-768x190.png 768w, https:\/\/computingforgeeks.com\/wp-content\/uploads\/2018\/10\/mycli-tab-completion-01-min-696x172.png 696w, https:\/\/computingforgeeks.com\/wp-content\/uploads\/2018\/10\/mycli-tab-completion-01-min-1068x264.png 1068w, https:\/\/computingforgeeks.com\/wp-content\/uploads\/2018\/10\/mycli-tab-completion-01-min.png 1286w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure>\n\n\n\n<p>If you switch to a database and type&nbsp;<strong>SELECT * FROM&nbsp;<\/strong>followed by &lt;tab&gt;, all options listed should be for the tables in the current database, and <strong>WHERE<\/strong> <strong>&lt;tab&gt;<\/strong>&nbsp;will only show column names.<\/p>\n\n\n\n<figure class=\"wp-block-image is-resized\"><a href=\"https:\/\/computingforgeeks.com\/wp-content\/uploads\/2018\/10\/mycli-tab-completion-02-min.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"563\" src=\"https:\/\/computingforgeeks.com\/wp-content\/uploads\/2018\/10\/mycli-tab-completion-02-min-1024x563.png\" alt=\"\" class=\"wp-image-3955\" title=\"\" srcset=\"https:\/\/computingforgeeks.com\/wp-content\/uploads\/2018\/10\/mycli-tab-completion-02-min-1024x563.png 1024w, https:\/\/computingforgeeks.com\/wp-content\/uploads\/2018\/10\/mycli-tab-completion-02-min-300x165.png 300w, https:\/\/computingforgeeks.com\/wp-content\/uploads\/2018\/10\/mycli-tab-completion-02-min-768x422.png 768w, https:\/\/computingforgeeks.com\/wp-content\/uploads\/2018\/10\/mycli-tab-completion-02-min-696x383.png 696w, https:\/\/computingforgeeks.com\/wp-content\/uploads\/2018\/10\/mycli-tab-completion-02-min-1068x588.png 1068w, https:\/\/computingforgeeks.com\/wp-content\/uploads\/2018\/10\/mycli-tab-completion-02-min-764x420.png 764w, https:\/\/computingforgeeks.com\/wp-content\/uploads\/2018\/10\/mycli-tab-completion-02-min.png 1527w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure>\n\n\n\n<p>For more information on using and configuring mycli,&nbsp;<a href=\"http:\/\/mycli.net\/docs\" target=\"_blank\" rel=\"noreferrer noopener\">check the official documentation<\/a>.<\/p>\n\n\n\n<p>Recommended books:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/computingforgeeks.com\/best-books-to-learn-mysql-mariadb-databases\/\" target=\"_blank\" rel=\"noreferrer noopener\">Best Books To Learn MySQL \/ MariaDB Databases<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>In this guide, we will do the installation and usage of mycli on Ubuntu or Debian Linux systems. Mycli is a&nbsp;MySQL terminal client written in Python and Python Prompt Toolkit library with AutoCompletion and Syntax Highlighting. It works with MySQL, MariaDB, and Percona database servers. mycli exist to help you write complex queries easily and &#8230; <a title=\"Install mycli MySQL AutoCompletion on Ubuntu \/ Debian\" class=\"read-more\" href=\"https:\/\/computingforgeeks.com\/mycli-mysql-client-autocompletion-ubuntu\/\" aria-label=\"Read more about Install mycli MySQL AutoCompletion on Ubuntu \/ Debian\">Read more<\/a><\/p>\n","protected":false},"author":3,"featured_media":3956,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[461,329,26,50,53,81],"tags":[279,610,323,611],"cfg_series":[],"class_list":["post-3952","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-databases","category-automation","category-debian","category-linux-tutorials","category-mariadb","category-ubuntu","tag-mariadb","tag-mycli","tag-mysql","tag-percona"],"_links":{"self":[{"href":"https:\/\/computingforgeeks.com\/wp-json\/wp\/v2\/posts\/3952","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/computingforgeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/computingforgeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/computingforgeeks.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/computingforgeeks.com\/wp-json\/wp\/v2\/comments?post=3952"}],"version-history":[{"count":0,"href":"https:\/\/computingforgeeks.com\/wp-json\/wp\/v2\/posts\/3952\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/computingforgeeks.com\/wp-json\/wp\/v2\/media\/3956"}],"wp:attachment":[{"href":"https:\/\/computingforgeeks.com\/wp-json\/wp\/v2\/media?parent=3952"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/computingforgeeks.com\/wp-json\/wp\/v2\/categories?post=3952"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/computingforgeeks.com\/wp-json\/wp\/v2\/tags?post=3952"},{"taxonomy":"cfg_series","embeddable":true,"href":"https:\/\/computingforgeeks.com\/wp-json\/wp\/v2\/cfg_series?post=3952"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}