SlideShare une entreprise Scribd logo
1  sur  56
What's SQL ? Structured Query Language , is a database computer language designed for managing data in relational database management systems (RDBMS), and originally based upon relational algebra. Its scope includes data query and update, schema creation and modification, and data access control.
Downloading MySQL To download  MySQL , go to  http://www.mysql.com/get/Downloads/MySQL-3.23/mysql-3.23.58-win.zip/from/pick  and choose a file mirror to download from.
Installing MySQL Instructions: 1. Firstly, we have to extract the MySQL zip archive to a temporary file and run  setup.exe  from the extracted directory. 2. You can safely use all the default options for this installer. 3. Once the setup wizard is complete it is safe to delete the files you have just extracted (the mysql-3.23.58-win folder). 4. Run the file  C:ysqlininmysqladmin.exe  and a user name and a password of your choice.
This user name and password combination is used for the MySQL administration utility - it is not used to connect to databases at all.  ,[object Object]
To test that Apache recognizes the MySQL installation go to http://127.0.0.1/test.php in a web browser again and scroll down the page until the MySQL section.   ,[object Object]
Basic And Advance SQL Commands
CREATE TABLE ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
INSERT STATEMENTS ,[object Object],[object Object],[object Object],[object Object]
REPLACE STATEMENTS ,[object Object],[object Object],[object Object],[object Object]
UPDATE STATEMENTS  ,[object Object],[object Object],[object Object],[object Object]
Add a new column "male" in table user. ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Change column name "male" into "gender" in table user and change the type to VARCHAR(3) and allow NULL values. ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Change the size of column "gender" from 3 to 6 in table user. ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
SELECT STATEMENTS ,[object Object],[object Object],[object Object],[object Object]
DELETE STATEMENTS ,[object Object],[object Object],[object Object],[object Object]
Show field formats of the selected table. ,[object Object],[object Object],[object Object],[object Object]
To see database's field formats. mysql> describe [table name];
To delete a db. ,[object Object],[object Object],[object Object]
To delete a table. ,[object Object],[object Object],[object Object]
Show all data in a table. ,[object Object],[object Object],[object Object],[object Object]
Show all records from mos_menu table containing name "Home". ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Returns the columns and column information pertaining to the designated table. mysql> show columns from [table name];
Show certain selected rows with the value "whatever". mysql> SELECT * FROM [table name] WHERE [field name] = "whatever";
Show all records containing the name "Bob" AND the phone number '12345678'. mysql> SELECT * FROM [table name] WHERE name = "Bob" AND phone_number = '12345678';
Show all records not containing the name "Bob" and the phone number '12345678' order by the phone_number field. mysql> SELECT * FROM [table name] WHERE name != "Bob" AND phone_number = '12345678' order by phone_number;
Show all records starting with the letters 'bob' AND the phone number '12345678'. mysql> SELECT * FROM [table name] WHERE name like "Bob%" AND phone_number = '12345678';
Show all records starting with the letters 'bob' AND the phone number '12345678' limit to records 1 through 5. mysql> SELECT * FROM [table name] WHERE name like "Bob%" AND phone_number = '12345678' limit 1,5;
Use a regular expression to find records. Use "REGEXP BINARY" to force case-sensitivity. This finds any record beginning with a. mysql> SELECT * FROM [table name] WHERE rec RLIKE "^a";
Show unique records. mysql> SELECT DISTINCT [column name] FROM [table name];
Show selected records sorted in an ascending (asc) or descending (desc). mysql> SELECT [col1],[col2] FROM [table name] ORDER BY [col2] DESC;
Return number of rows. mysql> SELECT COUNT(*) FROM [table name];
Sum column. mysql> SELECT SUM(*) FROM [table name];
Join tables on common columns. mysql> select lookup.illustrationid, lookup.personid,person.birthday from lookup left join person on lookup.personid=person.personid=statement to join birthday in person table with primary illustration id;
Creating a new user. Login as root. Switch to the MySQL db. Make the user. Update privs. # mysql -u root -p mysql> use mysql; mysql> INSERT INTO user (Host,User,Password) VALUES('%','username',PASSWORD('password')); mysql> flush privileges;
Change a users password from unix shell. # [mysql dir]/bin/mysqladmin -u username -h hostname.blah.org -p password 'new-password'
Change a users password from MySQL prompt. Login as root. Set the password. Update privs. # mysql -u root -p mysql> SET PASSWORD FOR 'user'@'hostname' = PASSWORD('passwordhere'); mysql> flush privileges;
Recover a MySQL root password. Stop the MySQL server process. Start again with no grant tables. Login to MySQL as root. Set new password. Exit MySQL and restart MySQL server. # /etc/init.d/mysql stop # mysqld_safe --skip-grant-tables & # mysql -u root mysql> use mysql; mysql> update user set password=PASSWORD("newrootpassword") where User='root'; mysql> flush privileges; mysql> quit # /etc/init.d/mysql stop # /etc/init.d/mysql start
Set a root password if there is on root password. # mysqladmin -u root password newpassword
Update a root password. # mysqladmin -u root -p oldpassword newpassword
Allow the user "bob" to connect to the server from localhost using the password "passwd". Login as root. Switch to the MySQL db. Give privs. Update privs. # mysql -u root -p mysql> use mysql; mysql> grant usage on *.* to bob@localhost identified by 'passwd'; mysql> flush privileges;
Give user privilages for a db. Login as root. Switch to the MySQL db. Grant privs. Update privs. # mysql -u root -p mysql> use mysql; mysql> INSERT INTO db (Host,Db,User,Select_priv,Insert_priv,Update_priv,Delete_priv,Create_priv,Drop_priv) VALUES ('%','databasename','username','Y','Y','Y','Y','Y','N'); mysql> flush privileges; or mysql> grant all privileges on databasename.* to username@localhost; mysql> flush privileges;
To update info already in a table. mysql> UPDATE [table name] SET Select_priv = 'Y',Insert_priv = 'Y',Update_priv = 'Y' where [field name] = 'user';
Delete a row(s) from a table. mysql> DELETE from [table name] where [field name] = 'whatever';
Update database permissions/privilages. mysql> flush privileges;
Delete a column. mysql> alter table [table name] drop column [column name];
Add a new column to db. mysql> alter table [table name] add column [new column name] varchar (20);
Change column name. mysql> alter table [table name] change [old column name] [new column name] varchar (50);
Make a unique column so you get no dupes. mysql> alter table [table name] add unique ([column name]);
Make a column bigger. mysql> alter table [table name] modify [column name] VARCHAR(3);
Delete unique from table. mysql> alter table [table name] drop index [colmn name];
Load a CSV file into a table. mysql> LOAD DATA INFILE '/tmp/filename.csv' replace INTO TABLE [table name] FIELDS TERMINATED BY ',' LINES TERMINATED BY '' (field1,field2,field3);
Dump all databases for backup. Backup file is sql commands to recreate all db's. # [mysql dir]/bin/mysqldump -u root -ppassword --opt >/tmp/alldatabases.sql
Dump one database for backup. # [mysql dir]/bin/mysqldump -u username -ppassword --databases databasename >/tmp/databasename.sql
Dump a table from a database. # [mysql dir]/bin/mysqldump -c -u username -ppassword databasename tablename > /tmp/databasename.tablename.sql
Restore database (or database table) from backup. # [mysql dir]/bin/mysql -u username -ppassword databasename < /tmp/databasename.sql
T H A N K  Y O U

