Penguins Unbound
User:goeko > Database/SQL > MySQL > Useful Commands

Useful Commands

Page last modified 16:02, 13 Sep 2011 by goeko
    Table of contents
    No headers

    I have collected some commands I found useful.

     

    To see all databases

    use mysql;
    select * from db;
    select Db from db;
    

    or

    show databases
    

     

    To use a databse

    use {database_name}
    

     

    To Show tables

    show tables;
    

     

    To see table colums and info

    describe {tablename};
    

     

    To list results of a query vertically you can add a '\G' to the end of the query.

    select * from mysql.user where user='fred' \G
    

    (Notice there is no ';' at the end of that query, just the '\G')

     

    To get info about a table.  Notice the syntax is not what I would expect,

    use mysql;
    show table status like 'user';
    

    or if you want to see info about all the tables in a database

    show table status in mysql;
    

    http://dev.mysql.com/doc/refman/4.1/...le-status.html

     

    There are also several useful "SHOW" commands, check out the documentation.

    http://dev.mysql.com/doc/refman/4.1/en/show.html

     

    To see mysql variables, seting for the mysql server

    SHOW VARIABLES;
    SHOW VARIABLES LIKE '%size%';
    SHOW GLOBAL VARIABLES LIKE '%size%';

    http://dev.mysql.com/doc/refman/5.1/...variables.html

    Powered by MindTouch Core