如何获取mysql帮助信息

如何获取mysql帮助信息,第1张

获取mysql有关的帮助信息,直接在mysql提示符下输入help即可获得有关在mysql客户端相关的帮助信息。

这个方式与Oracle SQL*plus下的help 是类似的。

mysql>help

For information about MySQL products and services, visit:

http://www.mysql.com/

For developer information, including the MySQL Reference Manual, visit:

http://dev.mysql.com/

To buy MySQL Enterprise support, training, or other products, visit:

https://shop.mysql.com/

List of all MySQL commands:

Note that all text commands must be first on line and end with ''

? (\?) Synonym for `help'.

clear (\c) Clear the current input statement. --清除当前输入的语句

connect (\r) Reconnect to the server. Optional arguments are db and host. --重新连接,通常用于被剔除或异常断开后重新连接,SQL*plus下也有这样一个connect命令

delimiter (\d) Set statement delimiter. --设置命令终止符,缺省为;,比如我们可以设定为/来表示语句结束

edit (\e) Edit command with $EDITOR. --编辑缓冲区的上一条SQL语句到文件,缺省调用vi,文件会放在/tmp路径下

ego (\G) Send command to mysql server, display result vertically. --控制结果显示为垂直显示

exit (\q) Exit mysql. Same as quit. --退出mysql

go(\g) Send command to mysql server. --发送命令到mysql服务

help (\h) Display this help.

nopager (\n) Disable pager, print to stdout.--关闭页设置,打印到标准输出

notee (\t) Don't write into outfile. --关闭输出到文件

pager (\P) Set PAGER [to_pager]. Print the query results via PAGER. --设置pager方式,可以设置为调用more,less等等,主要是用于分页显示

print (\p) Print current command.

prompt(\R) Change your mysql prompt. --改变mysql的提示符

quit (\q) Quit mysql.

rehash(\#) Rebuild completion hash. --自动补齐相关对象名字

source(\.) Execute an SQL script file. Takes a file name as an argument. --执行脚本文件

status(\s) Get status information from the server.--获得状态信息

system(\!) Execute a system shell command.--执行系统命令

tee (\T) Set outfile [to_outfile]. Append everything into given outfile.-- *** 作结果输出到文件

use (\u) Use another database. Takes database name as argument. --切换数据库

charset (\C) Switch to another charset. Might be needed for processing binlog with multi-byte charsets. --设置字符集

warnings (\W) Show warnings after every statement. --打印警告信息

nowarning (\w) Don't show warnings after every statement.

--上面的所有命令,扩号内的为快捷 *** 作,即只需要输入“\”+ 字母即可执行

For server side help, type 'help contents'--注意这里的描述help contents将获得服务器端的相关帮助信息

--演示部分,演示常用命令

--connect命令

mysql>connect chardb localhost

Reading table information for completion of table and column names

You can turn off this feature to get a quicker startup with -A

Connection id:5

Current database: chardb

--设置分页,在多余一个页面显示时会不停的翻滚,用该命令可以设置分页,设置为调用系统命令

mysql>pager more --设置为more方式

PAGER set to 'more'

mysql>select table_name,table_type,engine from information_schema.tables --该查询会超出一屏显示后按空格键会自动翻滚到下一屏

mysql>pager tail -5 --设置输出尾部5行

PAGER set to 'tail -5'

mysql>select table_name,table_type,engine from information_schema.tables

| setup_timers | BASE TABLE | PERFORMANCE_SCHEMA |

| threads | BASE TABLE | PERFORMANCE_SCHEMA |

| animals | BASE TABLE | InnoDB |

| shop | BASE TABLE | InnoDB |

+----------------------------------------------+-------------+--------------------+

92 rows in set (0.02 sec)

mysql>pager --查看当前的pager设置

PAGER set to 'tail -5'

mysql>nopager --切换到标准(缺省)pager方式

PAGER set to stdout

--tee命令,输出日志文件

mysql>tee /tmp/query.log--开启输出到文件,相当与SQL*plus下的spool

Logging to file '/tmp/query.log'

mysql>select table_name,table_type,engine from information_schema.tables

+----------------------------------------------+-------------+--------------------+

| table_name | table_type | engine |

+----------------------------------------------+-------------+--------------------+

| CHARACTER_SETS | SYSTEM VIEW | MEMORY |

| COLLATIONS | SYSTEM VIEW | MEMORY |

.............

mysql>notee --关闭输出到文件,相当于SQL*Plus下的spool off

Outfile disabled.

mysql>system tail /tmp/query.log--查看输出的日志文件

| setup_consumers | BASE TABLE | PERFORMANCE_SCHEMA |

| setup_instruments| BASE TABLE | PERFORMANCE_SCHEMA |

| setup_timers | BASE TABLE | PERFORMANCE_SCHEMA |

| threads | BASE TABLE | PERFORMANCE_SCHEMA |

| animals | BASE TABLE | InnoDB |

| shop | BASE TABLE | InnoDB |

+----------------------------------------------+-------------+--------------------+

92 rows in set (0.02 sec)

--改变mysql提示符

mysql>prompt SessionA>

PROMPT set to 'SessionA>'

--恢复到缺省提示符

SessionA>prompt

Returning to default PROMPT of mysql>

--执行sql脚本文件

mysql>system more query.sql --注意,此时为当前目录

use chardb

select * from tb_isam

mysql>source query.sql

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

+------+-------+

| id | value |

+------+-------+

|1 | a |

|2 | b |

|3 | c |

|4 | f |

+------+-------+

4 rows in set (0.00 sec)

--获取状态信息

mysql>status

--------------

mysql Ver 14.14 Distrib 5.5.37, for Linux (x86_64) using readline 5.1

Connection id: 6

Current database: chardb

Current user: root@localhost

SSL:Not in use

Current pager: less

Using outfile: ''

Using delimiter:

Server version: 5.5.37-log MySQL Community Server (GPL)

Protocol version: 10

Connection: Localhost via UNIX socket

Server characterset:latin1

Db characterset:utf8

Client characterset:latin1

Conn. characterset:latin1

UNIX socket:/var/lib/mysql/mysql.sock

Uptime: 3 hours 10 min 59 sec

Threads: 1 Questions: 97 Slow queries: 0 Opens: 313 Flush tables: 1 Open tables: 51 Queries per second avg: 0.008

--------------

--修改客户端字符集

我也被这个问题困扰了,刚才看了flweb的回答得到启发。感谢flweb!

进入命令行即cmd中,进入到安装了mySql的路径下,我的是

C:\Program Files\MySQL\MySQL Server 5.1\bin>

C:\Program Files\MySQL\MySQL Server 5.1\bin>mysql

ERROR 1045 (28000): Access denied for user 'ODBC'@'localhost' (using password: N

O)

直接输入mysql得到错误提示,拒绝访问。因为没有输入密码。由此可以知道默认的用户是ODBC。

C:\Program Files\MySQL\MySQL Server 5.1\bin>mysqlshow

mysqlshow: Access denied for user 'ODBC'@'localhost' (using password: NO)

直接输入mysqlshow得到错误提示,拒绝访问。因为没有输入密码。

C:\Program Files\MySQL\MySQL Server 5.1\bin>mysqlshow -u root -p 123456

Enter password: ******

mysqlshow: Unknown database '123456'

mysqlshow的意思是显示该用户下的数据库,-u 后跟用户,-p表示要输入密码,但其后如果

有东西那么表示的是数据库的名称而不是叫我们输入密码,密码输入执行这条指令后会提示

输入密码。

C:\Program Files\MySQL\MySQL Server 5.1\bin>mysqlshow -u root -p

Enter password: ******

+--------------------+

| Databases |

+--------------------+

| information_schema |

| mysql |

| test |

+--------------------+

上面就达到了我们的目的。

C:\Program Files\MySQL\MySQL Server 5.1\bin>mysqlshow -u root -p test

Enter password: ******

Database: test

+--------+

| Tables |

+--------+

+--------+

这条指令的功能是显示test的数据库的内容。

执行下面这条指令后就可以开始我们的mysql之旅了。

C:\Program Files\MySQL\MySQL Server 5.1\bin>mysql -u root -p

Enter password: ******

Welcome to the MySQL monitor. Commands end with or \g.

Your MySQL connection id is 24

Server version: 5.1.50-community MySQL Community Server (GPL)

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

This software comes with ABSOLUTELY NO WARRANTY. This is free software,

and you are welcome to modify and redistribute it under the GPL v2 license

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

mysql>\h 显示帮助

For information about MySQL products and services, visit:

http://www.mysql.com/

For developer information, including the MySQL Reference Manual, visit:

http://dev.mysql.com/

To buy MySQL Enterprise support, training, or other products, visit:

https://shop.mysql.com/

List of all MySQL commands:

Note that all text commands must be first on line and end with ''

? (\?) Synonym for `help'.

