MySQL instructions for use-3

Source: Internet
Author: User

3.4 Getting information about Databases and Tables

Get information about a database and a table

What if you forget the database or the name of the table? Or what about the structure of a given table? (For example, do you know what the columns are, what is the name?)

There are several ways MySQL can solve this problem.

As you already know from the previous article, you can see the database by show databases, and the database () function to know the current selection

SELECT DATABASE();



如果你什么数据库也没选择,这条语句执行的结果是Null,如


通过下面的语句,可以查看当前数据库有哪些列表
SHOW TABLES;

Note that it is tables, not tables (), without this function


If you want to see the results of a database, you can use the describe statement, which will show each column of the database
DESCRIBE pet;

Note that it shows information such as structure, data type, etc., and is not the complete information of the table
field shows the name of the column, type is the data type. Null indicates that the column can insert a null value, key indicates whether the column is indexed, default describes its defaults, and finally extra describes the special information. If a column is set to Auto_incrment, its value is automatically incremented
If a column is indexed, you can view the information by show index from Tbl_name.
3.5 Using MySQL in Batch Mode

Use MySQL batch mode.

In the previous section, you enter the statement through the interactive mode of MySQL and view the results. In fact, you can use the batch mode of MySQL.

To do this, you need to write the statement that you want to run to the file, and then tell MySQL to read it and run it.

batch-file
如果你的系统是window,而批处理文件里面包含一些特殊字符,那么,恭喜你,可能会发生一些错误,你可以这样做
batch-file"
如果你需要通过命令行指定连接的参数,那么命令可以是这样的
shell>   mysql-h   host  -u   user  -P <   batch-file     Enter Password:   ********    

If you do, it's best to write a script, Then execute the script.

Span style= "font-size:15px;" > Why write a script?
1. For example, some statements are run once a day or every week, and a script can avoid repeating the wheel over and over again.
2. You can copy from a script that has already been written, and then modify it.
3. Batch mode is also useful when you are developing multiple lines of statements, and if you accidentally make a mistake, you do not have to re-enter it, just modify it correctly, then let MySQL execute it again
4. If your statement executes with a lot of results, you can output a page by page instead of watching it roll over your screen.
batch-file | more

5. You can also export the results to a file for further processing
batch-file > mysql.out
6.你可以将你的脚本展示给你的小伙伴,让它们也可以用它。
7.还有一些情况不能使用交互模式,如果在运行一个计划任务时,这种情况下,你必须使用批处理模式

当然,交互模式与批处理模式输出的结果形式可能有些不同


批处理的如

If you say that I want to use batch mode, but I also want the result of interactive mode, then you should use:mysql-t. If you want to echo the execution result: mysql-v


The following two forms will execute the file
filename;filename

未完待续.....

MySQL instructions for use-3

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.