如果返回一个大的结果集,但是缺少内存,可以使用—quick选项。这会强制mysql从服务器端一次返回一行,而不是将所有结果集都放到内存中。这种方式的实现是调用一个名叫mysql_use_result()的C API,而不是调用mysql_store_result()的C API。

    mysql 常用选项
    —bind-address
    如果有多个网卡接口,使用该选项决定使用哪个ip去连接mysql服务器。

    —compress,-C
    在服务端与客户端之间压缩所有的信息。

    —database=db_name,-D db_name
    指定哪个数据库

    —delimiter=str
    指定分隔符,默认是分号。

    —host=name,-h name
    指定服务器名称。

    —max_allowed_packet=value
    默认16MB,最大1GB。服务器与客户端通信的最大缓存。

    —max_join_size=value
    当使用safe_updates时,在连接语句中自动限制行数。

    —password=[password],-p[password]
    指定用户密码,当使用-p时,密码与-p之间不能有空格。

    —port,-P
    指定端口

    —protocol={TCP/SOCKET/PIPE/MEMORY}
    指定传输协议

    —quick
    每收到一行就显示一行,而不是把结果全部缓存。

    —safe-updates
    update或者delete语句中,没有使用where子句或者limit子句时,会报错。

    —select-limit
    当使用safe-updates时,限制select返回的行,默认1000。

    —socket,-S
    本地连接时使用的socket文件

    mysql命令

    1. mysql> help
    2. List of all MySQL commands:
    3. Note that all text commands must be first on line and end with ';'
    4. ? (\?) Synonym for `help'.
    5. clear (\c) Clear the current input statement.
    6. connect (\r) Reconnect to the server. Optional arguments are db and host.
    7. delimiter (\d) Set statement delimiter.
    8. edit (\e) Edit command with $EDITOR.
    9. ego (\G) Send command to mysql server, display result vertically.
    10. exit (\q) Exit mysql. Same as quit.
    11. go (\g) Send command to mysql server.
    12. help (\h) Display this help.
    13. nopager (\n) Disable pager, print to stdout.
    14. notee (\t) Don't write into outfile.
    15. pager (\P) Set PAGER [to_pager]. Print the query results via PAGER.
    16. print (\p) Print current command.
    17. prompt (\R) Change your mysql prompt.
    18. quit (\q) Quit mysql.
    19. rehash (\#) Rebuild completion hash.
    20. source (\.) Execute an SQL script file. Takes a file name as an argument.
    21. status (\s) Get status information from the server.
    22. system (\!) Execute a system shell command.
    23. tee (\T) Set outfile [to_outfile]. Append everything into given
    24. outfile.
    25. use (\u) Use another database. Takes database name as argument.
    26. charset (\C) Switch to another charset. Might be needed for processing
    27. binlog with multi-byte charsets.
    28. warnings (\W) Show warnings after every statement.
    29. nowarning (\w) Don't show warnings after every statement.
    30. resetconnection(\x) Clean session context.
    31. For server side help, type 'help contents'

    mysql客户端日志
    在unix系统中,mysql客户端会把命令记录到家目录中的.mysql_history文件中
    如果一条语句是多行,会分两次记录,一次记录原始语句,一次记录整条语句。

    mysql> SELECT
        -> 'Today is'
        -> ,
        -> CURDATE()
        -> ;
    

    会记录成以下格式:

    SELECT
    'Today is'
    ,
    CURDATE()
    ;
    SELECT 'Today is' , CURDATE();
    

    如果想禁用.mysql_history,可以按照以下步骤设置:
    1/删除.mysql_history
    2/将MYSQL_HISTFILE的路径设置为/dev/null
    3/创建一个软链接

    ln -s /dev/null $HOME/.mysql_history
    

    使用help contents获得服务器端的帮助

    mysql> help contents;
    You asked for help about help category: "Contents"
    For more information, type 'help <item>', where <item> is one of the following
    categories:
       Account Management
       Administration
       Compound Statements
       Contents
       Data Definition
       Data Manipulation
       Data Types
       Functions
       Geographic Features
       Help Metadata
       Language Structure
       Plugins
       Procedures
       Storage Engines
       Table Maintenance
       Transactions
       User-Defined Functions
       Utility
    

    mysql客户端使用text文件

    mysql db_name < text_file
    

    如果mysql已经启动,且需要执行text文件中的脚本,可以使用source语句或者. :

    mysql> source file_name
    mysql> \. file_name