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 ... ;)
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment