Basic MySQL commands


These are some basic commands to use for MySQL:

 

  • Create a database from MySQL command line: CREATE DATABASE “database_name”;
  • Display a list of your available databases: SHOW DATABASES;
  • Select your database: USE “database_name”;
  • Create a table: CREATE TABLE “database_name” (id INT NOT NULL PRIMARY KEY AUTO_INCREMENT, any_string CHAR(25), any_int INT(10));
  • Create an entry in the table: INSERT INTO “database_name” (id, any_string, any_int) VALUES (NULL, ‘José’, ’56′);
  • Create entries: INSERT INTO “database_name” (id, any_string, any_int) VALUES (NULL, ‘Laura Ru’, ’47′), (NULL, ‘Julian Arto’, ’30′), (NULL, ‘James Dean’, ’82′);
  • Run a query on your database: SELECT * FROM “database_name”;
  • More advanced query: SELECT any_string, any_int FROM “database_name” ORDER BY any_int;
  • List the int in reverse order: SELECT any_string, any_int FROM “database_name” ORDER BY any_int DESC;

Please also visit: http://sql-ex.ru/ To learn and practice SQL/MySQL skills.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s