Monday, July 30, 2012

QUERIES IN SELECTION


Basic queries
Mapping - Basic form of the SQL SELECT statement. 
SELECT (attribute list)
FROM (table list)
WHERE (condition)
Example:
SELECT collegeID FROM college WHERE collegeID=1;
SELECT collegeID, collegeName from college where fname='sheryll may';

Aliases
      - When you join tables, it's often the case that the tables contain columns with the same names.
Example:
   SELECT  E.FNAME, E.LNAME, S.FNAME,   S.LNAME
   FROM   EMPLOYEE AS E, EMPLOYEE AS S
   WHERE  E.SUPERSSN=S.SSN

The use of * 
       - the * is refer to all the attributes.
Example:
    SELECT * FROM college WHERE collegename='CEN';

 Distinct
     - the distinct is used to not to show the record which have a duplicate.
Example:
    SELECT DISTINCT S.age FROM studentinfo;

Monday, July 16, 2012

DATABASE SECURITY


 There are security guidelines in a database particularly in mysql. One of the guidelines is for privacy and security of the database. For example, do not give the password to anyone or to unauthorized person.


Access Privileges

The access privilege is to give a user a privilege to access the databases such as INSERT, UPDATE, DELETE, SELECT. The access privileges enable the user to manage the operation or the record in MySql server.
The access privilege system are the CREATE, GRANT, REVOKE.

The Mysql Access Privilege System which is the CREATE, GRANT, REVOKE. The CREATE privilege is to create a user/account to the mysql. The syntax in creating an account is CREATE USER 'name'@'localhost' IDENTIFIED BY 'password'; 


The grant is to grant the user to access the database. the syntax is GRANT ALL ON db1.tablename TO 'name'@'localhost';

 


The syntax of revoke REVOKE INSERT ON *.* FROM 'name'@'localhost;
  




Permissions
The example of different kinds of permissions are Select_priv; permission to run SELECT queries,
Insert_priv, this is permission to run INSERT statements.  Update_priv, this is the permission to run UPDATE statements. Delete_priv, this is the permission to run DELETE statements. Create_priv, this is the permission to CREATE tables and databases.

The Account Management
To manage the account in the database, first is to CREATE USER, if you want to delete the account, DROP USER. The GRANT is to grant the user to all the priveleges mentioned above.  The RENAME USER used to rename the name of the user. The REVOKE used when you don’t want to give privileges the user. The SET PASSWORD is to set a password in the database.

  

Monday, July 9, 2012

MYSQL SERVER MANAGEMENT


Optimizing
It is used to remove overhead, sort indexes for better access, and generally keep your tables in good order. It is very useful in tables to optimize who’s currently updated or deleted. The OPTIMIZE statement is a SQL statement used when connected to a MySQL database. The syntax is as follows: OPTIMIZE TABLE tablename. Optimizing is an important part of any administrative routine for databases and should be performed regularly.

Analyzing
Analyzing tables improves performance by updating the index information for a table so that MySQL can make a better decision on how to join tables.

Checking
The checking of table is very useful, it checks if there are errors in the table to prevent corruption of 
data. It has six options and there are UPGRADE, QUICK, FAST, MEDIUM, EXTENDED, CHANGED. 
The for upgrade checks if the table is needed to be upgrade if the mysql is compatible with the tables
 that has been created. The incompatibilities may occur because the storage format for a data type 
has changed or because its sort order has changed.

Repairing
The main function of this is to repair table from errors or corrupted table. The same as the checking tables, the repair tables has five options and there are QUICK, FAST, MEDIUM, EXTENDED, CHANGED. The syntax for this is repair table tablename option; you will know if the table is repaired or not by its output. The output has the last row which is the message type. You can see the status if it’s ok.

MYSQL SERVER LOGS


Error Log
The error logs contains information that MySQL occur while the server is running, startup and shutdown data. the error log includes the incorrect password as well as the syntax error in the configuration file. The error logs found in the data directory where the mysql folder is placed and called either mysql.err (on Windows) or hostname.err. You can specify a directory to place the logs unless you give the absolute path to create the file.

General Query log
The general query log as the name indicate, the mysqld act as the general information. It logs all the connections and all executed queries. You can see who is logging on from some place as well as to identify what queries is being run and what time and it can be useful to know the information. To enable the query log, log = [querylog_filename]in the my.ini configuration file. It’s not mandatory to indicate a name in the filename, automatically, the query log will be given the hostname.

Binary log
the event which describe database changes such as as table creation operations or changes to table data is the content of binary log. To enable the binary log: log-bin[=binary_update_log_filename]
in your configuration file. The filename is mandatory and like the query log, the log will be named hostname-bin, with hostname being the name of the host. In an efficient binary format, this log stores all updates to the database.

Slow query log
The SQL statements has the slow query log and it took more than long query time seconds to execute and required at least min_examined_row_limit rows to be examined. Only integer times are written for logging to tables. Times are written including the microseconds part for logging to a file. You can enable the slow query logs, set a slow log query log file, and set the log_query_time in my.cnf.
Edit the MySQL configuration file.
vi /etc/my.cnf
In the [mysqld] section add/edit the following variables
long_query_time = 0
slow_query_log = 1
slow_query_log_file=/var/log/mysqld.slow.query.log

Installation of Mysql in Windows


How To install Mysql in Windows

There is a package that contains all the files found in the complete install package. This is the mysql-noinstall. The Noinstall distribution is packaged as a Zip archive. This is so convenient and used by many users.
To install the mysql-noinstall package, just download the file mysql-noinstall-5.1.65-win32.zip after downloading the file, you must extract the file because this is a zip achieve file. You can place the extract file from all the drives you have.
After the extraction, you can use the mysql server. Rename the file into mysql. To know and test if it works, go to the command prompt.

Type the following command:

cd (drive which the extract mysql has place):\mysql\bin
example:
cd c:\mysql\bin

to start the mysql:
start mysqld

to log in to mysql:
mysql –u root

to shutdown mysql:
mysqladmin –u root shutdown