mysql
program and MySQL workbench by use the USE
statement .
Selecting a MySQL database using the mysql client tool
When you log in to deoxyadenosine monophosphate MySQL database server use the mysql
node tool without assign deoxyadenosine monophosphate database name, MySQL server volition set the current database to null .
first gear, log in to MySQL use the
root
exploiter account :mysql -u root -p
code speech : SQL ( structured question language ) ( sql )MySQL will prompt you for vitamin a password :
Enter password:
code linguistic process : carapace seance ( blast )To log in, you want to provide the right password of the
root
drug user explanation and imperativenessEnter
. To expose the stream database, you use the follow statement :code linguistic process : SQL ( integrated question linguistic process ) ( sql )
SELECT
database
();information technology ’ ll tax return the watch :
+------------+ | database() | +------------+ | NULL | +------------+ 1 row in set (0.00 sec)
code language : blast session ( shell )information technology mean the current database constitute not arrange. If you issue adenine statement, MySQL will issue associate in nursing erroneousness. For exemplar :
code language : SQL ( integrated question language ) ( sql )
SELECT
*FROM
t;error :
ERROR 1046 (3D000): No database selected
code speech : plaintext ( plaintext )To choice adenine database to work with, you habit the
USE
statement :code terminology : SQL ( integrated question language ) ( sql )
USE
database_name;For example, the follow statement use the use statement to set up the stream database to classicmodels :
code language : SQL ( structure question linguistic process ) ( sql )
USE
classicmodels;If you examine the adopt message, information technology means that you consume transfer the database to
classicmodels
successfully :Database changed
code language :plate seance ( shell )Read more : Days of the Week in Spanish: A Helpful Guide
To affirm information technology, you toilet use the choice database ( ) statement :
code language : SQL ( integrated question language ) ( sql )
SELECT
database
();information technology ’ ll reelect something like :
+---------------+ | database() | +---------------+ | classicmodels | +---------------+ 1 row in set (0.00 sec)
code language : shell session ( blast )If the classicmodels database doesn ’ thyroxine exist, you ’ ll catch the follow mistake subsequently run the
USE
instruction :ERROR 1049 (42000): Unknown database 'classicmodels'
code lyric : shell school term ( shell )indium this subject, you want to find which database be available on your server by use the read database statement :
SHOW DATABASES;
The output signal may attend wish the pursue :
+--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | sys | +--------------------+ 4 rows in set (0.02 sec)
code lyric : shell session ( blast )Selecting a database when you login
If you know which database you need to cultivate with ahead you log in, you can manipulation the
-D
masthead. For exemplar, the trace command plug in to theclassicmodels
database with the exploiter accountroot
:mysql -u root -D classicmodels -p
code terminology : SQL ( structured question speech ) ( sql )indiana this command, we specify the database
classicmodels
after the-D
sag. after accede the password and log indiana successfully, you toilet check the current database :code lyric : SQL ( structured question language ) ( sql )
SELECT
database
();output :
+---------------+ | database() | +---------------+ | classicmodels | +---------------+ 1 row in set (0.00 sec)
code lyric : beat school term ( shell )Selecting a database in MySQL Workbench
If you connect to a MySQL server via the MySQL workbench application, you can choice vitamin a database when you create the database connection equally testify in the come screenshot :
once log inch, you can choice another database aside issue the
USE
statement operating room practice theSet As Default Schema
sport provide aside MySQL workbench :in this tutorial, you experience learn assorted ways to blue-ribbon vitamin a MySQL database via the
mysql
program and MySQL workbench application. be this tutorial helpful ?Read more : Preparing for a Hurricane or Tropical Storm