MySQL Basics Flashcards

All questions are from https://www.sanfoundry.com/mysql-questions-answers-basic-database-terminology/

1
Q

Which type of database management system is MySQL?

a) Object-oriented
b) Hierarchical
c) Relational
d) Network

A

Answer: c
Explanation: MySQL is a ‘relational’ DBMS. It is efficient at relating data in two different tables and joining information from them. Hierarchical and Network DBMS are based on parent-child relationships of records. Object-oriented DBMS use objects to represent models.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is data in a MySQL database organized into?

a) Objects
b) Tables
c) Networks
d) File systems

A

Answer: b
Explanation: Since MySQL is an RDBMS, it’s data is organised in tables for establishing relationships. A table is a collection of rows and columns, where each row is a record and columns describe the feature of records.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

MySQL is freely available and is open source.

a) True
b) False

A

Answer: a
Explanation: MySQL is free and open source. It’s source code is available for use and is freely downloadable. It includes the MySQL Server, the world’s most popular open source database, and MySQL Cluster, a real-time, open source transactional database.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What represents an ‘attribute’ in a relational database?

a) Table
b) Row
c) Column
d) Object

A

Answer: c
Explanation: Each column in a table represents a feature (attribute) of a record. Table stores the information for an entity whereas a row represents a record. Object has no relevance in an RDBMS.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What represents a ‘tuple’ in a relational database?

a) Table
b) Row
c) Column
d) Object

A

Answer: b
Explanation: Each row in a table represents a record. A tuple is a collection of attribute values that makes a record unique. A tuple is a unique entity whereas attribute values can be duplicate in the table.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How is communication established with MySQL?

a) SQL
b) Network calls
c) A programming language like C++
d) APIs

A

Answer: a
Explanation: SQL is the standard language for RDBMS systems like MySQL. SQL queries facilitate quick information retrieval from tables and other elementary operations required to maintain an RDBMS system.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What does ‘name’ represent in the following SQL code snippet?

   CREATE TABLE student
   (
       name CHAR(30),
       roll_num INT,
       address CHAR(30),
       phone CHAR(12)
   );

a) A table
b) A row
c) A column
d) An object

A

Answer: c
Explanation: ‘name’, ‘roll_num’, ‘address’ and ‘phone’ are the attributes in the table ‘student’. The CREATE TABLE construct in SQL creates a table, assigns a name to it and its attributes, and specifies the type of fields used in the table.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Which is the MySQL instance responsible for data processing?

a) MySQL client
b) MySQL server
c) SQL
d) Server daemon program

A

Answer: b
Explanation: MySQL uses client-server architecture. The MySQL server program runs on the machine where databases are stored. SQL is a query language used for querying the tables and information retrieval.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

The MySQL server used in its client/server architecture is _______________

a) mysqla
b) mysqlb
c) mysqlc
d) mysqld

A

Answer: d
Explanation: mysqld is the MySQL server program. It serves the incoming client requests by accessing the database. The others are not valid MySQL programs. MySQL implements a client/server architecture wherein mysqld is the server program.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

In MySQL databases, the structure representing the organizational views of the entire databases is ____________

a) Schema
b) View
c) Instance
d) Table

A
Answer: a
Explanation: The schema in a database gives a blueprint of the structure. A view is an object that can be generated with a query. A table is a collection of records. An instance is analogous to a class object.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Which of the following clauses is used to display information that match a given pattern?

a) LIKE
b) WHERE
c) IS
d) SAME

A

Answer: a
Explanation: The ‘LIKE’ clause filters information that match a given pattern. ‘WHERE’ clause selects information that is specified by a condition. ‘IS’ is used to match the exact condition specified.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What column names are displayed when this SQL command is executed?

SHOW COLUMNS FROM tbl_name LIKE ‘%name’;

a) suffixed with ‘name’
b) prefixed with ‘name’
c) suffixed with ‘%name’
d) prefixed with ‘%name’

A

Answer: a
Explanation: The wildcard ‘%’ is used to indicate that any number of characters can replace it. All column names that end in ‘name’ are displayed. Additional information of columns like type and size are listed.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

MySQL server can operate in different SQL modes, depending on the value of the sql_mode system variable. Which mode changes syntax and behavior to conform more closely to standard SQL?

a) TRADITIONAL
b) ANSI
c) MSSQL
d) STRICT

A

Answer: b

ANSI - This mode changes syntax and behavior to conform more closely to standard SQL.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

If you were building a table schema to store student grades as a letter (A, B, C, D, or F) which column type would be the best choice?

a) ENUM
b) OTEXT
c) VARCHAR
d) LONGTEXT

A

Answer: a

An ENUM is a string object with a value chosen from a list of permitted values that are enumerated explicitly in the column specification at table creation time.

example
CREATE TABLE shirts (
    name VARCHAR(40),
    size ENUM('x-small', 'small', 'medium', 'large', 'x-large')
);
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Which option of most MySQL command-line programs can be used to get a description of the program’s different options?

a) –options
b) ?
c) –help
d) -h

A

Answer: c
–help Display help message and exit

there is no shortcut key

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

MySQL uses environment variables in some of the programs and command-line operations. Which variable is used by the shell to find MySQL programs?

a) DIR
b) HOME
c) PATH
d) MYSQL_HOME

A

Answer: c
PATH Used by the shell to find MySQL programs.

There is no env variable used by MySQL called DIR. HOME The default path for the mysql history file is $HOME/.mysql_history. MYSQL_HOME The path to the directory in which the server-specific my.cnf file resides.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

You must ensure the accuracy and reliability of the data in your database. You assign some constraints to limit the type of data that can go into a table. What type of constraints are you assigning?

a) row level
b) database level
c) column level
d) function level

A

Answer: c

Constraints can be column level or table level. Column level constraints apply to a column, and table level constraints apply to the whole table.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

You need to export the entire database, including the database objects, in addition to the data. Which command-line tool do you use?

a) mysqlexport
b) mysqladmin
c) mysqldump
d) mysqld

A