Contenu connexe

Tendances (19)

MySQL partitions tutorial
MySQL partitions tutorialMySQL partitions tutorial
MySQL partitions tutorial
 
Advanced Querying with CakePHP 3
Advanced Querying with CakePHP 3Advanced Querying with CakePHP 3
Advanced Querying with CakePHP 3
 
MySQL
MySQLMySQL
MySQL
 
MYSQL
MYSQLMYSQL
MYSQL
 
MYSQL
MYSQLMYSQL
MYSQL
 
Mysql quick guide
Mysql quick guideMysql quick guide
Mysql quick guide
 
PHP Data Objects
PHP Data ObjectsPHP Data Objects
PHP Data Objects
 
eComma
eCommaeComma
eComma
 
Functional programming with php7
Functional programming with php7Functional programming with php7
Functional programming with php7
 
全裸でワンライナー(仮)
全裸でワンライナー(仮)全裸でワンライナー(仮)
全裸でワンライナー(仮)
 
Quick reference for cql
Quick reference for cqlQuick reference for cql
Quick reference for cql
 
Taking Perl to Eleven with Higher-Order Functions
Taking Perl to Eleven with Higher-Order FunctionsTaking Perl to Eleven with Higher-Order Functions
Taking Perl to Eleven with Higher-Order Functions
 
