Posts

Showing posts with the label My SQL

The Requested Url /Phpmyadmin/ Was Not Found On This Server

Image
  What Is phpMyAdmin phpMyAdmin is an open-source software tool introduced on September 9, 1998, which is written in PHP. Basically, it is a third-party tool to manage the tables and data inside the database. phpMyAdmin supports various type of operations on MariaDB and MySQL. The main purpose of phpMyAdmin is to handle the administration of MySQL over the web. phpMyAdmin has a GUI application which used to mange the database. Here we can create a database, table and execution of mysql query using phpMyAdmin GUI Our Problem  : phpMyAdmin url not found. Here you will find the  Solution Here

Free AWS EC2 Ubuntu Instance Website setup

Image
Amazon Web Service is a cloud platform which given us to create free hosting in both platform like Windows and Linux. Here we are working on Ubuntu setup. Where we will install Apache2, PHP and MySQL. 1. First you have to create new account in AWS. If you have existing account then no need to create. 2. After login you have to select EC2 option then you enter EC2 Dashboard. 3. Click Launch Instance 4. Select Free tier Eligible Ubuntu option. 5. Add New Volume EBS. 6. Add New Tag. 7. Add Security Group.   Type : SSH   Protocol: TCP   Port : 22   Source : Anywhere   Type : HTTP   Protocol : TCP   Port : 80   Source : Anywhere 8. Review and Launch 9. Create a New Pair Key. Download Key. 10. Using Puttygen.exe software create public and private key. 11. Login SSH using putty.exe Now we are ready to install Apache2, PHP, MySQL. Command 1 ( Update Ubuntu server ) sudo apt-get update sudo apt-get dist-upgrade Command 2 ( Install apache2 server ) sud

Import CSV to Database using PHP

