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 ...

Get MySQL in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.