Linguagem sql
Linguagem sqlLinguagem sql
Linguagem sql
 
Python Ireland Nov 2010 Talk: Unit Testing
Python Ireland Nov 2010 Talk: Unit TestingPython Ireland Nov 2010 Talk: Unit Testing
Python Ireland Nov 2010 Talk: Unit Testing
 
My sql.ppt
My sql.pptMy sql.ppt
My sql.ppt
 
Simple Ways To Be A Better Programmer (OSCON 2007)
Simple Ways To Be A Better Programmer (OSCON 2007)Simple Ways To Be A Better Programmer (OSCON 2007)
Simple Ways To Be A Better Programmer (OSCON 2007)
 
Dependency injection in PHP 5.3/5.4
Dependency injection in PHP 5.3/5.4Dependency injection in PHP 5.3/5.4
Dependency injection in PHP 5.3/5.4
 
mapserver_install_linux
mapserver_install_linuxmapserver_install_linux
mapserver_install_linux
 
MS SQL Database basic
MS SQL Database basicMS SQL Database basic
MS SQL Database basic
 

En vedette (16)

Sql presentation 1 by chandan
Sql presentation 1 by chandanSql presentation 1 by chandan
Sql presentation 1 by chandan
 
working with database using mysql
working with database using mysql working with database using mysql
working with database using mysql
 
MySql Triggers Tutorial - The Webs Academy
MySql Triggers Tutorial - The Webs AcademyMySql Triggers Tutorial - The Webs Academy
MySql Triggers Tutorial - The Webs Academy
 
ISAS On SQL Features like Trigger, Transaction,Batches, Stored Procedure
ISAS On SQL Features like Trigger, Transaction,Batches, Stored ProcedureISAS On SQL Features like Trigger, Transaction,Batches, Stored Procedure
ISAS On SQL Features like Trigger, Transaction,Batches, Stored Procedure
 
User defined functions
User defined functionsUser defined functions
User defined functions
 
User Defined Functions
User Defined FunctionsUser Defined Functions
User Defined Functions
 
PL/SQL User-Defined Functions in the Read World
PL/SQL User-Defined Functions in the Read WorldPL/SQL User-Defined Functions in the Read World
PL/SQL User-Defined Functions in the Read World
 
user defined function
user defined functionuser defined function
user defined function
 
User defined functions in C
User defined functions in CUser defined functions in C
User defined functions in C
 
MYSQL.ppt
MYSQL.pptMYSQL.ppt
MYSQL.ppt
 
Introduction to MySQL
Introduction to MySQLIntroduction to MySQL
Introduction to MySQL
 
SQL Basics
SQL BasicsSQL Basics
SQL Basics
 
SQL Tutorial - Basic Commands
SQL Tutorial - Basic CommandsSQL Tutorial - Basic Commands
SQL Tutorial - Basic Commands
 
Introduction to Mysql
Introduction to MysqlIntroduction to Mysql
Introduction to Mysql
 
MySql slides (ppt)
MySql slides (ppt)MySql slides (ppt)
MySql slides (ppt)
 
Sql ppt
Sql pptSql ppt
Sql ppt
 

Similaire à My sql presentation

Similaire à My sql presentation (20)

Diva10
Diva10Diva10
Diva10
 
My sql Syntax
My sql SyntaxMy sql Syntax
My sql Syntax
 
Msql
Msql Msql
Msql
 
MySQL Database System Hiep Dinh
MySQL Database System Hiep DinhMySQL Database System Hiep Dinh
MySQL Database System Hiep Dinh
 
My sql with querys
My sql with querysMy sql with querys
My sql with querys
 
Raj mysql
Raj mysqlRaj mysql
Raj mysql
 
Mysql
MysqlMysql
Mysql
 