Answer: c

The mysqldump client utility performs logical backups, producing a set of SQL statements that can be executed to reproduce the original database object definitions and table data. It dumps one or more MySQL databases for backup or transfer to another SQL server. The mysqldump command can also generate output in CSV, other delimited text, or XML format.

mysqlexport - no such program
mysqladmin is a client for performing administrative operations. You can use it to check the server’s configuration and current status, to create and drop databases, and more. mysqladmin [options]
mysqld - the database server executable

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

When you have a subquery inside of the main query, which query is executed first?

a) The subquery is never executed. Only the main query is executed.
b) They are executed at the same time
c) the main query
d) the subquery

A

Answer: d

The subquery is called an Inner query and the main query is called the outer query. The inner query is executed first and then the main query gets executed. In case you have multiple subqueries then the innermost query gets executed first.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

MySQL uses security based on___for all connections, queries, and other operations that users can attempt to perform.

a) administrator schema
b) encrypted algorithms
c) user settings
d) access control lists

A

Answer: d

MySQL uses security based on Access Control Lists (ACLs) for all connections, queries, and other operations that users can attempt to perform. There is also support for SSL-encrypted connections between MySQL clients and servers.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

Which of the following is NOT the correct usage of a comment in a SQL statement for MySQL?
a) SELECT /* Author: jsai
Purpose: select contacts / contact_id, last_name, first_name
FROM contacts;
b) SELECT contact_id, last_name, first_name # jsai
FROM contacts;
c) SELECT contact_id, last_name, first_name /
jsai
FROM contacts;
d) SELECT contact_id, last_name, first_name – jsai
FROM contacts;

A
Answer: c 
using # symbol is:
# comment goes here
using -- symbol is:
-- comment goes here
using /* and */ symbols is:
/* comment goes here */
This is a correct example of a comment spanning multiple lines
SELECT contact_id, last_name, first_name
/*
 * Author: TechOnTheNet.com
 * Purpose: To show a comment that spans multiple lines in your SQL
 * statement in MySQL.
 */
FROM contacts;
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

Which of the following is NOT a string function

a) repeat
b) mid
c) reverse
d) truncate

A

Answer : d

The MySQL TRUNCATE function returns a number truncated to a certain number of decimal places.

The MySQL REPEAT function repeats a string a specified number of times. REPEAT( string, number )

The MySQL REVERSE function returns a string with the characters in reverse order. REVERSE( string )

The MySQL MID function allows you to extract a substring from a string. MID( string, start_position, length )

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

Assuming that we have a table called contacts in MySQL that is populated with the following data:

contact_id last_name website1 website2
1 Johnson techonthenet.com
2 Anderson
3 Smith TBD TBD
4 Jackson math.com minecraft.com

SELECT *
FROM contacts
WHERE website1 <=>website2;

what happens when we query using the following above query:

a) only row 3 is returned
b) all rows are returned
c) no rows are returned
d) rows 2 and 3 are returned

A

Answer : d

our query returns all rows from the contacts table where website1 is equal to website2, including those records where website1 and website2 are NULL values.

Because the = operator only compares non-NULL values, it is not safe to use with NULL values. To overcome this limitation, MySQL added the <=> operator to allow you to test for equality with both NULL and non-NULL values.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

Assuming that we have a table called contacts in MySQL that is populated with the following data:

contact_id last_name website1 website2
1 Johnson techonthenet.com
2 Anderson
3 Smith TBD TBD
4 Jackson math.com minecraft.com

SELECT *
FROM contacts
WHERE last_name <> ‘Johnson’;

what happens when we query using the following above query:

a) the SELECT statement would return all rows from the contacts table where the last_name is not equal to Johnson.
b) the SELECT statement would return all rows from the contacts table where the last_name is equal to Johnson.
c) the SELECT statement would return all rows from the contacts table where the last_name is equal to Johnson and any any rows with NULL
d) an error would occur

A

Answer: a

In MySQL, you can use the <> or != operators to test for inequality in a query.

the SELECT statement would return all rows from the contacts table where the last_name is not equal to Johnson.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Q

Which of the following statements will fail?

a) SELECT depart, MAX(salary) AS highest
FROM employees
GROUP BY department;

b) SELECT depart, MAX(salary) AS highest salary
FROM employees
GROUP BY department;

c) SELECT department, MAX(salary) “highest salary”
FROM employees
GROUP BY department;

d) SELECT department, MAX(salary) AS “highest”
FROM employees
GROUP BY department;

A

Answer: b
aliases are used to make the column headings in your result set easier to read.

if the alias_name did not include any spaces, we are not required to enclose the alias_name in quotes. However, it would have been perfectly acceptable to add quotes even if no spaces.

Since there are spaces in this alias_name, “highest salary” must be enclosed in quotes.

the AS keyword is optional, Most programmers will specify the AS keyword when aliasing a column name, but not when aliasing a table name. Whether you specify the AS keyword or not has no impact on the alias in MySQL.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
26
Q

The following command was entered in mysql shell

CREATE USER IF NOT EXISTS ‘test’@’localhost’ IDENTIFIED BY ‘Password’ PASSWORD EXPIRE INTERVAL 90 DAY;
Query OK, 0 rows affected, 1 warning (0.00 sec)

Which of the following can be used to troubleshoot why the command failed?

a) show error;
b) show error();
c) show warning;
d) show warning();

A

Answer : c

SHOW WARNINGS [LIMIT [offset,] row_count]

you have to run it immediately after a query that had warnings attached to it.

show warning(); is incorrect syntax

SHOW ERRORS, shows only error conditions (it excludes warnings and notes),

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
27
Q

The LOCAL capability for LOAD DATA does not need to be enabled explicitly.

a) True
b) False

A

Answer: a
Explanation: The ‘LOCAL’ capability for the ‘LOAD DATA’ statement does not need to be enabled explicitly. It can be controlled at build time and at runtime. This can be achieved in two ways.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
28
Q

The LOCAL capability for client library or LOAD DATA is enabled by ______________

