Database: MySQL: Commands

Web/GUI interface to MySQL

The most common way to manage MySQL databases is by using a program like PHPMyAdmin, which is probably the most popular way to manage MySQL databases that are used to support Web servers. There is also a GUI front end.

Command line interface

These commands can be entered from the command line after the MySQL server has been started, and after the MySQL command line interpreter has been started. See MySQL.

MySQL text commands in addition to standard SQL commands

Commands end with semi-colon, cancel a command with \c.
SELECT command
SELECTVERSION(); To display MySQL version.
SELECTUSER(); To display current user.
SELECTNOW(); Shows server time.
SELECTDATABASE(); Shows current database.
Useful Admin Commands
QUIT To quit interation with mysql command interpreter.
CREATEDATABASE dbname; Creates a database.
GRANTALL ON dbname.* TO user; Gives permission.
USEdbname Subsequent commands use dbname.
Working with a database
DESCRIBEtablename; Displays table field names and types.
LOADDATA LOCAL INFILE 'filepath'
INTO TABLE tablename;
Reads tab-separated rows of values into table. Can change separator.
SHOW command
SHOWDATABASES; To see which databases are available.
SHOWTABLES; Displays tables in current database.
SET command
SETPASSWORD
= PASSWORD('new pw');
;
Sets current user's password to 'new pw'.
SETPASSWORD FOR user
= PASSWORD('new pw');
;
Sets user's password to 'new pw'.