Mysql
MysqlMysql
Mysql
 
06 Php Mysql Connect Query
06 Php Mysql Connect Query06 Php Mysql Connect Query
06 Php Mysql Connect Query
 
Mysqlppt
MysqlpptMysqlppt
Mysqlppt
 
My sql
My sqlMy sql
My sql
 
Mysql cheatsheet
Mysql cheatsheetMysql cheatsheet
Mysql cheatsheet
 
Introduction to database
Introduction to databaseIntroduction to database
Introduction to database
 
Introduction to database
Introduction to databaseIntroduction to database
Introduction to database
 
Php MySql For Beginners
Php MySql For BeginnersPhp MySql For Beginners
Php MySql For Beginners
 
SQL Injection in PHP
SQL Injection in PHPSQL Injection in PHP
SQL Injection in PHP
 
Concern of Web Application Security
Concern of Web Application SecurityConcern of Web Application Security
Concern of Web Application Security
 
SQL -PHP Tutorial
SQL -PHP TutorialSQL -PHP Tutorial
SQL -PHP Tutorial
 
ໂປຮແກຮມ MySQL
ໂປຮແກຮມ MySQLໂປຮແກຮມ MySQL
ໂປຮແກຮມ MySQL
 
Mysql
MysqlMysql
Mysql
 

Dernier

TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 

Dernier (20)

TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 