a) –enabled-local-file
b) –enable-local-infile
c) –enable-global-file
d) –enable-local-file

A

Answer: b
Explanation: At build time LOCAL capability for the client library or LOAD DATA can be enabled or disabled by default. The ‘–enable-local-infile’ or ‘–disable-local-infile’ option is used when running configure.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
29
Q

What is the most important configurable resource for MyISAM?

a) key cache
b) memory cache
c) time cache
d) speed cache

A

Answer: a
Explanation: For the index processing, ‘MyISAM’ manages its own key cache, which is the most important configurable resource for the MyISAM storage engine. It is used for index based retrievals and sorts.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
30
Q

How many options can be used to control LOCAL capability at runtime?

a) 0
b) 1
c) 2
d) 3

A

Answer: c
Explanation: At runtime, the server can be started with the ‘–local-infile’ or ‘–skip-local-infile’ options to enable or disable ‘LOCAL’ capability on the server side. It can be enabled at build time too.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
31
Q

‘x’ in the following MySQL statement is ____________

DELETE FROM x USING x LEFT JOIN y ON x.col = y.col;

a) column name
b) table name
c) server name
d) database name

A

Answer: b
Explanation: The ‘DELETE’ operation is being performed in the statement. The table names are ‘x’ and ‘y’. The column name is ‘col’. The rows from left join of x and y get deleted according to the condition given.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
32
Q

The mode used to turn off the special meaning of backslash and treat it as an ordinary character is _____________

a) NO_ESCAPES_SLASH
b) NO_ESCAPES_BACKSLASH
c) NO_BACKSLASH_ESCAPES
d) NO_BACKSLASH_ESCAPE

A

Answer: c
Explanation: To turn off the special meaning of backslash in MySQL, and treat it as an ordinary character, the SQL mode named NO_BACKSLASH_ESCAPES is enabled. The escape sequence is treated as characters.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
33
Q

What is the synonym for CHARACTER SET?

a) CSET
b) CHSET
c) CHARSET
d) CHCSET

A

Answer: c
Explanation: ‘CHARACTER SET’ can be abbreviated into ‘CHARSET’ and can be used in the same contexts and statements where ‘CHARACTER SET’ is used. ‘charset’ is the server-supported character set.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
34
Q

The option that executes all SQL statements in a SQL script irrespective of the number of errors is ______________

a) –ensure
b) –force
c) –violent
d) –run

A

Answer: b
Explanation: If SQL queries in a file are run using mysql in batch mode, mysql either quits after the first error. If the –force option is specified all the queries are executed indiscriminately.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
35
Q

Which keyword is the synonym for DATABASE?

a) TABLE
b) OBJECT
c) DB
d) SCHEMA

A

Answer: d
Explanation: In any statement where the word ‘DATABASE’ occurs, the keyword ‘SCHEMA’ can be used as a synonym in place of it. In the literal sense, SCHEMA refers to the structure of the database.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
36
Q

It is not required to have an access privilege for a database before selecting it with ‘USE’.

a) True
b) False

A

Answer: b
Explanation: In order to select a database as the default database for the MySQL server using the ‘USE’ statement, some access privilege for the database needs to be granted or attained.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
37
Q

The file created by the server to store the database attributes is __________

a) db.otp
b) dp.zip
c) db.opt
d) db.cls

A

Answer: c
Explanation: Whenever a database is created in MySQL, the MySQL server creates a directory with the same name as the database. It creates the file db.opt to store the attributes.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
38
Q

Which of the following is the correct way to run a os command from the mysql shell?

a) system ls -l
b) ! ls -l
c) both of the above
d) neither of the above

A

Answer: c

the command system or ! can be used to run os command from database command line.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
39
Q

What is the maximum collations a character set can have?

a) 0
b) 1
c) 2
d) more than 1

A

Answer: d
Explanation: The MySQL server allows simultaneous use of multiple character sets. A given character set is allowed to have one or more collations. It can be chosen according to the need of the database.

40
Q

Unicode support is provided in MySQL.

a) True
b) False

A

Answer: a
Explanation: In MySQL, Unicode character set support is provided by the utf8 and ucs2 character sets. There are further additional character sets available as of MySQL version 6.0.4.

41
Q

Which clause can be used to sort string values according to a specific collation?

a) SORT
b) GROUP
c) FILTER
d) COLLATE

A

Answer: d
Explanation: The ‘COLLATE’ operator can be used to sort the string values according to a specific collation. For example, ‘SELECT col FROM tbl ORDER BY col COLLATE latin1_swedish_ci’ sorts by swedish collation.

42
Q

Which MySQL statement is used to find out which character sets are available?

a) SHOW CHARACTER SET
b) SHOW COLLATION
c) SHOW CHARACTER SETS
d) SHOW COLLATIONS

A

Answer: a
Explanation: It is simple to determine the character sets and collations that are available in MySQL. ‘SHOW CHARACTER SET’ shows the character sets while ‘SHOW COLLATION’ shows the collations.

43
Q

Which collations does this MySQL statement list?

SHOW COLLATION LIKE 'utf8%'

a) names beginning with utf8
b) names ending with utf8
c) names containing utf8% anywhere
d) names ending in utf8%

A

nswer: a
Explanation: The character set ‘utf8’ is used for the Unicode character set 8. The ‘LIKE’ keyword does the job of narrowing the search space to refer to only those names that begin with ‘utf8’.

44
Q

Which statement is used to show the server’s current character set and collation settings?

a) SHOW CONSTANTS
b) SHOW CONSTRAINTS
c) SHOW VARIABLES
d) DISP VARIABLES

A

Answer: c
Explanation: The statement ‘SHOW VARIABLES LIKE ‘character_set_%” displays a table consisting of two columns, ‘Variable_name’ and ‘Value’. Replacing characer_set_% with collation_% shows the collation variables.

45
Q

What does UTF stand for int utf8?

a) Universal Transformation Format
b) Unicode Transformation Format
c) Universal Transformation Formula
d) Unicode Transformation Formula

