This set of MySQL Interview Questions and Answers focuses on “MySQL Setup – 2”.
1. MySQL client runs on the machine containing the databases and servers connect to the client over a network.
Explanation: MySQL operates using a client/server architecture. It is the server that runs on the machine and not the client. The clients connect to the MySQL server to request information from the database(s).
2. The number of attributes in the following table is ______________
CREATE TABLE employee ( emp_name CHAR(30), emp_id INT );
Explanation: The name of the table created is ’employee’. It has two attributes, namely, ’emp_name’ and ’emp_id’. The attributes are the columns in a table. emp_name is of type string and emp_id is of type integer.
3. Which of the following options tells mysql to ask for entering the password?
Explanation: The command ‘mysql -p’ (alternative form: –password) prompts for the password. ‘-h’ (alternative form: –host) specifies the host where the MySQL server is running. ‘-u’ is for specifying the username.
4. What is the host name in the following command?
mysql -h cobra.snake.net -p -u sampadam
Explanation: The ‘-h’ option specifies the hostname of the server. The ‘cobra.snake.net’ is the complete host name. The ‘-p’ option prompts for the account’s password and ‘-u’ specifies the user name.
5. What is ‘tamp’ in the following command?
mysql -h xyz.host.try.net -p -u tamp
a) user name
c) host name
d) table name
Explanation: ‘tamp’ is the name of the user. The user will be prompted for password due to the ‘-p’ option. ‘xyz.host.try’ is the host name here. The entire command specifies the host-user pair and prompts for password to establish the connection.
6. The query ‘SELECT NOW()’ shows the current _____________
b) time only
c) date only
d) date and time
Explanation: SELECT NOW() is an SQL query. It shows both the current date and the current time. It is generally displayed in the format ‘yyyy-mm-dd hh-mm-ss’. For example, 2009-04-21 11-51-36.
7. Suppose you want to select a database named ‘sampledb’ as the default database. Which of the following commands do you use?
a) SELECT DATABASE()
b) SELECT DATABASE sampledb
c) USE DATABASE sampledb
d) USE sampledb
Explanation: ‘USE sampledb’ selects sampledb as the default database. Initially, ‘SELECT DATABASE();’ command displays ‘NULL’, since no database is selected by default. The other two are not valid commands.
8. What does ‘abc’ & ‘xyz’ specify?
CREATE TABLE abc (xyz);
a) table name and column specs
b) column specs and table name
c) table name and number of columns
d) table name and number of rows
Explanation: The ‘CREATE TABLE’ construct’s syntax is ‘CREATE TABLE tbl_name (column_specs)’. ‘tbl_name’ indicates the table name. ‘column_specs’ provides the specifications of the table attributes.
9. To see the table structure, which of the following commands is issued?
a) DESCRIBE tbl_name
b) VIEW tbl_name
c) SELECT TABLE tbl_name
d) SELECT tbl_name
Explanation: The ‘DESCRIBE’ command is issued to see the structure of the table ‘tbl_name’. It shows the structure in the format: Field-Type-Null-Key-Default-Extra. The ‘VIEW’ and ‘SELECT’ commands are used to see the contents of the table.
10. SHOW DATABASES lists the databases in the server to which you are connected.
Explanation: The ‘SHOW DATABASES’ command is used to display the list of the databases that are being managed by the server to which connection is established. This list would vary from server to server.
Sanfoundry Global Education & Learning Series – MySQL Database.
To practice all areas of MySQL for Interviews, here is complete set of 1000+ Multiple Choice Questions and Answers.