MySQL Database Multiple Choice Questions on “Interacting with MySQL”.
1. The command to move the cursor to the beginning of line in MySQL input editor is?
a) Ctrl-A
b) Ctrl-E
c) Ctrl-D
d) Esc-a
Answer: a
Clarification: Control-A moves the cursor to the beginning of the line. Ctrl-E moves the cursor to the end of the line. Control-D deletes the character under the cursor whereas Esc-a is not valid.
2. What does Control-_ do in MySQL input editor?
a) copies to clipboard
b) pastes from clipboard
c) undoes last change
d) deletes the current line
Answer: c
Clarification: Control-_ undoes the last change that was made. This can be repeated. The mysql input editor has a variety of commands to facilitate editing while providing inputs to the command line itself.
3. On UNIX, statements entered in ‘MySQL’ are saved in which file?
a) .mysql_queries
b) .queries
c) .mysql_history
d) .history
Answer: c
Clarification: Statements entered in ‘MySQL’ are stored in the file named ‘.mysql_history’. This file is located in the home directory itself. The SQL statements can be directly pasted into this file.
4. MySQL can be used to execute script files.
a) True
b) False
Answer: a
Clarification: MySQL is capable of reading input from a file in batch mode. This is also known as the non-interactive mode. A lot of typing and time can be saved when commands are stored in a file and executed from a file.
5. Suppose run_me.sh is a script file. Which command is used to make it executable?
a) chmod +e run_me.sh
b) chmod +a run_me.sh
c) chmod +y run_me.sh
d) chmod +x run_me.sh
Answer: d
Clarification: The command ‘chmod +x file_name’ makes a script file executable. mysql supports reading from a script file and executing queries from it. Before a script is run, it is necessary for it to be made executable.
6. To execute the contents of a query file ‘exec.sql’ by feeding it to mysql, which command is used?
a) mysql exec.sql > sampdb
b) mysql sampdb < exec.sql
c) mysql exec.sql
d) mysql exec
Answer: b
Clarification: mysql queries can be run after placing the queries in a file, and then executing it by feeding it to mysql. By default, mysql prints output in a tab-delimited format when it is running in noninteractive mode.
7. Which option prints output in table-format when MySQL is run interactively?
a) -t
b) -tf
c) -p
d) -pf
Answer: a
Clarification: MySQL produces output in tab-delimited format when it is run in batch mode. Suppose a table-format output is desired, the -t option is used along with the mysql command. -tf is not a valid option.
8. The clause that enables mapping a short command to a long command is __________
a) map
b) direct
c) label
d) alias
Answer: d
Clarification: If the shell program permits an alias, a short command can be mapped to a long command. This reduces the time taken by typing long commands frequently. An alias is defined by the keyword ‘alias’ followed by the short and long commands.
9. The connection parameters for setting up MySQL can be stored in an option file to save typing the names every time a connection is established.
a) True
b) False
Answer: a
Clarification: Every Time MySQL is invoked, connection parameters like hostname, username and password are required. To save typing these parameters all the time, they can be saved in an option file instead and executed when setting up the connection.
10. In UNIX, the name of the option file is __________
a) .my.cnf
b) .my.ini
c) .my.opt
d) .my.opc
Answer: a
Clarification: Under Unix, an option file is set up by creating a file named ‘~/.my.cnf’ in the home directory. ‘C:my.ini’ is the option file that is setup in Windows. An option file stores the connection parameters.