A

Answer: b
Explanation: In the utf8 character set in MySQL, the characters are represented in one, two or three bytes. ‘UTF’ stands for ‘Unicode Transformation Format’. Unicode support prior to MySQL 6.0 was different.

46
Q

To check if the data directory contains insecure files or directories, the command executed is _____________

a) ls -l
b) ls -a
c) ls -la
d) ls -lu

A

Answer: c
Explanation: It can be determined whether the data directory contains insecure files or directories by executing ‘ls -la’. Then the lookup for files or directories that have the “group” or “other” permissions turned on.

47
Q

What enables the read and execute access to all users outside of mysql group.

a) drwxrwxr-x
b) drwxrwxr-y
c) drwyrwyr-x
d) drwyrwyr-y

A

Answer: a
Explanation: Some database directories have the proper permissions like ‘drwx——‘ enables read, write, and execute access to the owner, but no access to anyone else. Other directories have an overly permissive access mode like ‘drwxrwxr-x’.

48
Q

The server uses a Unix domain socket file for connections by clients to localhost.

a) True
b) False

A

Answer: a
Explanation: The server uses a Unix domain socket file for connections by clients to localhost. The socket file normally is publicly accessible so that client programs can use it again properly.

49
Q

Which program is used as a utility for MyISAM table maintenance?

a) innochecksum
b) myisam_ftdump
c) myisamchk
d) myisamlog

A

Answer: c
Explanation: The program ‘myisamchk’ is a utility for the table maintenance. ‘innochecksum’ is used for offline InnoDB file checksum utility. To display full text index information ‘myisam_ftdump’ is used.

50
Q

What does the AUTO_INCREMENT sequences normally begin at?

a) 0
b) -1
c) 1
d) 2

A

Answer: c
Explanation: The AUTO_INCREMENT column attribute provides unique numbers for column identification. AUTO_INCREMENT sequences normally begin at 1 and increase monotonically like 1, 2, 3, and so on.

51
Q

How can the value of recently generated sequence number be obtained?

a) LAST_INSERT_ID()
b) LATEST_INSERT_ID()
c) INITIAL_INSERT_ID()
d) INSERT_ID()

A

Answer: a
Explanation: The value of most recently generated sequence number can be obtained by calling the LAST_INSERT_ID() function. This enables to reference the AUTO_INCREMENT value in the subsequent statement.

52
Q

Triggers are not supported for _____________

a) delete
b) update
c) insert
d) views

A

Answer: d
Explanation: In MySQL, the triggers are run only after the table modifications like insert, update and delete are run. Triggers are not supported for views. In order to create a trigger, the CREATE TRIGGER statement is used.

53
Q

Triggers and events are not invoked automatically by the server.

a) True
b) False

A

Answer: b
Explanation: The triggers and events are invoked automatically by the server, so the concept of invoking user is not applied. Thus, they have no SQL SECURITY characteristic and always execute with definer privileges.

54
Q

How is a stored procedure invoked?

a) INVOKE
b) SEE
c) CALL
d) RETURN

A

Answer: c
Explanation: In MySQL, a stored procedure is invoked using the CALL statement. A stored procedure does not have a return value but can modify its parameters. It also returns some result sets.

55
Q

How is a stored procedure invoked?

a) CALL
b) INVOKE
c) SEE
d) RETURN

A

Answer: a
Explanation: In MySQL, a stored procedure is invoked using the CALL statement. A stored procedure does not have a return value but can modify its parameters. It also returns some result sets.

56
Q

In inner join, result is produced by matching rows in one table with rows in another table.

a) True
b) False

A

Answer: a
Explanation: The inner join is a form of join in MySQL that is used to combine the result of concatenating the contents of two tables into a new table. In inner join, result is produced by matching rows in one table with rows in another table.

57
Q

The join where all possible row combinations are produced is called _________

a) INNER JOIN
b) OUTER
c) NATURAL
d) CARTESIAN

A

Answer: d
Explanation: In ‘cartesian product’, each row of each table is combined with each row in every other table to produce all possible combination. This produces a very large number of rows since the number is the product of rows.

58
Q

The clause that filters JOIN results is called _________

a) WHERE
b) SORT
c) GROUP
d) GROUP BY

A

Answer: a
Explanation: Sometimes the result of a join is very large and is not desirable. In these cases, the results can be filtered with the help of the ‘WHERE’ clause which is followed by a set of condition(s).

59
Q

What is joining a table to itself called?

a) COMPLETE
b) SELF
c) OBSOLETE
d) CROSS

A

Answer: b
Explanation: Joining a table to itself in a database is called ‘self-join’. When a self-join is being performed, the table is being used multiple times within the query and a table name qualifier is unnecessary.

60
Q

In which join will all the rows from the left table appear in the output irrespective of the content of the other table?

a) RIGHT JOIN
b) LEFT JOIN
c) INNER JOIN
d) OUTER JOIN

A

Answer: b
Explanation: In a ‘LEFT JOIN’, the output is produced for every row of the left table, even if it does not exist in the right table. This is the reason it is called a ‘LEFT JOIN’. ‘LEFT JOIN’ is a kind of OUTER JOIN.

61
Q

The join in which all the rows from the right table appear in the output irrespective of the content of the other table is ___________

a) CARTESIAN JOIN
b) CROSS JOIN
c) INNER JOIN
d) RIGHT JOIN

A

Answer: d
Explanation: In a ‘RIGHT JOIN’, the output is produced for every row of the right table, even if it does not exist in the other table. This is the reason why it is called a ‘RIGHT JOIN’. ‘RIGHT JOIN’ and ‘LEFT JOIN’ are a kind of OUTER JOIN.

62
Q

. CROSS JOIN and JOIN are similar to __________

a) INNER JOIN
b) NATURAL JOIN
c) OUTER JOIN
d) CARTESIAN JOIN

A

Answer: a
Explanation: The joins ‘CROSS JOIN’ and ‘JOIN’ types are exactly similar to the ‘INNER JOIN’. The statements containing ‘INNER JOIN’ can replace it with ‘CROSS JOIN’ or ‘JOIN’ to get exactly the same result.

