Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
118 views

Mysql Dba Qa

1. SERIAL data type in MySQL defines a BIGINT NOT NULL PRIMARY KEY AUTO_INCREMENT column for automatically generating unique integers. 2. HEAP tables are in-memory tables for high-speed temporary storage that do not allow TEXT/BLOB fields or AUTO_INCREMENT and require indexes to be NOT NULL. The max_heap_table_size variable controls their maximum size. 3. InnoDB has advantages over MyISAM like row-level locking, transactions, foreign keys, and crash recovery while MyISAM has advantages like more conservative disk usage and no limitations on data size.

Uploaded by

navin_net
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
118 views

Mysql Dba Qa

1. SERIAL data type in MySQL defines a BIGINT NOT NULL PRIMARY KEY AUTO_INCREMENT column for automatically generating unique integers. 2. HEAP tables are in-memory tables for high-speed temporary storage that do not allow TEXT/BLOB fields or AUTO_INCREMENT and require indexes to be NOT NULL. The max_heap_table_size variable controls their maximum size. 3. InnoDB has advantages over MyISAM like row-level locking, transactions, foreign keys, and crash recovery while MyISAM has advantages like more conservative disk usage and no limitations on data size.

Uploaded by

navin_net
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 4

1. What is SERIAL data type in MySQL?

----------------------------------------------
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.
===================================================================================

3. Explain advantages of InnoDB over MyISAM?


---------------------------------------------
Row-level locking, transactions, foreign key constraints and crash recovery.
=============================================

4. Explain advantages of MyISAM over InnoDB?


--------------------------------------------
Much more conservative approach to disk space management - each MyISAM table is
stored in a separate file, which could be compressed then with myisamchk if needed.
With InnoDB the tables are stored in tablespace, and not much further optimization
is possible. All data except for TEXT and BLOB can occupy 8,000 bytes at most. No
full text indexing is available for InnoDB. TRhe COUNT(*)s execute slower than in
MyISAM due to tablespace complexity.
============================================

5. Explain the difference between MyISAM Static and MyISAM Dynamic.


-------------------------------------------------------------------
In MyISAM static all the fields have fixed width. The Dynamic MyISAM table would
include fields such as TEXT, BLOB, etc. to accommodate the data types with various
lengths. MyISAM Static would be easier to restore in case of corruption, since even
though you might lose some data, you know exactly where to look for the beginning
of the next record.
===================================================================

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.
===================================================================================
=====================

7. What are federated tables?


------------------------------
Introduced in MySQL 5.0, federated tables allow access to the tables located on
other databases on other servers.
==============================

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.
===================================================================================
========================================

10. What is mirroring (in the context of disk I/O).


----------------------------------------------------
Mirroring combines two disks as a unit. Every write is duplicated on both disks.
If you lose one disk, you have an immediate copy. Like a tandem truck that has
spare tires running in parallel. Lose one, and you don’t have to pull over
immediately to replace it.
====================================================

11. How would you setup master/slave & master/master replication?


-----------------------------------------------------------------
A basic replication setup involves creating a full dump of the primary database,
while it’s tables are locked. The DBA should capture the master status, logfile &
position at that time. She should then copy the dump file to the secondary machine
& import the full dump. Finally the CHANGE MASTER TO statement should be run to
point this database instance to it’s master. Lastly START SLAVE should be issued.
If all goes well SHOW SLAVE STATUS should show YES for both of these status
variables:
Slave_IO_Running: Yes
Slave_SQL_Running: Yes

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:

root@steve:~# /etc/init.d/mysql stop

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:

root@steve:~$ mysql --user=root mysql


Enter password:

mysql> update user set Password=PASSWORD('new-password-here') WHERE User='root';


Query OK, 2 rows affected (0.04 sec)
Rows matched: 2 Changed: 2 Warnings: 0

mysql> flush privileges;


Query OK, 0 rows affected (0.02 sec)

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.

This will now allow you to start the server:

root@steve:~# /etc/init.d/mysql start


Starting MySQL database server: mysqld.
Checking for corrupt, not cleanly closed and upgrade needing tables..
Now everything should be done and you should have regained access to your MySQL
database(s); you should verify this by connecting with your new password:
root@steve:~# mysql --user=root --pass=new-password-here
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 5 to server version: 5.0.24a-Debian_4-log

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.

You might also like