A Brief Introduction to MySQL By Nishkam, Neeraj,Saurabh, Hrishikesh  and Somesh
Pointers <ul><li>What is MySQL ? Its good features. </li></ul><ul><li>Installation guide. </li></ul><ul><li>Security and P...
What Is MySQL? <ul><li>A fast, reliable, easy-to-use, multi-user multi-threaded relational database system. </li></ul><ul>...
Why Use MySQL ?  <ul><li>MySQL server can handle very large databases. </li></ul><ul><li>Offers rich and very useful set o...
What Does MySQL Offer ? <ul><li>A privilege and password system that is very flexible and secure and allows host-based ver...
Quick Installation Guide <ul><li>tar –zxvf Mysql.x.xx.xx.tar.gz </li></ul><ul><li>cd  Mysql-x.xx.xx.xx </li></ul><ul><li>....
Configuring MySql <ul><li>--bindir=Dir specifies dir for binaries </li></ul><ul><li>--localstatedir=Dir data dir  </li></u...
Support  <ul><li>Works on many different platforms like FreeBSD , NetBSD , Linux 2.0+, Windows ’95, ’98, 2000 & NT, HP-UX ...
Security in mysql <ul><li>Issues that bother: eavesdropping,altering </li></ul><ul><li>Uses ACL’s (Access Control Lists) ,...
Privileges provided by mysql <ul><li>The five tables: user,db,host,tables_priv,columns_priv </li></ul><ul><li>The privileg...
How the privilege system works <ul><li>First reference to user followed by db and host , takes place during connection ver...
Some tips on security <ul><li>Beneficial to invest in a firewall ; check using “telnet server_port 3306” </li></ul><ul><li...
Continued….. <ul><li>Following mysqld options affect security:   1. –- secure  2. – skip-grant-privileges    3. – skip-nam...
Compatibility with Standards <ul><li>What doesn’t MySQL have ? </li></ul><ul><li>Transactions – no provision for commit an...
Compatibility (contd.) <ul><li>What extra does MySQL have ? </li></ul><ul><li>Locking/Unlocking of tables  </li></ul><ul><...
More about Locks ! <ul><li>Locks help in maintaining integrity, atomicity </li></ul><ul><li>Read locks – enable you to onl...
MySql  Table  Types <ul><li>Creates a .frm file that holds the table and column definition. </li></ul><ul><li>Syntax  for ...
MyISAM tables <ul><li>Use B-Tree indexing to store the keys, string indexes are compressed . </li></ul><ul><li>MyISAM itse...
Merge tables <ul><li>A collection of identical MyISAM tables which are used collectively.  </li></ul><ul><li>FOR eg : </li...
Heap tables and Berkley DB <ul><li>Use hashed index and are stored in memory </li></ul><ul><li>Generally used for temporar...
MySQL Language Reference <ul><li>OPTIMIZE </li></ul><ul><li>Syntax :: …  OPTIMIZE TABLE tbl_name[,tbl_name].. </li></ul><u...
MySQL Language Reference <ul><li>Checks a table for errors and updates the key statistics  of the table </li></ul><ul><li>...
MySQL Language Reference <ul><li>REPAIR </li></ul><ul><li>Syntax:  </li></ul><ul><li>REPAIR TABLE tbl_name[,tbl_name...] [...
Replication in MySQL <ul><li>What?? </li></ul><ul><li>One server is designated as the master, while the other ( or others)...
How To (SLAVE) <ul><li>Upgrade both slave and master to 3.23.15 or higher.  </li></ul><ul><li>PUT THESE IN my.cnf of SLAVE...
How To (SLAVE) (contd) <ul><li>Take a snapshot of all the tables/databases on the  master   </li></ul><ul><li>Use command ...
HOW TO (MASTER) <ul><li>log-bin , FLUSH MASTER , FLUSH SLAVE </li></ul><ul><li>When  you  start the slave thread will be c...
Upcoming SlideShare
Loading in...5
×

Mysql2

660

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
660
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
12
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Mysql2

  1. 1. A Brief Introduction to MySQL By Nishkam, Neeraj,Saurabh, Hrishikesh and Somesh
  2. 2. Pointers <ul><li>What is MySQL ? Its good features. </li></ul><ul><li>Installation guide. </li></ul><ul><li>Security and Privilege System </li></ul><ul><li>Compatibility with standards </li></ul><ul><li>Locks – an interesting feature </li></ul><ul><li>Table types </li></ul><ul><li>Some more salient features </li></ul><ul><li>Replication </li></ul>
  3. 3. What Is MySQL? <ul><li>A fast, reliable, easy-to-use, multi-user multi-threaded relational database system. </li></ul><ul><li>It is freely available and released under GPL (GNU General Public License ). </li></ul>
  4. 4. Why Use MySQL ? <ul><li>MySQL server can handle very large databases. </li></ul><ul><li>Offers rich and very useful set of functions. </li></ul><ul><li>Connectivity, speed and security make MySQL very suited for accessing database on a network. </li></ul><ul><li>A lot of contributed software available. </li></ul>
  5. 5. What Does MySQL Offer ? <ul><li>A privilege and password system that is very flexible and secure and allows host-based verification. </li></ul><ul><li>Multi-threaded request-handling using kernel thread. </li></ul><ul><li>Replication features. </li></ul><ul><li>Very actively developed. </li></ul><ul><li>Memory leak proof. </li></ul>
  6. 6. Quick Installation Guide <ul><li>tar –zxvf Mysql.x.xx.xx.tar.gz </li></ul><ul><li>cd Mysql-x.xx.xx.xx </li></ul><ul><li>./configure –prefix=/usr/local/mysql </li></ul><ul><li>make </li></ul><ul><li>make install </li></ul><ul><li>scripts/mysql_install_db </li></ul><ul><li>safe_mysqld </li></ul><ul><li>Mysql –u root password ‘mypassword’ </li></ul>
  7. 7. Configuring MySql <ul><li>--bindir=Dir specifies dir for binaries </li></ul><ul><li>--localstatedir=Dir data dir </li></ul><ul><li>--with-tcp-port=portno </li></ul><ul><li>--with-unix-sock-path=absolute-path </li></ul><ul><li>--with-mysqld-ldflag=-all-static </li></ul><ul><li>--with-charset=charset (default Latin1) </li></ul><ul><li>--with-low-memory </li></ul>
  8. 8. Support <ul><li>Works on many different platforms like FreeBSD , NetBSD , Linux 2.0+, Windows ’95, ’98, 2000 & NT, HP-UX etc </li></ul><ul><li>There are client tools and APIs available in c, c++, java, perl, python, php, Tcl </li></ul>
  9. 9. Security in mysql <ul><li>Issues that bother: eavesdropping,altering </li></ul><ul><li>Uses ACL’s (Access Control Lists) , also there’s some support for SSL connections </li></ul><ul><li>Has inbuilt methods for storing confidential data like passwords in encrypted form. </li></ul><ul><li>Access is restricted thru grant of privileges to users,hosts </li></ul>
  10. 10. Privileges provided by mysql <ul><li>The five tables: user,db,host,tables_priv,columns_priv </li></ul><ul><li>The privileges come into play only if there is a retrieval of data from the database, or updation of data in the database,e.g: select 1+1; calculator  </li></ul><ul><li>File privilege : load data infile, select …. Into outfile </li></ul>
  11. 11. How the privilege system works <ul><li>First reference to user followed by db and host , takes place during connection verification </li></ul><ul><li>Reference to tables_priv and columns_priv at data access stage </li></ul><ul><li>Ordering of user table on the basis of more specific host values first, followed by more specific user values. </li></ul><ul><li>For security purposes , mysql disallows host </li></ul><ul><li>addresses of the form :192.168.7.yahoo.com </li></ul>
  12. 12. Some tips on security <ul><li>Beneficial to invest in a firewall ; check using “telnet server_port 3306” </li></ul><ul><li>Do not rely on the data entered by the user, he can trick the code by using special character sequences </li></ul><ul><li>Make use of tcpdump, to check the whether or not mysql data streams r unencrypted: </li></ul><ul><li>tcpdump –l –i eth0 –w – src port 3306|strings </li></ul><ul><li>Dont run mysqld as root. </li></ul><ul><li>Don’t give process and file privileges to users as far as possible. </li></ul>
  13. 13. Continued….. <ul><li>Following mysqld options affect security: 1. –- secure 2. – skip-grant-privileges 3. – skip-name-resolve 4. –skip-networking </li></ul><ul><li>Passwords by default are stored in hashed form in database.But if the scrambled password is known the hacker can still log in as the user. </li></ul><ul><li>Passwords can be stored in my.cnf file when non-interactive access has to be done </li></ul><ul><li>Inbuilt functions for hashing: password, encrypt,encode,decode </li></ul>
  14. 14. Compatibility with Standards <ul><li>What doesn’t MySQL have ? </li></ul><ul><li>Transactions – no provision for commit and rollback </li></ul><ul><li>No nested sub-queries </li></ul><ul><li>Views are not supported </li></ul><ul><li>Foreign keys not used for referential integrity checks </li></ul>
  15. 15. Compatibility (contd.) <ul><li>What extra does MySQL have ? </li></ul><ul><li>Locking/Unlocking of tables </li></ul><ul><li>Atomicity of operations </li></ul><ul><li>Directory organization </li></ul><ul><li>Access of tables across tables </li></ul><ul><li>Several other features, discussed later… </li></ul>
  16. 16. More about Locks ! <ul><li>Locks help in maintaining integrity, atomicity </li></ul><ul><li>Read locks – enable you to only read from the locked tables. </li></ul><ul><li>Write locks – enable you to read and write exclusively. Other threads can’t access/update currently locked tables </li></ul><ul><li>Write locks have higher priority than read locks </li></ul>
  17. 17. MySql Table Types <ul><li>Creates a .frm file that holds the table and column definition. </li></ul><ul><li>Syntax for defining table type is .. : CREATE TABLE test ( ) TYPE=HEAP .. </li></ul><ul><li>Categorization of types : Transaction safe type and Non transaction safe type. </li></ul><ul><li>Transaction Safe table types allow rollbacks,restore changes if update fails ,etc . </li></ul><ul><li>Non Transaction Safe table types are much faster ,use less disk space as well as memory for updates. </li></ul>
  18. 18. MyISAM tables <ul><li>Use B-Tree indexing to store the keys, string indexes are compressed . </li></ul><ul><li>MyISAM itself supports three different table formats: a) static (fixed length) b) Dynamic c) Compressed </li></ul><ul><li>Static : fastest ,secure and simplest format , used when there are no varchar, blob or text. </li></ul><ul><li>Dynamic : each record stores a header that contain its length </li></ul><ul><li>Compressed : created using myisampack tool , they are read only ,use very little space as each record is compressed separately </li></ul><ul><li>ISAM is a deprecated version of MyISAM </li></ul>
  19. 19. Merge tables <ul><li>A collection of identical MyISAM tables which are used collectively. </li></ul><ul><li>FOR eg : </li></ul><ul><li>CREATE TABLE t1 (a INT AUTO_INCREMENT PRIMARY KEY, message CHAR(20)); </li></ul><ul><li>CREATE TABLE t2 (a INT AUTO_INCREMENT PRIMARY KEY, message CHAR(20)) ; </li></ul><ul><li>CREATE TABLE total (a INT NOT NULL, message CHAR(20), KEY(a)) TYPE=MERGE UNION=(t1,t2) </li></ul><ul><li>allowed : select ,insert and Operations update . </li></ul>
  20. 20. Heap tables and Berkley DB <ul><li>Use hashed index and are stored in memory </li></ul><ul><li>Generally used for temporary tables . </li></ul><ul><li>Berkley DB is used for making the tables transaction safe </li></ul>
  21. 21. MySQL Language Reference <ul><li>OPTIMIZE </li></ul><ul><li>Syntax :: … OPTIMIZE TABLE tbl_name[,tbl_name].. </li></ul><ul><li>Used only for MyISAM tables </li></ul><ul><li>It performs the following functions :repairs the table if the table has deleted rows,sorts the index,and the statistics are also made to date. </li></ul><ul><li>CHECK </li></ul><ul><li>Syntax :: … CHECK TABLE tbl_name[,tbl_name...] [TYPE = [QUICK | FAST | EXTEND | CHANGED]] </li></ul>
  22. 22. MySQL Language Reference <ul><li>Checks a table for errors and updates the key statistics of the table </li></ul><ul><li>BACKUP </li></ul><ul><li>BACKUP TABLE tbl_name[,tbl_name...] TO '/path/to/backup/directory‘ </li></ul><ul><li>This again works only for MyISAM </li></ul><ul><li>ANALYZE </li></ul><ul><li>During analysis the table is locked with a read lock </li></ul>
  23. 23. MySQL Language Reference <ul><li>REPAIR </li></ul><ul><li>Syntax: </li></ul><ul><li>REPAIR TABLE tbl_name[,tbl_name...] [TYPE = QUICK] </li></ul><ul><li>FLUSH </li></ul><ul><li>Syntax : </li></ul><ul><li>FLUSH flush_option [,flush_option] </li></ul><ul><li>Used to clear the internal cache of Mysql </li></ul><ul><li>It has various options like HOSTS,LOGS,PRIVELEDGES, TABLES tbl_names,etc </li></ul>
  24. 24. Replication in MySQL <ul><li>What?? </li></ul><ul><li>One server is designated as the master, while the other ( or others) as slave(s) </li></ul><ul><li>Updates done only on master and binary logs made </li></ul><ul><li>The slave connects to the master, catches up on the missed updates, and then starts receiving updates immediately as they come to the master. </li></ul><ul><li>Why?? </li></ul><ul><li>For robustness you have two systems and switch to the backup if you have problems with the master. </li></ul><ul><li>The extra speed is achieved by sending a part of the non-updating queries to the replica server. </li></ul>
  25. 25. How To (SLAVE) <ul><li>Upgrade both slave and master to 3.23.15 or higher. </li></ul><ul><li>PUT THESE IN my.cnf of SLAVE </li></ul><ul><li>master-host,user,passwd </li></ul><ul><li>server-id=< unique no>= 1 & <=2^32-1 </li></ul><ul><li>master-connect-retry !! (keep trying) </li></ul><ul><li>master-info-file </li></ul><ul><li>replicate-rewrite-db </li></ul><ul><li>skip-slave-start </li></ul><ul><li>Restart the slave(s) </li></ul>
  26. 26. How To (SLAVE) (contd) <ul><li>Take a snapshot of all the tables/databases on the master </li></ul><ul><li>Use command LOAD TABLE <tblname> FROM MASTER (3.23.23)+ </li></ul><ul><li>SLAVE START/STOP </li></ul><ul><li>FLUSH SLAVE </li></ul>
  27. 27. HOW TO (MASTER) <ul><li>log-bin , FLUSH MASTER , FLUSH SLAVE </li></ul><ul><li>When you start the slave thread will be created </li></ul><ul><li>Tables are not Locked </li></ul><ul><li>SET SQL_LOG_BIN=0/1 </li></ul><ul><li>CHANGE MASTER TO master_def_list </li></ul>
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×