In this case, you need to find which databases are available on your server by using the show databases statement: SHOW DATABASES If the classicmodels database doesn’t exist, you’ll get the following error after executing the USE statement: ERROR 1049 (42000): Unknown database 'classicmodels' Code language: Shell Session ( shell ) To verify it, you can use the select database() statement: SELECT database() Code language: SQL (Structured Query Language) ( sql ) If you see the following message, it means that you have changed the database to classicmodels successfully: Database changed Code language: Shell Session ( shell ) To select a database to work with, you use the USE statement: USE database_name Code language: SQL (Structured Query Language) ( sql )įor example, the following statement uses the USE statement to set the current database to classicmodels: USE classicmodels Code language: SQL (Structured Query Language) ( sql ) For example: SELECT * FROM t Code language: SQL (Structured Query Language) ( sql )Įrror: ERROR 1046 (3D000): No database selected Code language: plaintext ( plaintext ) If you issue a statement, MySQL will issue an error. It means the current database is not set. It’ll return the following: +-+ġ row in set (0.00 sec) Code language: Shell Session ( shell ) To display the current database, you use the following statement: SELECT database() Code language: SQL (Structured Query Language) ( sql ) To log in, you need to provide the correct password of the root user account and press Enter. MySQL will prompt you for a password: Enter password: Code language: Shell Session ( shell ) When you log in to a MySQL database server using the mysql client tool without specifying a database name, MySQL server will set the current database to NULL.įirst, log in to MySQL using the root user account: mysql -u root -p Code language: SQL (Structured Query Language) ( sql ) Selecting a MySQL database using the mysql client tool Summary: in this tutorial, you will learn how to select a database in the mysql program and MySQL Workbench by using the USE statement.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |