mysql
mysqloptions
[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 by carriage returns. It won’t prompt
the user, won’t display error messages to
stdout
, and won’t save to the
history file.
--debug=
filename
, -# filename
Instructs the client to record debugging information to the logfile specified.
--debug-info, -T
Causes the client to display debugging information when finished.
--exec=
'statement'
, -e
'statement'
Executes an SQL statement contained in single or double quotes. The equals sign may be replaced optionally with a space in the long form.
--force, -f
With this option, the client is to continue executing or processing, even if there are SQL errors.
--help, -?
Displays basic help information.
--hostname=
host
, -h
host
Specifies the hostname (e.g., localhost) or Internet Protocol (IP) address of the MySQL server.
--no-auto-rehash, -A
Automatic rehashing is normally used to let the user complete table
and column names when typing in terminal mode by pressing the Tab key
after having entered the first few letters of the name. The
--no-auto-rehash
option will disable this feature
and, thereby, decrease the startup time for the client. This option
is deprecated as of Version 4 of MySQL.
--password=[
password
], -p[
password
]
Provides the password to give to the
MySQL server. No spaces are allowed between the -p
and the password. If a password is not given, the user will be
prompted for one.
--port=
port
, -P
port
Specifies the port to use for connecting to the server. The default is 3306.
--quick, -q
This option has the client retrieve and display data one row at a time rather than buffering the entire results set before displaying data. With this option, the history file isn’t used, and it may slow the server if the output is suspended.
--raw, -r
For data that may contain characters that would normally be converted
in batch mode to an escape-sequence equivalent (e.g., newline to
), you can use this option to have the client
print out the characters without converting them.
--set-variable
var=value
, -o
var=value
Sets a server variable. Enter
mysql --help
for the current values for a
particular server’s variables.
--silent, -s
Reduces the number of messages displayed. Including this several times will further reduce messages.
--socket=
socket
, -S
socket
Provides the path and name of the server’s socket file.
--table, -t
Causes data from a query that is executed to be displayed in ASCII format, which is the format normally used in terminal mode.
--unbuffered, -n
This option has the client flush the memory buffer after each query is performed.
--user=
user
, -u
user
Instructs the client to access MySQL with a user different from the current system user.
--verbose, -v
Displays more information. Use
-vv
or -vvv
to increase
verbosity.
--version, -V
Displays the version of the utility.
--wait, -w
If the client cannot connect to the server, this option tells the client to wait and retry repeatedly until it can connect.
3.136.27.75