Import csv database using PHP. Follow the following code and you will done with CSV import script using PHP. If you have any questions you can feel free comment we will reply you ASAP. PHP Code <?php if(isset($_POST["Import"])) { $filename=$_FILES["file"]["tmp_name"]; if($_FILES["file"]["size"] > 0) { $file = fopen($filename, "r"); mysql_query('truncate table table'); while (($data = fgetcsv($file, 10000, ",")) !== FALSE) { $sql = "INSERT into table(name,email,avg,sr,runs,wickets,hs,sixes,fours,longsixes,created) values('$data[0]','$data[1]','$data[2]','$data[3]','$data[4]','$data[5]','$data[6]','$data[7]','$data[8]','$data[9]', now())"; mysql_query($sql); } fclose($file); echo

Enabling the MySQL Event Scheduler

MySQL events are executed by a special event scheduler thread. It's disabled by default. MySQL 5.1 Event Scheduler, Conceptually, this is similar to the idea of the UNIX crontab (also known as a “cron job”) The MySQL Event Scheduler manages the scheduling and execution of events. If you are running larg number of data like Shopping Cart, Any Portals that time we need to handle data. Here is Simple example Create Table CREATE TABLE user ( user_id INT  AUTO_INCREMENT, user varchar(250), created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (user_id) ) ; Start phpmyadmin SET GLOBAL event_scheduler = ON; Creat New Event CREATE EVENT newEvent ON SCHEDULE EVERY 1 DAY DO DELETE FROM user WHERE created_at = DATE_SUB(NOW(), INTERVAL 10 DAY); Finished .............. :)

Reset the auto increment value for a MySQL table

Image
The following example changes the auto increment value for the table named "applytable" to 100. This means that the next time you insert a record into this table the value of the auto incremental primary key will be 100. If the highest value for the column is already greater than 100 then it will be set to the highest value plus 1. ALTER TABLE mytable AUTO_INCREMENT = 100   The relevent info are highlighted with red circles in the screenshot below.

Second and Third Highest Salary using mysql

It is very easy to find second highest salary SELECT * FROM emp WHERE salary =(SELECT salary FROM emp GROUP BY salary ORDER BY salary DESC LIMIT 1 , 1) Third highest salary you can find following ways SELECT * FROM emp WHERE salary =(SELECT salary FROM emp GROUP BY salary ORDER BY salary DESC LIMIT 2 , 1)

What is normalization process?

Normalization is the process of efficiently organize a data in database. There are two goals of the normalization process: 1 Eliminating redundant data (for example, storing the same data in more than one table). 2. Ensuring data dependencies make sense (only storing related data in a table). Both of these are worthy goals as they reduce the amount of space a database consumes and ensure that data is logically stored.

Different between primary key and unique key?

One table may have more than one Unique Key Constraint columns, but should have only one Primary Key Constraint column.   Unique key allow us NULL values where Primary key not allow us null values.    

Second highest salary in MYSQL?

MY SQL We have one tables tblSalary empID     empName   empSal 1              A                 5000 2              B                 3000 3              C                 2000 4              D                 6000 Using of limit option we can find second highest salary in mysql. select empSal from tblSalary order by empSal DESC Limit 1, 1 Output 5000

how to select data in mysql using year?

Use Following code 1. SELECT YEAR(now()) 2. SELECT * FROM `table_name` WHERE YEAR( `start_date` ) LIKE '2007' LIMIT 0 , 30

Database backup using ssh linux

Here we are creating gz backup files using shell programming step1 . create backup file backup.sh step2. set cron job in control panel. #!/bin/bash ### MySQL Server Login Info ### MUSER="user" MPASS="Password" MHOST="localhost" MYSQL="$(which mysql)" MYSQLDUMP="$(which mysqldump)" BAK="backup/mysql" GZIP="$(which gzip)" NOW=$(date +"%d-%m-%Y") [ ! -d $BAK ] && mkdir -p $BAK || /bin/rm -f $BAK/* FILE=$BAK/"databasename".gz $MYSQLDUMP -u $MUSER -h $MHOST -p$MPASS "databasename" | $GZIP -9 > $FILE

Store Procedure

Reduced network traffic and latency, boosting application performance. Stored procedure execution plans can be reused, staying cached in SQL Server’s memory, reducing server overhead. Client execution requests are more efficient. For example, if an application needs to INSERT a large binary value into an image data column not using a stored procedure, it must convert the binary value to a character string (which doubles its size), and send it to SQL Server. When SQL Server receives it, it then must convert the character value back to the binary format. This is a lot of wasted overhead. A stored procedure eliminates this issue as parameter values stay in the binary format all the way from the application to SQL Server, reducing overhead and boosting performance. Stored procedures help promote code reuse. While this does not directly boost an application’s performance, it can boost the productivity of developers by reducing the amount of code required, along with reducing

How to get table count for all tables in a database in Mysql?

Following Example shows you how to get tables list from database using PHP CODE. <?php $dbname = 'mysql_dbname'; if (!mysql_connect('localhost', 'root', '')) {     echo 'Could not connect to mysql';     exit; } $sql = "SHOW TABLES FROM $dbname";$result = mysql_query($sql); if (!$result) {     echo "DB Error, could not list tables\n";     echo 'MySQL Error: ' . mysql_error();     exit; } while ($row = mysql_fetch_row($result)) {     echo "Table: $row[0] \n"; } mysql_free_result($result);?>

How many storage engines in MySQL?

1.  MyISAM :  MyISAM is a default storage engine and that one using in web, data warehousing and other application environments. 2. InnoDB : Using this engines our transaction is safe and we can use this for row level blocking. 3. Memory : Store data in RAM for fast access of data formally known as HEAP . 4. NDBClusters : This clustered database engine is particularly suited for applications that require the highest possible degree of up-time and availability.

Creating Index in Mysql

Index CREATE INDEX work_id(Index_name) ON table_name field_Name

php store array in database ?

Array can be stored in database in the form of string.we can use serialize function to make storable representation of array.we can also get back from that string to array using unserialize function.eg. <?php $arr=array("India","Pakistan","Sri Lanka","Bangladesh"); //process of serialization $newString=serialize($arr); //it will produce following output a:4:{i:0;s:5:"India";i:1;s:8:"Pakistan";i:2;s:9:"Sri Lanka";i:3;s:10:"Bangladesh";} //process of unserialization $arr=unserialize($newString); print_r($arr); //it will produce following output Array ( [0] => India [1] => Pakistan [2] => Sri Lanka [3] => Bangladesh ) ?>

MYSQL dump file using command prompt ?

First of all ,go to mysqldump utility folder eq. C:\wamp\bin\php\php5.3.0 using commad prompt and then type following code. in this example wordpress database has username root without password. login into command prompt if you are using XAMPP please follow following Step step 1.   cd  c:\xampp\mysq\bin Method 1.   mysql -u root -p -h localhost databasename < file.sql file must save in your c:\xampp\mysql\bin Method 2. >mysqldump --opt --user=root --password= wordpress > mydata.sql