63
Q

The left and right joins are also known as __________

a) INNER JOIN
b) NATURAL JOIN
c) OUTER JOIN
d) CARTESIAN JOIN

A

Answer: c
Explanation: The ‘inner join’ only deals with rows where a match can be found in both tables. The ‘LEFT JOIN’ and ‘RIGHT JOIN’ types are ‘OUTER JOIN’ types which differ from inner joins in this sense.

64
Q

Which one of the following addresses MySQL authentication?
a) GRANT ALL PRIVILEGES ON . TO ‘database_user’@’localhost’;
b) GRANT USAGE ON . TO ‘database_user’@’localhost’ ;
C) SET PASSWORD FOR ‘database_user’@’localhost’ = PASSWORD(‘NewPass’);
d) ALTER USER ‘database_user’@’localhost’ WITH MAX_CONNECTION = 100;

A

Answer: c
Authentication: Verifies the user’s identity. This is the first stage of access control.
You must successfully authenticate each time you connect.
If you fail to authenticate, your connection fails and your client disconnects.

creating a user and setting a password are examples of authentication.

The most common way to change an existing account’s password without changing any of its privileges is to use the SET PASSWORD statement.

GRANT options refer to authorization.

Authorization: Verifies the user’s privileges.

65
Q

The root user performed the following when creating the user account u1.

CREATE USER ‘u1’@’localhost’ IDENTIFIED BY ‘password’;
GRANT SELECT, INSERT, UPDATE ON . TO u1;
REVOKE INSERT, UPDATE ON db1.* FROM u1;

What is The result of the preceding statements?

a) an error occurs during log in to the mysql instance
b) an error occurs during creating of the statements above
c) SELECT applies globally to all tables, INSERT and UPDATE are not allowed globally
d) SELECT applies globally to all tables, whereas INSERT and UPDATE apply globally except to tables in db1. Account access to db1 is read only.

A

Answer: b

Because user u1 is defined for ‘localhost’ you must include that in the statement

mysql> GRANT SELECT, INSERT, UPDATE ON . TO u1;
ERROR 1410 (42000): You are not allowed to create a user with GRANT
mysql> REVOKE INSERT, UPDATE ON db1.* FROM u1;
ERROR 1141 (42000): There is no such grant defined for user ‘u1’ on host ‘%’
mysql> GRANT SELECT, INSERT, UPDATE ON . TO ‘u1’;
ERROR 1410 (42000): You are not allowed to create a user with GRANT
mysql> GRANT SELECT, INSERT, UPDATE ON . TO ‘u1’@’localhost’;
Query OK, 0 rows affected (0.00 sec)

66
Q

The root user performance the following when creating the user account u1.

CREATE USER u3;
GRANT SELECT, INSERT, UPDATE ON . TO u3;
GRANT DELETE ON . TO u3;
REVOKE INSERT, UPDATE ON . FROM u3;

What is The result of the preceding statements?

a) an error occurs during log in to the mysql instance
b) an error occurs during creating of the statements above
c) SELECT applies globally to all tables, INSERT and UPDATE are not allowed globally
d) DELETE applies globally to all tables, whereas SELECT, INSERT and UPDATE are not allowed globally

A

Answer: c

the user is created fine, it is not mandatory to create the password. When the user logs in they will be prompted to enter the password, in which case they just hit enter and they can log in without a password for authentication.

The user was granted select,insert, update and delete globally.

Only insert and update were globally revoked.

mysql> update sample01 set s_desc = null where s_name = 'p005';
ERROR 1142 (42000): UPDATE command denied to user 'u3'@'localhost' for table 'sample01'

mysql> delete from sample01 where s_name = ‘p005’;
Query OK, 1 row affected (0.01 sec)

67
Q

What is the default date format used by MySQL?

a) ‘DD-MON-YYYY’
b) ‘DD/MON/YYYY’
c) ‘MM/DD/YYYY’
d) ‘YYYY-MM-DD’

A

Answer: D
MySQL retrieves and displays DATE values in ‘YYYY-MM-DD’ format.

mysql> select curdate();
\+------------+
| curdate()  |
\+------------+
| 2021-07-10 |
\+------------+
1 row in set (0.00 sec)
68
Q

Create a table named cities, with a column named name, and a PRIMARY KEY named gps_coordinates

a) CREATE TABLE cities(
name VARCHAR(100) NOT NULL,
gps_coordinates INT NOT NULL PRIMARY KEY
);

b) CREATE TABLE cities(
name VARCHAR(100) NOT NULL,
gps_coordinates PRIMARY KEY
);

c) CREATE TABLE cities(
name VARCHAR(100) NOT NULL,
gps_coordinates NOT NULL PRIMARY KEY
);

d) CREATE TABLE cities(
name VARCHAR(100) NOT NULL,
PRIMARY KEY (gps_coordinates INT NOT NULL )
);

A

Answer: a

the gps_coordinates needs to have the data type defined, where b and c fail to define
a datatype

69
Q

Which of the following is the mysql server status varible for:
The number of connections that were aborted because the client died without closing the connection properly.

a) Aborted_connects
b) Aborted_client_connects
c) Aborted
d) Aborted_clients

A

answer: d

Aborted_clients

The number of connections that were aborted because the client died without closing the connection properly.

Aborted_connects

The number of failed attempts to connect to the MySQL server.

Aborted_client_connects and aborted do not exist

70
Q

What does CRUD stand for?

A

c REATING
r EADING
u PDATING
d ELETING

71
Q

Delete from x where id = 1;

What type of mysql SQL command is this?

a) DML
b) DDL
c) DCL
d) DQL
e) TCL

A

Answer: a

DDL – Data Definition Language
DQl – Data Query Language
DML – Data Manipulation Language
DCL – Data Control Language

The DELETE Statement in SQL is used to delete existing records from a table. We can delete a single record or multiple records depending on the condition we specify in the WHERE clause. It is referred to as a manipulation of data.

