美高梅网投网站-美高梅手机网投-美高梅官方网站
做最好的网站

您的位置:美高梅网投网址 > 数据库 > 美高梅官方网站那样做的实惠就是让我们我们在

美高梅官方网站那样做的实惠就是让我们我们在

发布时间:2019-11-06 22:15编辑:数据库浏览(193)

        登录数据库后,选择数据库时发现以下提示,

    想必大家在命令行操作mysql的时候会十分发愁现在的操作的是那个数据库吧,至少我就纠结过,可能您会说我打一条命令不就知道了,是的这样做确实可以的。
    可是今儿给大家介绍个好用的命令--prompt

    mysql> use test
    Reading table information for completion of table and column names
    You can turn off this feature to get a quicker startup with -A

    复制代码 代码如下:

    Database changed
    mysql>

    [root@fsailing1 ~]# mysql -uroot -p --prompt="\u@\h:\d \r:\m:\s>"
    Enter password:
    Welcome to the MySQL monitor.  Commands end with ; or g.
    Your MySQL connection id is 378
    Server version: 5.0.95 Source distribution

        意思是 预读这个库中表以及表列信息,一般原因是当库中表很多,表中数据很大时,就会出现执行use <库名>后半天没反应,连接很慢的情况,解决办法就是 -A 方式登录数据库,不会预读库中表信息。

    Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.

    shell> mysql -h hostname -u username -P port -p -A

    Oracle is a registered trademark of Oracle Corporation and/or its
    affiliates. Other names may be trademarks of their respective
    owners.

    Enter password:

    Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.

    (eg:shell> mysql -h 127.0.0.1 -u root -P 3306 -p -A)

    root@localhost:(none) 08:23:32>use test;
    Reading table information for completion of table and column names
    You can turn off this feature to get a quicker startup with -A

    本机登录数据库,直接执行-A也是可以的。

    Database changed
    root@localhost:test 08:23:44>exit;

    mysql> use test;
    Reading table information for completion of table and column names
    You can turn off this feature to get a quicker startup with -A

    这样做的好处就是让我们大家在操作数据库时更加方便快捷。

    Database changed
    mysql> q
    Bye
    [root@localhost ~]# mysql -u root -p -A
    Enter password:
    Welcome to the MySQL monitor. Commands end with ; or g.
    Your MySQL connection id is 12
    Server version: 5.7.23 MySQL Community Server (GPL)

    您也可以在在my.cnf配置文件里进行配置:

    Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

    复制代码 代码如下:

    Oracle is a registered trademark of Oracle Corporation and/or its
    affiliates. Other names may be trademarks of their respective
    owners.

    [mysql]
    prompt=mysql(\u@\h:\d)>

    Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.

    default-character-set=utf8

    mysql> use test
    Database changed
    mysql>

    复制代码 代码如下:

    另一种情况,无法切换访问数据库,提示此信息。(我没遇到过,一并贴过来了解下)

    [root@fsailing1 ~]# vim /etc/my.cnf
    [root@fsailing1 ~]# service mysqld restart
    停止 MySQL:                                               [确定]
    启动 MySQL:                                               [确定]
    [root@fsailing1 ~]# mysql -uroot -p
    Enter password:
    Welcome to the MySQL monitor.  Commands end with ; or g.
    Your MySQL connection id is 2
    Server version: 5.0.95 Source distribution

    由于MYSQL中数据库太大,导致读取预读时间太长,从而显示这个提示,如果之前都没有遇到这个问题,那么产生这个问题的原因可能是由于有改变数据库信息的操作,比如drop一个很大的表(几千万数据)而中途终止.

    Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.

    mysql> show processlist ;    (查看进程)

    Oracle is a registered trademark of Oracle Corporation and/or its
    affiliates. Other names may be trademarks of their respective
    owners.

    美高梅官方网站 1

    Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.

    上图中锁表的id为16545618,则可以使用kill命令,结束它.

    mysql(root@localhost:(none))>use test;
    Reading table information for completion of table and column names
    You can turn off this feature to get a quicker startup with -A

    mysql> kill 16545618;

    Database changed
    mysql(root@localhost:test)>

    删除这些锁表的情况,我的mysql就能正常访问了。

    这里也给出需要的一些个选项供大家参考。

     

    Option Description
    c A counter that increments for each statement you issue
    D The full current date
    d The default database
    h The server host
    l The current delimiter (new in 5.1.12)
    m Minutes of the current time
    n A newline character
    O The current month in three-letter format (Jan, Feb, …)
    o The current month in numeric format
    P am/pm
    p The current TCP/IP port or socket file
    R The current time, in 24-hour military time (0–23)
    r The current time, standard 12-hour time (1–12)
    S Semicolon
    s Seconds of the current time
    t A tab character
    U

    Your full user_name@host_name account name

    u Your user name
    v The server version
    w The current day of the week in three-letter format (Mon, Tue, …)
    Y The current year, four digits
    y The current year, two digits
    _ A space
      A space (a space follows the backslash)
    ' Single quote
    " Double quote
    \ A literal “” backslash character
    x

    x, for any “x” not listed above

    本文由美高梅网投网址发布于数据库,转载请注明出处:美高梅官方网站那样做的实惠就是让我们我们在

    关键词: