Mysql Dba Qa
Mysql Dba Qa
----------------------------------------------
BIGINT NOT NULL PRIMARY KEY AUTO_INCREMENT
==============================================
2. What are HEAP tables in MySQL? How do you control the max size of a HEAP table?
-----------------------------------------------------------------------------------
HEAP tables are in-memory. They are usually used for high-speed temporary storage.
No TEXT or BLOB fields are allowed within HEAP tables. You can only use the
comparison operators = and <=>. HEAP tables do not support AUTO_INCREMENT. Indexes
must be NOT NULL.
MySQL config variable max_heap_table_size.
===================================================================================
6. What happens when the column is set to AUTO INCREMENT and you reach the maximum
value for that table?
-----------------------------------------------------------------------------------
----------------------
It stops incrementing. It does not overflow to 0 to prevent data losses, but
further inserts are going to produce an error, since the key has been used already.
===================================================================================
=====================
8. What are the 3 primary backup mechanisms available to the DBA? List down the
(logical) steps to perform each of them.
-----------------------------------------------------------------------------------
-------------------------------------
Cold backups involve shutdown down the database server (mysqld) and then backing up
all the data files by making a copy of them to another directory. To be really
thorough, the entire datadir including binlogs, log files, /etc/my.cnf config file
should also be backed up. The cold backup is a database in itself, and can be
copied to an alternate server and mounted as-is.
Logical backups involve using the mysqldump tool. This locks tables while it runs
to maintain consistency of changing data, and can cause downtime. The resulting
dump file contains CREATE DATABASE, CREATE TABLE & CREATE INDEX statements to
rebuild the database. Note the file itself is not a database, but rather a set of
instructions which can tell a MySQL server *HOW* to reconstruct the database.
Important distinction here.
Hot backups are a great addition to the mix as they allow the physical database
data files to be backed up *WHILE* the server is up and running. In MySQL this can
be achieved with the xtrabackup tool, available from Percona. Despite the name, it
works very well with MyISAM and InnoDB tables too, so don’t worry if you’re not
using xtradb tables.
There are a few different restore scenarios, and the candidate should be able to
describe how these various backups can be restored, and what the steps to do so
would be. In addition they should understand what point-in-time recovery is, and
how to perform that as well. After restoring one of the above three backup types,
the DBA would use the mysqlbinlog utility to apply any subsequent transactions from
the binary logs. So if the backup was made at 2am last night, and you restore that
backup, the mysqlbinlog tool would be used to dig up transactions since 2am, and
apply them to that restored database.
===================================================================================
=======================================
9. What are inner joins and outer joins? In a credit card company, let us say you
have 2 tables: one containing cardholders identity, their number, address, and
other personal info. A second table contains their account activity. How would you
go about retrieving a monthly statement from the given data (you may assume the
existence of certain fields that store info pertaining to the activities of the
user in the account activity table).
-----------------------------------------------------------------------------------
----------------------------------------
An OUTER JOIN on those two tables will yield a record, with a null for the
statements columns.
===================================================================================
========================================
Master-master replication is similar, except one additional step. After the above
steps have run, you know that your application is not pointing at the slave
database. If you’re not sure, verify that fact first. Now determine the logfile
name & position on the slave with SHOW MASTER STATUS. Return to the primary box,
and run the CHANGE MASTER TO command to make it slave from the secondary box.
You’ve essentially asked MySQL to create a circular loop of replication.
How does MySQL avoid getting into an infinite loop in this scenario? The server_id
variable must be set, and be unique for all MySQL instances in your replication
topology.
=================================================================
12. How might you hack a MySQL server (given that you have gained shell access to
the host running the mysql server)?
-----------------------------------------------------------------------------------
----------------------------------
First of all you will need to ensure that your database is stopped:
Now you should start up the database in the background, via the mysqld_safe
command:
root@steve:~# /usr/bin/mysqld_safe --skip-grant-tables &
[1] 6702
Starting mysqld daemon with databases from /var/lib/mysql
mysqld_safe[6763]: started
Here you can see the new job (number "1") has started and the server is running
with the process ID (PID) of 6702.
Now that the server is running with the --skip-grant-tables flag you can connect to
it without a password and complete the job:
mysql> exit
Bye
Now that you've done that you just need to stop the server, so that you can go back
to running a secure MySQL server with password restrictions in place. First of all
bring the server you started into the foreground by typing "fg", then kill it by
pressing "Ctrl+c" afterwards.
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> exit
Bye
If you'd like to automate this process you could start by looking at this simple
shell script which will allow you to reset a password with one command.