O'Reilly logo

MySQL in a Nutshell by Russell J.T. Dyer

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Name

mysql

Synopsis

mysql options [database]

You can use the mysql client to interface with MySQL in terminal or console mode. To enter terminal mode, you would enter something like the following from the command line:

mysql -u russell -p

After entering this, if the MySQL server is running the user will be prompted for a password. Once in terminal mode, SQL statements may be entered to view or to change data.

As an alternative to terminal mode, when performing straightforward tasks in MySQL one can still use the mysql client from the command line. For instance, to execute a batch file that contains several SQL statements that will insert data into a database, you could do something like this:

mysql -u russell -ppassword db1 < stuff.sql

In this example, the password is given so that the user isn’t prompted. It’s entered immediately after the -p option, without a space in between. Next the database name db1 is given. The redirect (the less-than sign) tells the shell to input the text file stuff.sql to the command. When the client has finished processing the text file, the user is returned to the command prompt.

Several options may be given when calling the mysql client. They are listed alphabetically here:

--auto-rehash

Generates a hash of table and column names to complete the names for users when typing in terminal mode by pressing the Tab key after having entered the first few letters of the name.

--batch, -B

This default option displays data selected with fields separated by tabs and rows ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required