Truncate reinitializes the identity by making changes in data definition therefore it is DDL, whereas Delete only delete the records from the table and doesn’t make any changes in its Definition

72
Q

TRUNCATE TABLE table_name;

What type of mysql SQL command is this?

a) DML
b) DDL
c) DCL
d) DQL
e) TCL

A

Answer: b

DDL – Data Definition Language
DQl – Data Query Language
DML – Data Manipulation Language
DCL – Data Control Language

TRUNCATE statement is a Data Definition Language (DDL) operation that is used to mark the extents of a table for deallocation (empty for reuse). The result of this operation quickly removes all data from a table, typically bypassing a number of integrity enforcing mechanisms.

Truncate reinitializes the identity by making changes in data definition therefore it is DDL, whereas Delete only delete the records from the table and doesn’t make any changes in its Definition

73
Q

If you want your MySQL database to reject invalid data values during inserts , which sql mode would you need to set?

a) sql_mode=ANSI
b) sql_mode=STRICT_MODE
c) sql_mode=STRICT_ALL_TABLES
d) sql_mode=REJECT_CHECK

A

Answer: c

STRICT_ALL_TABLES

Enable strict SQL mode for all storage engines. Invalid data values are rejected. For details, see Strict SQL Mode.

ANSI
This is a composite mode that causes MySQL Server to be more “ANSI-like.” That is, it enables behaviors that are more like standard SQL, such as ANSI_QUOTES (described earlier) and PIPES_AS_CONCAT, which causes || to be treated as the string concatenation operator rather than as logical

74
Q

Which of the following is a mysql Client Program?

a) mysqladmin
b) mysqlslap
c) mysql
d) all of the above
e) none of the above

A

Answer: d

mysqlslap — A Load Emulation Client
mysql — The MySQL Command-Line Client
mysqladmin — A MySQL Server Administration Program

75
Q

Which of the following are statement termintors in MYSQL, by default?

a) ;
b) \g
c) \G
d) a and c
e) a, b and c

A

Answer: e

You may use any of several terminators to end a statement. Two terminators are the semicolon character (‘;’) and the \g sequence. They’re equivalent and may be used interchangeably

The \G sequence also terminates queries, but causes mysql to display query results in a vertical style that shows each output row with each column value on a separate line

mysql> SELECT VERSION(), DATABASE();
\+-----------+------------+
| VERSION() | DATABASE() |
\+-----------+------------+
| 8.0.25    | db1        |
\+-----------+------------+
1 row in set (0.00 sec)
mysql> SELECT VERSION(), DATABASE() \g
\+-----------+------------+
| VERSION() | DATABASE() |
\+-----------+------------+
| 8.0.25    | db1        |
\+-----------+------------+
1 row in set (0.00 sec)
mysql> SELECT VERSION(), DATABASE() \G
*************************** 1. row ***************************
 VERSION(): 8.0.25
DATABASE(): db1
1 row in set (0.00 sec)
76
Q

Which MySQL client program client can be used to quickly see which databases exist, their tables, or a table’s columns or indexes?

a) mysqladmin
b) mysqlslap
c) mysqlshow
d) mysql
e) none of the above

A

Answer: c

The mysqlshow client can be used to quickly see which databases exist, their tables, or a table’s columns or indexes.

mysqlshow provides a command-line interface to several SQL SHOW statements. The same information can be obtained by using those statements directly. For example, you can issue them from the mysql client program.

77
Q

Which is the correct syntax to have auto generated bencemark queries run in mysqlslap and will handle table and queries.

a) /usr/bin/mysqlslap –user=root -p –auto-generate-sql;
b) /usr/bin/mysqlslap –user=root -p
c) /usr/bin/mysqlslap –user=root -p -a;
d) all of the above
e) both a and c

A

Answer: e

–auto-generate-sql, -a

Generate SQL statements automatically when they are not supplied in files or using command options.

78
Q

Which of the following is false about running queries in the MySQL client program?

a) can run queries automatically by a job scheduler without user intervention
b) enables you to send queries to the MySQL server and receive their results
c) Batch mode is useful for running queries that have been prewritten
d) Interactive mode is useful for quick one-time queries
e) restore MyISAM tables that have become corrupt

A

Answer : e

When used interactively, mysql prompts you for a statement, sends it to the MySQL server for execution, and displays the results. mysql also can be used noninteractively in batch mode to read statements stored in files or produced by programs. This enables use of mysql from within scripts or cron jobs, or in conjunction with other applications.

79
Q

You can install just a standalone MySQL client shell on Windows 10?

a) TRUE
B) FALSE

A

Answer: a

Installing MySQL Shell on Microsoft Windows:

To install MySQL Shell on Microsoft Windows using the MSI Installer, do the following:

Download the Windows (x86, 64-bit), MSI Installer package from http://dev.mysql.com/downloads/shell/.

When prompted, click Run.

Follow the steps in the Setup Wizard.

80
Q

You issue the following command on the os prompt in linux, what happens?

mysqladmin -u root -p processlist status version

a) error occurs, need to run in mysql shell
b) no error occurs and the results are all the running processes, the current status and version
b) no error occurs and the result is the current version only
d) error occurs, you cannot run multiple commands together

A

Answer: B
If you would like to execute multiple ‘mysqladmin‘ commands together, then the command would be like this.

mysqladmin -u root -p processlist status version

81
Q

You are on server lin01 where the MySQL master is running, you want to start up the MySQL slave instance on server lin02. Which command will allow this?

a) mysqladmin -u root -p start-slave
b) mysqladmin -u root -s start-slave
c) mysql -u root start-slave
d) you cannot start the slave from another server

A

Answer: a

To start/stop MySQL replication on slave server, use the following commands.

mysqladmin -u root -p start-slave

82
Q

What does the following command do:

mysqladmin -u root -p debug

a) prints out debug and errors to the screen when you log in
b) errors out when run
c) tells the server to write debug information about locks in use, used memory and query usage to the MySQL log file
d) tells the server to write debug information about locks in use, used memory and query usage to the screen

