MySQL

What is Database?

  • A database is a structured collection of data.

 

What is Database Management System?

  • To add, access, and process data stored in a computer database, you need a database management system such as MySQL Server.

 

What is RDBMS?

  • A relational database stores data in separate tables rather than putting all the data in one big storeroom.

 

What is MySQL?

  • MySQL is open source Relational Database Management System (RDBMS). Open Source means that it is possible for anyone to use and modify the software.
  • The SQL part of MySQL stands for Structured Query Language. SQL is the most common standardized language used to access databases.
  • It is developed, distributed, and supported by Oracle Corporation.

 

                                                   


 

MySQL Commands – Basic

DATABASE:

Replace “DatabaseName” with the name of your database.

 

1. To show existing databases:
SHOW DATABASES;

 

2. To create a new database-
CREATE DATABASE DatabaseName;

 

3. To delete an existing database:
DROP DATABASE DatabaseName;

 

4. To use an existing database:
USE DatabaseName;

 

TABLES:

 

1. Create a new table:
CREATE TABLE TableName(column1 datatype, column2 datatype, … , columnn datatype, PRIMARY KEY(column1));

a) You can put Primary Key in one or more columns. Primary Key is the unique key which identifies unique record.

b) Although there are many datatypes, most popular ones are:
-int – for integers
-varchar – for characters only
-char – for numbers as well as characters
-decimal – for decimal values

c) ‘NOT NULL’ shows that these fields can not be NULL while creating records in this table.

 

2. To show an existing table:
DESCRIBE TableName;

 

3. To delete an existing table:
DROP TABLE TableName;

 

4. To add new rows of data into a table in database:
INSERT INTO TableName (column1, column2, … , columnn) VALUES (value1, value2, … , valuen);

a) You may not specify column names if you are inserting values for each and every column. But make sure the order of values is same as that of order of columns:
INSERT INTO TableName VALUES (value1, value2, … , valuen);

 

5. To fetch data/records from table and display it in tabular form:

a) To select specific fields/columns from table:
SELECT column1, column3, columnn from TableName;

b) To select all fields/columns from table:
SELECT * from TableName;

 

6. WHERE condition:

a) used to specify a condition while fetching the data from single table or joining with multiple tables:
SELECT column1, column2, column3 WHERE condition1;
Example:
– SELECT id, name, salary FROM customers WHERE salary>2000;
– SELECT id, name, salary FROM customers WHERE name = ‘Yash’;

b) To combine multiple conditions:
SELECT column1, column2, column3 WHERE condition1 AND condition2;
Example:
– SELECT id, name, salary FROM customers WHERE salary>2000 AND age>25;
SELECT column1, column2, column3 WHERE condition1 OR condition2;
Example:
– SELECT id, name, salary FROM customers WHERE salary>2000 OR age>25;

 

7. UPDATE query is to modify existing records in an existing table:

a) To update selected columns or all columns:
UPDATE TableName SET column1 = value1, column2 = value3 WHERE condition1;
UPDATE TableName SET column1 = value1, column2 = value3 WHERE condition1 AND condition2;
– UPDATE TableName SET column1 = value1, column2 = value3 WHERE condition1 OR condition2;

 

8. To delete records from table:

a) To delete all records:
DELETE FROM TableName;

b) To delete selected rows:
DELETE FROM TableName WHERE condition1;
DELETE FROM TableName WHERE condition1 AND condition2;
DELETE FROM TableName WHERE condition1 OR condition2;

9. To compare a value to similar values using wildcard operators, we use LIKE clause. There are two wildcards we use in conjunction with LIKE operator:

a) % – percent sign represents zero, on or multiple characters.

b) _ – underscore sign represents a single number or character.

c) Basic syntax:
– SELECT FROM TableName WHERE column1 LIKE ‘XXXX%’;
           – SELECT FROM TableName WHERE column1 LIKE ‘%XXXX%’;
           – SELECT FROM TableName WHERE column LIKE ‘XXXX_’;
           – SELECT FROM TableName WHERE column LIKE ‘_XXXX’;
           – SELECT FROM TableName WHERE column LIKE ‘_XXXX_’;

 

10. To select top n number or x percent records from table:

a) To select top records from specific columns from table:
SELECT TOP/LIMIT number/percent column1 column2 column3 FROM TableName WHERE condition1;  

b) To select top records from all columns from table:
SELECT TOP/LIMIT number/percent FROM TableName WHERE condition1;

 

11. To sort data in ascending or descending order, based on one or more columns:

a) To sort specific data/columns in ascending order:
SELECT column1, column2, column4, column7 FROM TableName WHERE condition1 ORDER BY column1, column2 ASC/DESC;

b) To sort all data/columns in ascending order:
SELECT * FROM TableName WHERE condition1 ORDER BY column1, column2 ASC/DESC;

MySQL

Yum Error

For this error of yum:

[Errno 14] HTTP Error 404 – Not Found

 

There are two ways:

1. Execute the following two command line instructions:

    i) yum clean all

    ii) yum update

2. Disable some repos:

    i) login as root user and enter the password:

    su -
    <
password>

    ii) switch to the repo folder:

    cd /etc/yum.repos.

    iii) look at your repo folder:

    ls  /etc/yum.repos.

    iv) execute the following commands to disable several repositories:

    PHP code:

    sed -'s/enabled=1/enabled=0/g' atrpms.repo
    sed 
-'s/enabled=1/enabled=0/g' livna.repo
    sed 
-'s/enabled=1/enabled=0/g' *rawhide*
    sed -'s/enabled=1/enabled=0/g' *testing*
    sed -'s/enabled=1/enabled=0/g' software.freivald.com.repo 

 

 

 

 

 

Yum Error