faqts : Computers : Databases : MySQL : Shell Commands : mysql

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

388 of 425 people (91%) answered Yes
Recently 9 of 10 people (90%) answered Yes

Entry

What are some basic MySQL commands that I should know?

Jul 16th, 2000 05:47
t dinesh, Philip Olson,


Some basic / useful commands are as follows :
While NOT yet connected to MySQL :
- connect to MySQL
   mysql -uUsername -pPassword
- connect to MySQL , directly to a database
   mysql -uUsername -pPassword DbName
- upload a MySQL schema into my Database
   mysql -uUsername -pPassword DbName < schema.sql
- dump a DB (copy DB for backup)
   mysql -uUsername -pPassword DbName > contents-of-db.sql
While connected to MySQL :
- display all databases
   show databases;
- connect to a Database
   use DbName;
- view tables of a Database (must be connected to the Database)
   show tables;
- view contents of a table (must be connected to the Database)
   select * from TableName;
Thoughts related to the above
- If you want to be prompted for your password rather then type
  it in the command line directly, just use -p vs -pPassword
- If you are not using MySQL as your local host, use the -h option so :
   mysql -uUsername -p -hHostname
- Keep in mind that there are many ways to do everything in 
  most programs, languages ... MySQL included.
- A useful Alias is as follows.  You'd put this in your .bashrc 
  file which is usually located in your user root directory (~username/)
     alias my='mysql -uUsername -p'
  that way it cuts down on typing.  for example, to connect to a 
  db you just do :
     my DbName
  and then enter your password (DON'T store your MySQL  
  password in .bashrc!!!)
- Using a ' ; ' after a command while in MySQL executes that command
---
This should get you going ... ;)