Sunday, August 28, 2011

Useful MySQL commands

Get help
shell> mysql --help
Connect to the server
shell> mysql -h hostname -u username -p database_name# hostname may be omitted for localhost
Disconnect from the server
mysql> /q # or QUIT
Grant privileges for a user
mysql> GRANT ALL ON *.* TO 'username'@'ip_address' IDENTIFIED BY 'password';
Switch database
mysql> use database_name
Display all databases
mysql> show databases;
Display all tables
mysql> show tables;
Get information of a table
mysql> describe table_name;

No comments:

Post a Comment