Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.



Published on

Published in: Technology
  • Be the first to comment

  • Be the first to like this


  1. 1. MYSQL MySQL is a database.The data in MySQL is stored in database objects called tables.A table is a collections of related data entries and it consists of columns and rows.Databases are useful when storing information categorically. A company may have a database with the following tables: "Employees", "Products", "Customers" and "Orders".
  2. 2. INSTALLATION <ul><li>It's simple to install MySQL on Linux using the RPM file. </li></ul><ul><li>1. Become the superuser if you are working in your account. (Type &quot;su&quot; and the prompt and give the root password). </li></ul><ul><li>2. Change to the directory that has the RPM download. </li></ul><ul><li>3. Type the following command at the prompt: </li></ul><ul><li>rpm -ivh &quot;mysql_file_name.rpm&quot; </li></ul><ul><li>Similarly you can also install the MySQL client and MySQL development RPMs if you've downloaded them. </li></ul><ul><li>Alternatively, you can install the RPMs through GnoRPM (found under System). </li></ul><ul><li>4.Now we'll set a password for the root user. Issue the following at the prompt: </li></ul><ul><li>mysqladmin -u root password mysqldata </li></ul>
  3. 3. 5.It is now time to test the programs. Typing the following at the prompt starts the mysql client program. The system asks for the the password.Type the root password (mysqldata).If you don't get the prompt for password, it might be because MySQL Server is not running. To start the server, change to /etc/rc.d/init.d/ directory and issue the command ./mysql start (or mysql start depending on the value of the PATH variable on your system). Now invoke mysql client program. 6.Once MySQL client is running, you should get the mysql> prompt. Type the following at this prompt: show databases;
  4. 4. 7. You should now get a display similar to: We've successfully installed MySQL on your system
  5. 5. I The MySQL server configuration normally started during installation process . The MySQL configuration wizard can be launched by clicking the MySQL server instance configuration wizard entry in the MySQL section of the window start menu. Another way to launch the configuration wizard, you can launch the MySQLInstanceConfig.exe file directly from bin directory of your MySQL installation. The MySQL server configuration wizard sets configuration variables values in my.ini file in the installation directory for the MySQL server. --defaults-file=&quot;C:Program FilesMySQLMySQL Server 5.0my.ini&quot; Path &quot;C:Program FilesMySQLMySQL Server 5.0&quot; is installation directory of MySQL server . The --defaults-file option instructs the MySQL server to read the specified file for configuration options when it starts. The MySQL client and utilities like mysql and mysqldump command-line client are unable to locate the my.ini file locate in the server installation directory. The MySQL use window server 2003, window server 2000 and window XP, MySQL server configuration wizard will configure with MySQL quickly without having to make many decisions about server configuration. CONFIGURATION
  6. 6. <ul><li>The MySQL server </li></ul><ul><li>[mysqld] </li></ul><ul><li>port= 3306 </li></ul><ul><li>socket= /opt/lampp/var/mysql/mysql.sock </li></ul><ul><li>skip-locking </li></ul><ul><li>key_buffer = 16M </li></ul><ul><li>max_allowed_packet = 1M </li></ul><ul><li>table_cache = 64 </li></ul><ul><li>sort_buffer_size = 512K </li></ul><ul><li>net_buffer_length = 8K </li></ul><ul><li>read_buffer_size = 256K </li></ul><ul><li>read_rnd_buffer_size = 512K </li></ul><ul><li>myisam_sort_buffer_size = 8M </li></ul>
  7. 7. <ul><li>Where do all the plugins live </li></ul><ul><li>plugin_dir = /opt/lampp/lib/mysql/plugin/ </li></ul><ul><li>Don't listen on a TCP/IP port at all. This can be a security enhancement, </li></ul><ul><li>if all processes that need to connect to mysqld run on the same host. </li></ul><ul><li>All interaction with mysqld must be made via Unix sockets or named pipes. </li></ul><ul><li>Note that using this option without enabling named pipes on Windows </li></ul><ul><li>(via the &quot;enable-named-pipe&quot; option) will render mysqld useless! </li></ul>
  8. 8. REPLICATION SLAVE <ul><li>Two methods to configure the host as a replication slave </li></ul>
  9. 9. <ul><li>1) Use the CHANGE MASTER TO command (fully described in our manual) - </li></ul><ul><li>The syntax is: </li></ul><ul><li>CHANGE MASTER TO MASTER_HOST=<host>, MASTER_PORT=<port>, </li></ul><ul><li>MASTER_USER=<user>, MASTER_PASSWORD=<password> ; </li></ul><ul><li>where you replace <host>, <user>, <password> by quoted strings and </li></ul><ul><li><port> by the master's port number (3306 by default). </li></ul><ul><li>Example: </li></ul><ul><li>CHANGE MASTER TO MASTER_HOST='125.564.12.1', MASTER_PORT=3306, </li></ul><ul><li>MASTER_USER='joe', MASTER_PASSWORD='secret'; </li></ul>
  10. 10. Set the variables below. However, in case you choose this method, then start replication for the first time (even unsuccessfully, for example if you mistyped the password in master-password and the slave fails to connect), the slave will create a file, and any later change in this file to the variables' values below will be ignored and overridden by the content of the file, unless you shutdown the slave server, delete and restart the slaver server.
  11. 11. QUERIES <ul><li>A query is a question or a request. </li></ul><ul><li>With MySQL, we can query a database for specific information and have a recordset returned. </li></ul><ul><li>EXAMPLE: </li></ul><ul><li>SELECT LastName FROM Persons </li></ul>
  12. 12. CREATE <ul><li>The Create command is used to create a table by specifying the tablename, fieldnames and constraints as shown below. </li></ul><ul><li>Syntax: </li></ul><ul><li>$createSQL=(&quot;CREATE TABLE tblName&quot;); </li></ul><ul><li>Example: </li></ul><ul><li>$createSQL=(&quot;CREATE TABLE tblstudent(fldstudid int(10) NOTNULL AUTO_INCREMENT PRIMARY KEY,fldstudName VARCHAR(250) NOTNULL,fldstudentmark int(4) DEFAULT '0' &quot;); </li></ul>
  13. 13. SELECT <ul><li>The Select command is used to select the records from a table using its field names. To select all the fields in a table, '*' is used in the command. </li></ul><ul><li>Syntax: </li></ul><ul><li>$selectSQL=(&quot;SELECT field_names FROM tablename&quot;); </li></ul><ul><li>Example: </li></ul><ul><li>$selectSQL=(&quot;SELECT * FROM tblstudent&quot;); </li></ul>
  14. 14. DELETE <ul><li>The Delete command is used to delete the records from a table using conditions as shown below: </li></ul><ul><li>Syntax: </li></ul><ul><li>$deleteSQL=(&quot;DELETE * FROM tablename WHERE condition&quot;); </li></ul><ul><li>Example: </li></ul><ul><li>$deleteSQL=(&quot;DELETE * FROM tblstudent WHERE fldstudid=2&quot;); </li></ul>
  15. 15. INSERT <ul><li>The Insert command is used to insert records into a table. The values are assigned to the field names as shown below: </li></ul><ul><li>Syntax: </li></ul><ul><li>$insertSQL=(&quot;INSERT INTO tblname(fieldname1,fieldname2..) VALUES(value1,value2,...) &quot;); </li></ul><ul><li>Example: </li></ul><ul><li>$insertSQL=(&quot;INSERT INTO Tblstudent(fldstudName,fldstudmark)VALUES(Baskar,75) &quot;); </li></ul>
  16. 16. DELETE <ul><li>The Update command is used to update the field values using conditions. This is done using 'SET' and the fieldnames to assign new values to them. </li></ul><ul><li>Syntax: </li></ul><ul><li>$updateSQL=(&quot;UPDATE Tblname SET (fieldname1=value1,fieldname2=value2,...) WHERE fldstudid=IdNumber&quot;); </li></ul><ul><li>Example: </li></ul><ul><li>$updateSQL=(&quot;UPDATE Tblstudent SET (fldstudName=siva,fldstudmark=100) WHERE fldstudid=2&quot;); </li></ul>
  17. 17. DROP <ul><li>The Drop command is used to delete all the records in a table using the table name as shown below: </li></ul><ul><li>Syntax: </li></ul><ul><li>$dropSQL=(&quot;DROP tblName&quot;); </li></ul><ul><li>Example: </li></ul><ul><li>$dropSQL=(&quot;DROP tblstudent&quot;); </li></ul>
  18. 18. UPDATE <ul><li>The update statement is used to change values that are already in a table. </li></ul><ul><li>SYNTAX: </li></ul><ul><li>UPDATE <table name> </li></ul><ul><li>SET <attribute> = <expression> </li></ul><ul><li>WHERE <condition>; </li></ul><ul><li>Example: </li></ul><ul><li>UPDATE STUDENT SET Name = ‘Amar’ </li></ul><ul><li>WHERE StudID=1001; </li></ul>
  19. 19. TRUNCATE <ul><li>It is used to delete the table. </li></ul><ul><li>SYNTAX: </li></ul><ul><li>truncatae table table_name </li></ul>
  20. 20. AS <ul><li>Syntax: </li></ul><ul><li>SELECT <columns>FROM <existing_table_name>AS <new_table_name> </li></ul><ul><li>Example: SELECT -> FROM artists -> AS t1; </li></ul><ul><li>Explanation: It is used to create a shorthand reference to elements with long names to make the SQL statements shorter and reduce the chance of typos in the longer names. </li></ul>
  21. 21. JOINS <ul><li>SQL joins are used to query data from two or more tables, based on a relationship between certain columns in these tables.The JOIN keyword is used in an SQL statement to query data from two or more tables, based on a relationship between certain columns in these tables.Tables in a database are often related to each other with keys.A primary key is a column (or a combination of columns) with a unique value for each row. Each primary key value must be unique within the table. The purpose is to bind data together, across tables, without repeating all of the data in every table. </li></ul>
  22. 22. DIFFERENT SQL JOINS <ul><li>JOIN: Return rows when there is at least one match in both tables </li></ul><ul><li>LEFT JOIN: Return all rows from the left table, even if there are no matches in the right table </li></ul><ul><li>RIGHT JOIN: Return all rows from the right table, even if there are no matches in the left table </li></ul><ul><li>FULL JOIN: Return rows when there is a match in one of the tables </li></ul>
  23. 23. INNER JOIN <ul><li>The INNER JOIN keyword return rows when there is at least one match in both tables. </li></ul><ul><li>SQL INNER JOIN Syntax </li></ul><ul><li>SELECT column_name(s) FROM table_name1 INNER JOIN table_name2 ON table_name1.column_name=table_name2.column_name; </li></ul><ul><li>EXAMPLE: </li></ul>LASTNAME FIRST NAME ORDER NO. Hansen Ola 22456 Hansen Ola 24562 Pettersen Kari 77895 Pettersen Kari 44678
  24. 24. LEFT JOIN <ul><li>The LEFT JOIN keyword returns all rows from the left table (table_name1), even if there are no matches in the right table (table_name2). </li></ul><ul><li>SQL LEFT JOIN Syntax: </li></ul><ul><li>SELECT column_name(s) FROM table_name1 </li></ul><ul><li>LEFT JOIN table_name2 ON table_name1.column_name=table_name2.column_name </li></ul>
  25. 25. RIGHT JOIN <ul><li>The RIGHT JOIN keyword Return all rows from the right table (table_name2), even if there are no matches in the left table (table_name1). </li></ul><ul><li>SQL RIGHT JOIN Syntax: </li></ul><ul><li>SELECT column_name(s) FROM table_name1 </li></ul><ul><li>RIGHT JOIN table_name2 ON table_name1.column_name=table_name2.column_name </li></ul>
  26. 26. FULL JOIN <ul><li>The FULL JOIN keyword return rows when there is a match in one of the tables. </li></ul><ul><li>SQL FULL JOIN Syntax: </li></ul><ul><li>SELECT column_name(s) FROM table_name1 </li></ul><ul><li>FULL JOIN table_name2 ON table_name1.column_name=table_name2.column_name </li></ul>
  27. 27. CONSTRAINTS <ul><li>Constraints are used to limit the type of data that can go into a table.Constraints can be specified when a table is created (with the CREATE TABLE statement) or after the table is created (with the ALTER TABLE statement). </li></ul><ul><li>We have the following constraints: </li></ul><ul><li>* NOT NULL </li></ul><ul><li>* UNIQUE </li></ul><ul><li>* PRIMARY KEY </li></ul><ul><li>* FOREIGN KEY </li></ul><ul><li>* CHECK </li></ul><ul><li>* DEFAULT </li></ul>
  28. 28. FUNCTIONS <ul><li>AGGERATE FUNCTIONS </li></ul><ul><li>SCALAR FUNCTIONS </li></ul>
  29. 29. AGGERATE FUNCTIONS <ul><li>SQL aggregate functions return a single value, calculated from values in a column. </li></ul><ul><li>AVG() - Returns the average value </li></ul><ul><li>COUNT() - Returns the number of rows </li></ul><ul><li>FIRST() - Returns the first value </li></ul><ul><li>LAST() - Returns the last value </li></ul><ul><li>MAX() - Returns the largest value </li></ul><ul><li>MIN() - Returns the smallest value </li></ul><ul><li>SUM() - Returns the sum </li></ul>
  30. 30. SCALAR FUNCTIONS <ul><li>SQL scalar functions return a single value, based on the input value. </li></ul><ul><li>* UCASE() - Converts a field to upper case </li></ul><ul><li>* LCASE() - Converts a field to lower case </li></ul><ul><li>* MID() - Extract characters from a text field </li></ul><ul><li>* LEN() - Returns the length of a text field </li></ul><ul><li>* ROUND() - Rounds a numeric field to the number of decimals specified </li></ul><ul><li>* NOW() - Returns the current system date and time </li></ul><ul><li>* FORMAT() - Formats how a field is to be displayed </li></ul>