dbcli / mycli

A Terminal Client for MySQL with AutoCompletion and Syntax Highlighting.
http://mycli.net
Other
11.42k stars 660 forks source link

Why aren't table/column names auto-completing? #513

Open HolaYang opened 7 years ago

HolaYang commented 7 years ago

Any way to diagnose why mycli can not auto complete on any field names or table names?

Mysql version:

mysql  Ver 14.14 Distrib 5.6.25, for debian-linux-gnu (x86_64) using  EditLine wrapper

~/.myclirc

# vi: ft=dosini
[main]

# Enables context sensitive auto-completion. If this is disabled the all
# possible completions will be listed.
smart_completion = True

# Multi-line mode allows breaking up the sql statements into multiple lines. If
# this is set to True, then the end of the statements must have a semi-colon.
# If this is set to False then sql statements can't be split into multiple
# lines. End of line (return) is considered as the end of the statement.
multi_line = False

# Destructive warning mode will alert you before executing a sql statement
# that may cause harm to the database such as "drop table", "drop database"
# or "shutdown".
destructive_warning = True

# log_file location.
log_file = ~/.mycli.log

# Default log level. Possible values: "CRITICAL", "ERROR", "WARNING", "INFO"
# and "DEBUG".
log_level = INFO

# Log every query and its results to a file. Enable this by uncommenting the
# line below.
# audit_log = ~/.mycli-audit.log

# Timing of sql statments and table rendering.
timing = True

# Table format. Possible values: psql, plain, simple, grid, fancy_grid, pipe,
# orgtbl, rst, mediawiki, html, latex, latex_booktabs, tsv.
# Recommended: psql, fancy_grid and grid.
table_format = ascii

# Syntax Style. Possible values: manni, igor, xcode, vim, autumn, vs, rrt,
# native, perldoc, borland, tango, emacs, friendly, monokai, paraiso-dark,
# colorful, murphy, bw, pastie, paraiso-light, trac, default, fruity
syntax_style = default

# Keybindings: Possible values: emacs, vi.
# Emacs mode: Ctrl-A is home, Ctrl-E is end. All emacs keybindings are available in the REPL.
# When Vi mode is enabled you can use modal editing features offered by Vi in the REPL.
key_bindings = vi

# Enabling this option will show the suggestions in a wider menu. Thus more items are suggested.
wider_completion_menu = True

# MySQL prompt
# \t - Product type (Percona, MySQL, Mariadb)
# \u - Username
# \h - Hostname of the server
# \d - Database name
# \n - Newline
prompt = '\t \u@\h:\d> '

# Custom colors for the completion menu, toolbar, etc.
[colors]
# Completion menus.
Token.Menu.Completions.Completion.Current = 'bg:#00aaaa #000000'
Token.Menu.Completions.Completion = 'bg:#008888 #ffffff'
Token.Menu.Completions.MultiColumnMeta = 'bg:#aaffff #000000'
Token.Menu.Completions.ProgressButton = 'bg:#003333'
Token.Menu.Completions.ProgressBar = 'bg:#00aaaa'

# Selected text.
Token.SelectedText = '#ffffff bg:#6666aa'

# Search matches. (reverse-i-search)
Token.SearchMatch = '#ffffff bg:#4444aa'
Token.SearchMatch.Current = '#ffffff bg:#44aa44'

# The bottom toolbar.
Token.Toolbar.Off = 'bg:#222222 #888888'
Token.Toolbar.On = 'bg:#222222 #ffffff'

# Search/arg/system toolbars.
Token.Toolbar.Search = 'noinherit bold'
Token.Toolbar.Search.Text = 'nobold'
Token.Toolbar.System = 'noinherit bold'
Token.Toolbar.Arg = 'noinherit bold'
Token.Toolbar.Arg.Text = 'nobold'

# Favorite queries.
[favorite_queries]
tsroten commented 7 years ago

@Takeoffyoung Hello! Here a few things to check:

  1. Make sure that a default database is set. In mycli, just run connect and make sure that it says ...connected to database "{database name}".... Mycli will autocomplete table names from whatever the current default database is (set via the use command`).
  2. Column autocompletion doesn't work unless the table name is in the query. For instance, typing select a is not going to autcomplete all the columns with a in it. You'd have to do select [a] from table1; where you type the from part and then back track to the column part of the select statement.
  3. Run the auto-completion refresh and make sure no errors appear. In mycli run \#
HolaYang commented 7 years ago

It works well after add -D {database name} to command.

But I cannot find any tips like "specifying database is precondition of enabling auto-complete".

Polishing README maybe matter.

Thanks 👍

tsroten commented 7 years ago

@Takeoffyoung I'm glad you figured it out. We're happy to help out if you come across anything else.

We actually do mention this in our documentation:

Only table names from the current database are suggested after the FROM keyword.

HolaYang commented 7 years ago

The document should clear that using USE {database name} does not work but specifying it via appending -D {database name} to startup command does.

No matter if it is after FROM keyword.

tsroten commented 7 years ago

@Takeoffyoung Both USE and -D should work for setting the current database that is used for suggesting completions. If it doesn't, then there might be an issue we should look into. That's how it currently works on mycli when I test it.