Siddesh BG's Build Release Config mgmt Blog

  • Subscribe to our RSS feed.
  • Twitter
  • StumbleUpon
  • Reddit
  • Facebook
  • Digg

Saturday, 26 September 2009

List of useful mysql commands

Posted on 05:19 by Unknown
Lets start with mysql database administration commands.
1) /bin/mysql -h hostname -u root -p #To login
2) SHOW DATABASES; # List all databases
3) DROP TABLE [table name]; #To delete a table
4) To create a new user - Login as root, switch to mysql db, make the user, update privileges
mysql) USE mysql;
mysql) INSERT INTO USER (Host, User, Password) VALUES ('%', 'username', PASSWORD('Password'));
mysql) flush privileges;
5)To change a password
/bin/mysqladmin -u username -h hostname -p password 'new-password'
or
mysql> SET PASSWORD FOR 'User'@'hostname'=PASSWORD('Passwd');
mysql> flush privileges;
6) To list available users - Login as root;
Use mysql;
SELECT USER FROM user;
SELECT USER,PASSWORD FROM user; #To know whether password is set fot users

Here are some more use full commands

1) CREATE DATABASE 134a;
2) DROP DATABASE 134a;
3) USE 134a;
4) CREATE TABLE president (
last_name VARCHAR(15) NOT NULL,
first_name VARCHAR(15) NOT NULL,
state VARCHAR(2) NOT NULL,
city VARCHAR(20) NOT NULL,
birth DATE NOT NULL DEFAULT '0000-00-00',
death DATE NULL
);
5) SHOW TABLES; #list tables
6) DESCRIBE president; #to view structure of table
7) INSERT INTO president VALUES ('Washington','Bush','George', 'VA', 'New York', '19320212', '19991214');
8) SELECT * FROM president;
9) SELECT * FROM president WHERE state="VA"; #selecting rows by using WHERE clause
10) SELECT state,first_name,last_name FROM president; #selecting specific columns
11) DELETE FROM president WHERE first_name="George"; # Deleting selected row
12) UPDATE president SET state="CA" WHERE first_name="George"; #Modify entries
13) LOAD DATA LOCAL INFILE 'president_db' INTO TABLE president; #Loading your data from a file into a table. Also try "mysql -u USERNAME -p < my_mysql_file
14) SELECT * FROM president WHERE death=NULL; # or WHERE death IS NULL #list president who are alive
15) SELECT last_name, birth FROM president WHERE birth < '1800-09-01';
16) SELECT last_name, birth FROM president ORDER BY birth ASC LIMIT 1; #select president who was born first
17) SELECT state, count(*) AS times FROM president GROUP BY state ORDER BY times DESC LIMIT 5; # Names of first 5 states in which the greatest number of presidents have been born
18) SELECT * FROM president WHERE (YEAR (now())-YEAR(birth)) < 60; #President who have been born in last 60 years
19) SELECT last_name, birth, death, FLOOR ((TO_DAYS(death)-TO_DAYS(birth))/365) AS age FROM president WHERE death IS NOT NULL ORDER BY age DESC LIMIT 10; #President who have died by their age in descending order
20) SELECT last_name, address, test_date, score FROM test, student WHERE test.ssn = student.ssn;

You can refer mysql.com/documentation/index.html and
mysql.com/documentation/bychapter/manual_Introduction.html for more details
Email ThisBlogThis!Share to XShare to FacebookShare to Pinterest
Posted in mysql | No comments
Newer Post Older Post Home
View mobile version

0 comments:

Post a Comment

Subscribe to: Post Comments (Atom)