clear (\c) Clear the current input statement.

connect (\r) Reconnect to the server. Optional arguments are db and host.

delimiter (\d) Set statement delimiter.

ego (\G) Send command to mysql server, display result vertically.

exit (\q) Exit mysql. Same as quit.

go(\g) Send command to mysql server.

help (\h) Display this help.

notee (\t) Don't write into outfile.

print (\p) Print current command.

prompt(\R) Change your mysql prompt.

quit (\q) Quit mysql.

rehash(\#) Rebuild completion hash.

source(\.) Execute an SQL script file. Takes a file name as an argument.

status(\s) Get status information from the server.

tee (\T) Set outfile [to_outfile]. Append everything into given outfile.

use (\u) Use another database. Takes database name as argument.

charset (\C) Switch to another charset. Might be needed for processing binlog

with multi-byte charsets.

warnings (\W) Show warnings after every statement.

nowarning (\w) Don't show warnings after every statement.

For server side help, type 'help contents'

mysql>\q 退出mysql

Bye

MySQLMySQL的管理

--安装--linux:yum-yinstallmariadbmariadb-serverORyum-yinstallmysqlmysql-server--windows:http://dev.mysql.com/downloads/mysql/--启动servicemysqldstart--开启chkconfigmysqldon

--设置开机自启ORsystemctlstartmariadbsystemctlenablemariadb

--查看psaux|grepmysqld--查看进程netstat-an|grep3306--查看端口

--设置密码mysqladmin-urootpassword'123'--设置初始密码,初始密码为空因此-p选项没有用mysqladmin-uroot-p123password'1234'--修改root用户密码--登录mysql

-本地登录,默认用户root,空密码,用户为[email protected]本地登录,指定用户名和密码,用户为[email protected]远程登录,用户为[email protected]的常用命令--启动mysql服务与停止mysql服务命令:netstartmysqlnetstopmysql--登陆与退出命令:mysql-h服务器IP-P端口号-u用户名-p密码--mysql-h127.0.0.1-P3306-uroot-p123--配置文件/*my.ini文件:[mysql]default-character-set=gbk[mysqld]character-set-server=gbk*/?

(\?)显示帮助信息clear(\c)明确当前输入语句connect(\r)连接到服务器,可选参数为数据库和主机delimiter(\d)设置语句分隔符ego(\G)发送命令到MySQL服务器,并显示结果exit(\q)退出MySQL等同于quitgo(\g)发送命令到MySQL服务器help(\h)显示帮助信息notee(\t)不写输出文件print(\p)打印当前命令prompt(\R)改变MySQL提示信息quit(\q)退出MySQLrehash(\#)重新完成散列source(\.)执行一个SQL脚本文件,以一个文件名作为参数。status(\s)以服务器获取MySQL的状态tee(\T)设置输出文件,并将信息添加到所有给定的输出文件use(\u)用另一个数据库,数据库名称作为参数charset(\C)切换到另一个字符集warnings(\W)每一个语句之后显示警告nowarning(\w)每一个语句之后不显示警告SQL及其规范SQL(StructuredQueryLanguage结构化查询语言)是一种数据库查询语言和程序设计语言,主要用于管理数据库中的数据,如存取数据、查询数据、更新数据等。SQL是专为数据库而建立的 *** 作命令集,是一种功能齐全的数据库语言。

在使用它时,只需要发出"做什么"的命令,"怎么做"是不用使用者考虑的。SQL功能强大、简单易学、使用方便,已经成为了数据库 *** 作的基础,并且现在几乎所有的数据库均支持SQL。

1>在数据库系统中,SQL语句不区分大小写。但字符串常量区分大小写。建议命令大写,表名库名小写;

2>SQL语句可单行或多行书写,以""结尾。关键词不能跨多行或简写。用空格和缩进来提高语句的可读性。子句通常位于独立行,便于编辑,提高可读性。

SELECT*FROMtb_tableWHERENAME="YUAN"注释:单行注释:--多行注释:/*......*/SQL语句可以折行 *** 作SQL语言由DDL,DML,DQL和DCL组成(1)数据库定义语言(DataDefinitionLanguage,DDL)数据库定义语言主要用于定义数据库、表等,其中包括CREATE语句、ALTER语句和DROP语句。CREATE语句用于创建数据库、数据表等,ALTER语句用于修改表的定义等,DROP语句用于删除数据库、删除表等。

(2)数据库 *** 作语言(DataMabipulationLanguage,DML)数据库 *** 作语言主要用于数据库进行添加、修改、删除 *** 作,其中包括INSERT语句、UPDATE语言和DELETE语句。INSERT语句用于插入数据,UPDATE语句用于修改数据,DELETE语句用于删除数据。

(3)数据库查询语言(DataQueryLanguage,DQL)数据库查询语言主要用于查询语言,也就是指SELECT语句。SELECT语句查询数据库中的一条或多条数据。

(4)数据库控制语言(DataControlLanguage,DCL)数据库控制语言主要用于控制用户的访问权限,其中包括GRANT语句、REVOKE语句、COMMIT语句和ROLLBACK语句。

GRANT语句用于给用户增加权限,REVOKE语句用于收回用户的权限,COMMIT语句用于提交事务,ROLLBACK语句用于回滚


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/8566167.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-18
下一篇 2023-04-18

发表评论

登录后才能评论

评论列表(0条)

保存