Notes MySQL command use: Using the database

Source: Internet
Author: User

The Use command allows us to work with the database.

Use command format: Use < database name >;

For example, if the XHKDB database exists, try to access it:
mysql> use XHKDB;
screen tip: Database changed

1) The USE statement can advertise that MySQL uses the Db_name database as the default (current) database for subsequent statements. The database remains as the default database until the end of the segment, or until the next different use statement appears:
mysql> use DB1;
mysql> SELECT COUNT (*) from mytable; # selects from Db1.mytable
mysql> use DB2;
mysql> SELECT COUNT (*) from mytable; # selects from Db2.mytable

2) Using the USE statement to mark a particular current database does not prevent you from accessing tables in other databases. The following example accesses the author table from the DB1 database and accesses the editor table from the DB2 database:
mysql> use DB1;
mysql> SELECT author_name,editor_name from Author,db2.editor
WHERE author.editor_id = db2.editor.editor_id;

The USE statement is set up to be compatible with Sybase.

Some netizens asked, how to quit after the connection. In fact, you do not have to quit, use the database, using show databases can query all the database, if you want to jump to another database, with
Use other database names
you can do it.

Notes MySQL command use: Using the database

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.