Sunday 5 May 2013

Error dropping database


MySQL: ERROR 1010 (HY000): Error dropping database (can't rmdir './sampledb', errno: 39)


Error:

          mysql> drop database sampledb;
          ERROR 1010 (HY000): Error dropping database (can't rmdir './sampledb', errno: 39)

Solution:

Open new terminal
         # cd /var/lib/mysql
         var/lib/mysql# ls
                         sampledb
/var/lib/mysql# rm -fr sampledb

Open MySQL

       mysql> drop database sampledb;
           ERROR 1008 (HY000): Can't drop database 'foodb'; database doesn't exist
      mysql> create database sampledb;
           Query OK, 1 row affected (0.00 sec)
      mysql> drop database sampledb;
           Query OK, 0 rows affected (3.38 sec)

Saturday 23 February 2013

Stored Procedure in MySQL

 


Select
        DELIMITER //
            CREATE PROCEDURE GetAllPicture()
            BEGIN
                     SELECT *  FROM image_infos;
             END //
        DELIMITER ;

         call  GetAllPicture();

Stored Procedures Parameters in MySQL

            In MySQL, a parameter has one of three modes IN, OUT and INOUT

           IN this is the default mode. IN indicates that a parameter can be passed into stored procedures but any 
           modification inside stored procedure does not change parameter.        
         
          OUT this mode indicates that stored procedure can change this parameter and pass back to the calling 
          program.

          INOUT obviously this mode is combined of IN and OUT mode; you can pass parameter into  
          storedprocedure and get it back with the new value from calling program.

 IN

              DELIMITER //
               CREATE PROCEDURE GetAllPictureById(IN user_id INT)
               BEGIN
                         SELECT * FROM image_infos WHERE  id = user_id;
               END //
               DELIMITER ;

OUT
             DELIMITER //
               CREATE PROCEDURE GetAllPictureById(IN user_id INT,OUT total_user INT)
               BEGIN
                         SELECT COUNT(*) AS total_user FROM image_infos WHERE  id = user_id;
               END //
               DELIMITER ;