Popular Posts

  • Solution to Project Euler Problem 10 - Find the sum of all the primes below two million
    http://projecteuler.net/problem=10 Problem The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17. Find the sum of all the primes below two mi...
  • Fortify scan automation steps for analyzing c/c++ code (Makefiles)
    I wrote in my previous blog about installing and configuring Fortify client. This blog presents standard steps to automate fortify scan for ...
  • Posting a JIRA bug using Perl Mechanize
    Perl provides modules which can be used as command line browser to automate tasks dependent on web pages. Among them LWP and mechanize are i...
  • jenkins error: java.io.IOException: Authentication method password not supported by the server at this stage
    When I tried to add a node to jenkins/hudson using ssh as launch method, the authentication keeps on failing with the below error. [12/15/11...
  • Unable to resolve target system name - a DNS problem
    I was not able to ping to any machines from my Windows 2003 server. I did following steps to debug & resolve the issue, which was relate...
  • Installing and configuring Fortify on Linux and Windows machines
    Installing Fortify on Linux (RHEL 5 32 bit) Download Fortify archive Fortify-360-2.6.5-Analyzers_and_Apps-Linux-x86.tar.gz and extract it to...
  • Perforce - can't edit exclusive file already opened
    In perforce, whenever a binary file like doc, xls or ppt files are checked out, it is opened in exclusive lock mode. So no other person can ...
  • Perforce and cygwin
    Are you a command-line freak ? Do you want your automated shell scripts to run on Windows ? Do you wish to work with Perforce commands on Cy...
  • Using BUILD_LOG_REGEX in jenkins email notification
    Jenkins provide 'Email-ext' plugin, which  allows to configure every aspect of email notifications. One of my requirement is to send...
  • 0509-036 Cannot load program p4 because of the following errors
    Here is the full description of error ............ bash-3.00# p4 info exec(): 0509-036 Cannot load program p4 because of the following error...

Categories

  • AIX
  • AIX ssh
  • ANT
  • apache
  • appliance
  • awk
  • branching
  • build-failures
  • cgi-perl
  • code-signing
  • commands
  • continuous Integration
  • cvs
  • cygwin
  • DNS
  • Drupal
  • EPM
  • euler
  • Fortify
  • hadoop
  • hpux
  • html
  • InstallShield
  • iptables
  • iso
  • jenkins-hudson
  • Jira
  • kiwi
  • linux
  • Makefile
  • maven
  • Miscellaneous
  • mysql
  • nexus
  • NFS
  • package
  • Perforce
  • Perl
  • php
  • rbuilder
  • rpath
  • rpm
  • rsync
  • Solaris
  • ssh
  • SuseStudio
  • tinderbox
  • unix
  • Visual studio 2008
  • vmware
  • war
  • webserver
  • wget
  • windows
  • xterm

Blog Archive

  • ►  2013 (12)
    • ►  December (1)
    • ►  July (2)
    • ►  April (2)
    • ►  March (2)
    • ►  February (3)
    • ►  January (2)
  • ►  2012 (43)
    • ►  December (2)
    • ►  November (1)
    • ►  October (4)
    • ►  September (7)
    • ►  August (5)
    • ►  July (4)
    • ►  June (2)
    • ►  May (3)
    • ►  April (4)
    • ►  March (3)
    • ►  February (1)
    • ►  January (7)
  • ►  2011 (23)
    • ►  December (4)
    • ►  November (9)
    • ►  October (4)
    • ►  September (1)
    • ►  June (2)
    • ►  May (1)
    • ►  April (1)
    • ►  March (1)
  • ►  2010 (15)
    • ►  December (2)
    • ►  November (1)
    • ►  September (3)
    • ►  April (1)
    • ►  February (6)
    • ►  January (2)
  • ▼  2009 (28)
    • ►  November (5)
    • ►  October (3)
    • ▼  September (2)
      • List of useful mysql commands
      • How to redirect stdout & stderr to a file using tee?
    • ►  August (1)
    • ►  July (1)
    • ►  June (5)
    • ►  May (3)
    • ►  April (1)
    • ►  February (2)
    • ►  January (5)
  • ►  2008 (20)
    • ►  December (6)
    • ►  November (3)
    • ►  October (1)
    • ►  September (1)
    • ►  July (8)
    • ►  June (1)
Powered by Blogger.

About Me

Unknown
View my complete profile