A

Answer: c

mysqladmin -u root -p debug

It tells the server to write debug information about locks in use, used memory and query usage to the MySQL log file including information about event scheduler.

83
Q

Which of the following allows you to perform some basic administrative functions on the MySQL server?

a) mysqladmin
b) mysqlshow
c) mysqladmin
d) mysqlconsole

A

Answer: a

MySQLAdmin is a command-line utility for MySQL Server that is installed when installing the MySQL package.

The MySQLAdmin client allows you to perform some basic administrative functions on the MySQL server.

It is used to create a database, drop a database, set a root password, change the root password, check MySQL status, verify MySQL functionality, monitor mysql processes, and verify the configuration of the server.

84
Q

The MySQLAdmin status command displays useful summary information about the MySQL server.

mysqladmin -u root -pPassword status

Which of the following will it not allow?

a) Slow queries: The number of queries that have taken more than long_query_time seconds
b) Users: listing of the users
c) Opens: The number of tables the server has opened.
d) Open tables: The number of tables that currently are open.
e) all of the above

A

Answer : b

The MySQLAdmin status command displays useful summary information about the MySQL server.

Uptime: How long the MySQL server has been running, it shows in seconds.
Threads: The number of active clients connection
Questions: The number of queries has been executed since the server was started.
Slow queries: The number of queries that have taken more than long_query_time seconds.
Opens: The number of tables the server has opened.
Flush tables: How many times flush-*, refresh, and reload commands the server has executed.
Open tables: The number of tables that currently are open.

85
Q

What does the mysql program interpret the first nonoption argument to be?

a) global variable
b) input file
c) output file
d) database

A

Answer : d

the mysql program interprets the first nonoption argument as a database name, so the
command mysql –user=root test indicates that you want to use the test database.

86
Q

All MySQL client programs understand which options?

a) –socket (or -S)
b) –user (or -u)
c) –password (or -p)
d) b and c
e) all of the above

A

Answer: d
The most frequently used of these are the –host
(or -h), –user (or -u), and –password (or -p) options that specify connection parameters. They
indicate the host where the MySQL server is running, and the user name and password of your MySQL
account. All MySQL client programs understand these options; they enable you to specify which server to
connect to and the account to use on that server.

87
Q

Which of the following is FALSE?

a) Options are processed in order, so if an option is specified multiple times, the first occurrence takes
precedence.
b) the first instance of the –user option is used
c) environment variables have the highest precedence and
command-line options the lowest.
d) all of these are TRUE

A

Answer: c

Options are processed in order, so if an option is specified multiple times, the last occurrence takes
precedence.

The following command causes mysql to connect to the server running on localhost:
mysql -h example.com -h localhost

There is one exception: For mysqld, the first instance of the –user option is used as a security
precaution, to prevent a user specified in an option file from being overridden on the command line.
If conflicting or related options are given, later options take precedence over earlier options.

environment variables have the lowest precedence and
command-line options the highest.

88
Q

Which Oracle product is not certified to work with MySQL Enterprise Edition?

a. Oracle Enterprise Manager
b. Oracle GoldenGate
c. Oracle Database Vault
d. PeopleSoft

A

Answer: D

MySQL
Enterprise Edition makes managing MySQL easier in these environments
by certifying and supporting the use of the MySQL Database in conjunction
with many Oracle products. These include:
• Oracle Linux
• Oracle VM
• Oracle Fusion Middleware
• Oracle Secure Backup
• Oracle Golden Gate
• Oracle Database Audit Vault and Database Firewall
• Oracle Enterprise Manager
• Oracle OpenStack for Oracle Linux
• Oracle Clusterware

89
Q

What are three backup capabilities provided by MySQL Enterprise Backup?

a) Compressed backups
b) Cold backups
c) Encryption for single-file backups
d) Backup only required tables

A

Answer: A, C and D

MySQL Enterprise Backup delivers:

“Hot” Online Backups - Backups take place entirely online, without interrupting MySQL transactions

Incremental Backup - Backup only data that has changed since the last backup

Partial Backup - Target particular tables or tablespaces

Full Instance Backup - Backs up data, as well as configuration and other information to easily create a complete “replica”

Point-in-Time Recovery (PITR) - Recover to a specific transaction

Online “Hot” Selective Restore - bring back only selected tables into a running database

Direct Cloud Storage Backup via S3 and Swift APIs - Backup and Restore directly to/from Oracle Storage Cloud, S3 and other Cloud Storage using AWS S3 API

Advanced LZ4 Compression - Support highly efficient, low impact and ultra fast LZ4 compression, as well as LZMA and zlib

AES 256 encryption - Built in 256-bit Advanced Encryption Standard (AES) encryption to secure all the sensitive backup data

NEW! Supports MySQL TDE - Enables secure archival quality backup and restore of TDE encrypted database files and keys

Streaming “Zero storage” Single Step Backup and Restore - Run a full or partial backup from one server and a restore to another in one streamed step without staged storage

Backup Validation - Provides assurance checks to confirm backup integrity and quality by confirming that internal pages are valid and file checksums match.

Exclude Tables - Exclude unnecessary tables from your Backups, saving backup time and space

Binlog and Relay log backup - Simplifies cloning source to replica servers for HA replication

Include Tables - Backup only required tables for better granularity and usability.

Continuous Monitoring - Monitor the progress and disk space usage

Selective Backup/Restore - An efficient and transportable method to backup InnoDB tables using Transportable Tablespaces

Table renaming on restore of Transportable Tablespace (TTS) backups

Compression - Cut costs by reducing storage requirements up to 90%

Backup to Tape - Stream backup to tape or other media management solutions

Multi-platform - Backup and Restore on Linux, Windows, Mac & Solaris

90
Q

After installing MySQL Enterprise Edition on Linux, where can you find the default data directory?

a. ) /usr
b. ) /usr/bin
c. ) /etc/my.cnf
d. ) /var/lib/mysql
e. ) /usr/mysql

