MySQL Database

    How to start mysql terminal in Mac Ox

    Open terminal and execute following command

    /Applications/MAMP/Library/bin/mysql -uroot -p

    Enter password if any your mysql console will be started then

    How to connect to mysql console mamp on mac os

    First of all start terminal check this in launchpad or simply search in spotlight. When terminal is opened type following command and then enter database password
    apple@mohit$ /Applications/MAMP/Library/bin/mysql -uroot -p
    Enter Password:

    How to import comma seperated text file to mysql database in php

    This are two ways of doing this first is if file already placed on server then you can give filepath and tablename and run create this file import.php <?php $connec = mysql_connect(, ,); mysql_select_db(, $connec); $sql = "LOAD DATA LOCAL INFILE '' REPLACE INTO TABLE FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '\"' LINES TERMINATED BY '\r\n' IGNORE 1 LINES "; mysql_query($sql); if(mysql_error()) { echo(mysql_error()); } else { echo("Import sucessfull data imported to mysq

    How to create new user in mysql using ssh

    To create new user in mysql using ssh connect to mysql with root user then follow the steps
    1. Create new user
    mysql> CREATE USER mohit@localhost IDENTIFIED BY '****';

    2. Grant previleges to newly created user
    mysql> GRANT ALL PRIVILEGES ON *.* TO mohit@localhost

    How to import/export mysql database via ssh

    You can import export mysql database via ssh follow the steps mentioned below 1. Login to ssh using ssh client putty or via (ubuntu)terminal 2.

    How to show result from first 5 or 10 records in a table based on a condition from mysql database

    To show result from first 5 or 10 records on the basis of some condtion from mysql database use following query:
    (SELECT id, status FROM data
    ORDER BY created_at DESC
    LIMIT 0, 5)  AS t WHERE t.status = 'failed'

    Where data is table name and status is field name contains status "failed" or "success" if there are 5 consecutive it will display 5 records otherwise failed-success in last 5 records

    Note: You can change the limit from 5 to 10, 20 etc depends upon your requirement