My sql presentation

  • 1. What's SQL ? Structured Query Language , is a database computer language designed for managing data in relational database management systems (RDBMS), and originally based upon relational algebra. Its scope includes data query and update, schema creation and modification, and data access control.
  • 2. Downloading MySQL To download MySQL , go to http://www.mysql.com/get/Downloads/MySQL-3.23/mysql-3.23.58-win.zip/from/pick and choose a file mirror to download from.
  • 3. Installing MySQL Instructions: 1. Firstly, we have to extract the MySQL zip archive to a temporary file and run setup.exe from the extracted directory. 2. You can safely use all the default options for this installer. 3. Once the setup wizard is complete it is safe to delete the files you have just extracted (the mysql-3.23.58-win folder). 4. Run the file C:ysqlininmysqladmin.exe and a user name and a password of your choice.
  • 4.
  • 5.
  • 6. Basic And Advance SQL Commands
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17. To see database's field formats. mysql> describe [table name];
  • 18.
  • 19.
  • 20.
  • 21.
  • 22. Returns the columns and column information pertaining to the designated table. mysql> show columns from [table name];
  • 23. Show certain selected rows with the value &quot;whatever&quot;. mysql> SELECT * FROM [table name] WHERE [field name] = &quot;whatever&quot;;
  • 24. Show all records containing the name &quot;Bob&quot; AND the phone number '12345678'. mysql> SELECT * FROM [table name] WHERE name = &quot;Bob&quot; AND phone_number = '12345678';
  • 25. Show all records not containing the name &quot;Bob&quot; and the phone number '12345678' order by the phone_number field. mysql> SELECT * FROM [table name] WHERE name != &quot;Bob&quot; AND phone_number = '12345678' order by phone_number;
  • 26. Show all records starting with the letters 'bob' AND the phone number '12345678'. mysql> SELECT * FROM [table name] WHERE name like &quot;Bob%&quot; AND phone_number = '12345678';
  • 27. Show all records starting with the letters 'bob' AND the phone number '12345678' limit to records 1 through 5. mysql> SELECT * FROM [table name] WHERE name like &quot;Bob%&quot; AND phone_number = '12345678' limit 1,5;
  • 28. Use a regular expression to find records. Use &quot;REGEXP BINARY&quot; to force case-sensitivity. This finds any record beginning with a. mysql> SELECT * FROM [table name] WHERE rec RLIKE &quot;^a&quot;;
  • 29. Show unique records. mysql> SELECT DISTINCT [column name] FROM [table name];
  • 30. Show selected records sorted in an ascending (asc) or descending (desc). mysql> SELECT [col1],[col2] FROM [table name] ORDER BY [col2] DESC;
  • 31. Return number of rows. mysql> SELECT COUNT(*) FROM [table name];
  • 32. Sum column. mysql> SELECT SUM(*) FROM [table name];
  • 33. Join tables on common columns. mysql> select lookup.illustrationid, lookup.personid,person.birthday from lookup left join person on lookup.personid=person.personid=statement to join birthday in person table with primary illustration id;
  • 34. Creating a new user. Login as root. Switch to the MySQL db. Make the user. Update privs. # mysql -u root -p mysql> use mysql; mysql> INSERT INTO user (Host,User,Password) VALUES('%','username',PASSWORD('password')); mysql> flush privileges;
  • 35. Change a users password from unix shell. # [mysql dir]/bin/mysqladmin -u username -h hostname.blah.org -p password 'new-password'
  • 36. Change a users password from MySQL prompt. Login as root. Set the password. Update privs. # mysql -u root -p mysql> SET PASSWORD FOR 'user'@'hostname' = PASSWORD('passwordhere'); mysql> flush privileges;
  • 37. Recover a MySQL root password. Stop the MySQL server process. Start again with no grant tables. Login to MySQL as root. Set new password. Exit MySQL and restart MySQL server. # /etc/init.d/mysql stop # mysqld_safe --skip-grant-tables & # mysql -u root mysql> use mysql; mysql> update user set password=PASSWORD(&quot;newrootpassword&quot;) where User='root'; mysql> flush privileges; mysql> quit # /etc/init.d/mysql stop # /etc/init.d/mysql start
  • 38. Set a root password if there is on root password. # mysqladmin -u root password newpassword
  • 39. Update a root password. # mysqladmin -u root -p oldpassword newpassword
  • 40. Allow the user &quot;bob&quot; to connect to the server from localhost using the password &quot;passwd&quot;. Login as root. Switch to the MySQL db. Give privs. Update privs. # mysql -u root -p mysql> use mysql; mysql> grant usage on *.* to bob@localhost identified by 'passwd'; mysql> flush privileges;
  • 41. Give user privilages for a db. Login as root. Switch to the MySQL db. Grant privs. Update privs. # mysql -u root -p mysql> use mysql; mysql> INSERT INTO db (Host,Db,User,Select_priv,Insert_priv,Update_priv,Delete_priv,Create_priv,Drop_priv) VALUES ('%','databasename','username','Y','Y','Y','Y','Y','N'); mysql> flush privileges; or mysql> grant all privileges on databasename.* to username@localhost; mysql> flush privileges;
  • 42. To update info already in a table. mysql> UPDATE [table name] SET Select_priv = 'Y',Insert_priv = 'Y',Update_priv = 'Y' where [field name] = 'user';
  • 43. Delete a row(s) from a table. mysql> DELETE from [table name] where [field name] = 'whatever';
  • 44. Update database permissions/privilages. mysql> flush privileges;
  • 45. Delete a column. mysql> alter table [table name] drop column [column name];
  • 46. Add a new column to db. mysql> alter table [table name] add column [new column name] varchar (20);
  • 47. Change column name. mysql> alter table [table name] change [old column name] [new column name] varchar (50);
  • 48. Make a unique column so you get no dupes. mysql> alter table [table name] add unique ([column name]);
  • 49. Make a column bigger. mysql> alter table [table name] modify [column name] VARCHAR(3);
  • 50. Delete unique from table. mysql> alter table [table name] drop index [colmn name];
  • 51. Load a CSV file into a table. mysql> LOAD DATA INFILE '/tmp/filename.csv' replace INTO TABLE [table name] FIELDS TERMINATED BY ',' LINES TERMINATED BY '' (field1,field2,field3);
  • 52. Dump all databases for backup. Backup file is sql commands to recreate all db's. # [mysql dir]/bin/mysqldump -u root -ppassword --opt >/tmp/alldatabases.sql
  • 53. Dump one database for backup. # [mysql dir]/bin/mysqldump -u username -ppassword --databases databasename >/tmp/databasename.sql
  • 54. Dump a table from a database. # [mysql dir]/bin/mysqldump -c -u username -ppassword databasename tablename > /tmp/databasename.tablename.sql
  • 55. Restore database (or database table) from backup. # [mysql dir]/bin/mysql -u username -ppassword databasename < /tmp/databasename.sql
  • 56. T H A N K Y O U