Announcement

Collapse
No announcement yet.

Some important basic Mysql commands

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Some important basic Mysql commands

    Basic Mysql commands

    Mysql is the database service , Following are few basic mysql commands used on linux server .The beloe mentioned commands can be executed from PhpMyadmin as those commands has to be executed from shell .



    For finding important information about Mysql

    Code:
    --------------------------------------------
    # mysql -e status
    --------------------------------------------

    To connect to the mysql prompt

    Code:
    --------------------------------------------
    #mysql
    --------------------------------------------

    If you want to create a database named 'testdatabase'.

    Code:
    --------------------------------------------
    #mysql>create database testdatabase;
    --------------------------------------------

    If a user want to create user and password

    Code:
    ----------------------------------------------------------------------------------------
    #mysql> CREATE USER 'username'@'localhost' IDENTIFIED BY 'password';
    ----------------------------------------------------------------------------------------

    To check whether the mysql connection

    Code:
    --------------------------------------------
    #mysql -u username -p databasename
    --------------------------------------------

    It will ask for password then enter the password

    To use a database
    Code:
    --------------------------------------------
    mysql> use databasename ;
    --------------------------------------------

    These above are some of the Mysql commands which can be fired from the shell prompt to find out the information or sort some mysql issue.

  • #2
    Here you will find a collection of basic MySQL statements that should prove useful for basic CRUDS operations (create, replace, update, delete, select). There may be some issues with the kind of quotes you use around your data. If you are having difficulties, try using singe quotes ( ' ) or tricky quotes ( ` -- on keyboard key next to number 1) around your data. One or the other is bound to work.

    CREATE DATABASE :-
    Will create a MySQL database
    CREATE DATABASE database_name ;

    CREATE TABLE :-
    Create a table on the database you are currently logged into.

    INSERT STATEMENTS :-
    INSERT INTO table_name ( `col_A`, `col_B`, `col_C`) VALUES ( `col_A_data`, `col_B_data`, `col_C_data`) ;

    REPLACE STATEMENTS :-
    REPLACE INTO table_name ( `col_A`, `col_B`) VALUES ( `col A data`, `col B data`) ;

    UPDATE STATEMENTS :-
    UPDATE table_name SET col_B='new_data' WHERE col_A='reference_data' ;

    The above commands will update a row's columns with the new values which are specified with in the SET of section as well as database row to update in specified by.

    Comment


    • #3
      # CREATE DATABASE
      CREATE DATABASE database_name ;

      Will create a MySQL database :- You may have to ensure that the user you used to log in has enough privileges to create databases. Some web hosting companies do not allow their customers to create databases -- as they have already created a couple databases for you. In this case you should already have enough privy's to create tables on the already created databases. Check with your hosting provider to see what the proper database names are and what the usernames and passwords are for the database(s).

      --------------------------------------------------------------------------------------------------

      # SELECT STATEMENTS
      SELECT * FROM table_name WHERE 1 ;

      Returns all rows and all columns from table_name.. All rows is specified by the * (asterisk) symbol between SELECT and FROM.

      Example:
      SELECT * FROM music WHERE 1;

      Comment


      • #4
        Select count(*) from table;
        SELECT column_name(s)
        FROM table_name
        WHERE column_name LIKE pattern
        and there are so many queries exist. But for all the most common queries needed are select, update, delete, create.

        Comment

        Working...
        X