A

Answer: d

After MySQL is installed, the data directory must be initialized, including the tables in the mysql system database.

the default data directory id /var/lib/mysql

91
Q

Three update statements have been executed within one transaction. The transaction is still uncommitted when the connection between the server and the client issuing the commands is closed. What will happen with the transaction?

A. All changes are committed
B. All changes are rolled back
C. If the connection was closed normally at the client’s request, the changes are committed. If the connection closed abnormally, the changes are rolled back.
D. The changes are neither committed nor rolled back. The entire session states, including the pending changes are saved separately by the server and the session is restored when the client reconnects.

A

Answer : B

The entire operation should be wrapped in a transaction so that if any one of the steps fails, any completed steps can be rolled back.

You start a transaction with the START TRANSACTION statement and then either make its changes permanent with COMMIT or discard the changes with ROLLBACK. So, the SQL for our sample transaction might look like this:

1 START TRANSACTION;
2 UPDATE checking SET balance = balance - 200.00 WHERE customer_id = 10233276;
3 UPDATE savings SET balance = balance + 200.00 WHERE customer_id = 10233276;
4 Update checking_savings_summary set balance = balance + 200.00 WHERE customer_id = 10233276;
5 COMMIT;

If the client connection is dropped/lost after step 4 but before step 5 then all updates are rolled back

Transactions aren’t enough unless the system passes the ACID test. ACID stands for Atomicity, Consistency, Isolation, and Durability.

92
Q

Which security feature helps to prevent unplanned queries from being executed, such as from SQL injection attacks?

A. Enterprise Auditing of activity and halting execution to injected queries
B. Applying authorization rules to prevent queries based on their WHERE clause manipulation is present C. Enterprise External authentication as it will ensure application user accounts can’t access certain rows of data
D. Enterprise Transparent Data Encryption, protecting data from being viewed through queries for a given database user
E. Enterprise Firewall filtering for pre-defined whitelist queries

A

Answer: E

Enterprise Firewall filtering for pre-defined whitelist queries helps prevent sql injection attacks

One such effective approach to managing and reducing the risks associated with SQL-injection attacks is to introduce a query sanitizer at the database level which sorts out all good SQL (and let it run) from the bad SQL (which is rejected). This concept is referred to as an SQL firewall.

93
Q

Which two of the following features does the MySQL Enterprise Monitor not provide

A. Monitoring of MySQL Enterprise Backup jobs
B. Baselining of MySQL configuration settings
C. Profiling of Queries, highlighting the poor performers
D. Alerting of events that are capable of being passed to Enterprise notification systems
E. Automated SR generated on the Oracle Support portal based on advisor setups.

A

Answer: B and E

94
Q

Objective Monitoring MySQL with Performance Schema

Consider the events_% tables in Performance Schema.
Which three methods will clear or reset the collected events in the tables?

A. using DELETE statements
(for example, DELETE FROM performance_schema.events_waits_current)
B. using the RESET PERFORMANCE CACHE statement
C. using the FLUSH PERFORMANCE CACHE statement
D. using TRUNCATE statements
(for example, TRUNCATE TABLE performance_schema.events_waits_current)
E. disabling and re-enabling all instruments
F. restarting MySQL
G. using the ps_truncate_all_tables() procedure in the sys schema

A

Answer: E,G , D

mysql> RESET PERFORMANCE CACHE;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘PERFORMANCE CACHE’ at line 1
mysql> RESET PERFORMANCE CACHE;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘PERFORMANCE CACHE’ at line 1
mysql> DELETE FROM performance_schema.events_waits_current;
ERROR 1142 (42000): DELETE command denied to user ‘root’@’localhost’ for table ‘events_waits_current’
mysql>

The ps_truncate_all_tables() Procedure
Truncates all Performance Schema summary tables, resetting all aggregated instrumentation as a snapshot. Produces a result set indicating how many tables were truncated.
95
Q

Consider the events_% tables in performance Schema.
Which two methods will clear or reset the collected events in the tables?
A. Using DELETE statements, for example, DELETE FROM performance_schema.events_waits_current;
B. Using the statement RESET PERFORMANCE CACHE;
C. Using the statement FLUSH PERFORMANCE CACHE;
D. Using TRUNCATE statements, for example, TRUNCATE TABLE performance_schema.events_waits_current;
E. Disabling and re-enabling all instruments
F. Restarting Mysql

A

Answer: D , E

D: To avoid unpredictable results if you make timer changes, use TRUNCATE TABLE to reset Performance Schema statistics.
Example:
As with other aggregate tables within Performance Schema, you can reset the statistics within the digest table with:
TRUNCATE TABLE performance_schema.events_statements_summary_by_digest;

https://dev.mysql.com/doc/refman/8.0/en/performance-schema-timing.html

96
Q

MySQL is installed on a Linux server and has the following configuration:

[mysqld]

User=mysql

Datadir=/data/mysql

As the ‘root’ user, change the datadir location by executing:

Shell> cp –R /var/lib/mysql/data/mysql/

Shell> chown –R mysql /data/mysql/

What is the purpose of changing ownership of datadir to the ‘mysql’ user?

A. MySQL cannot be run as the root user.

B. MySQL requires correct file ownership while remaining secure.

C. MySQL needs to be run as the root user, but file cannot be owned by it.

D. The mysqld process requires all permissions within datadir to be the same.

A

Answer: B

97
Q

Which three are characteristics of a newly created role? (Choose three.) *

A. It can be dropped using the DROP ROLE statement
B. It is stored in the mysql.role table.
C. It is created as a locked account
D. It can be renamed using the RENAME ROLE statement
E. It can be granted to user accounts.
F. It can be protected with a password.

A
Answer:  A, C,E
A role can be created
A role can be dropped
A role when created is locked, has no password, and is assigned the default authentication plugin. 
A role can be granted privilege's
A role can be assigned to a user
A role can be assigned to another role

This is no such thing as the mysql.role table
It cannot be protected with a password
A role cannot be renamed using RENAME role