MySQL

From SHellium Wiki
Jump to: navigation, search
Geographylogo.png In other languages: English | Afrikaans | Albanian | Arabic | Brazilian | Bulgarian | Catalan | Chinese | Croatian | Czech | Danish | Dutch | Esperanto | Estonian | Filipino | Finnish | Flemish | French | German | Greek | Hebrew | Hindi | Hungarian | Indonesian | Italian | Japanese | Latvian | Lithuanian | Macedonian | Malay | Malayalam | Norwegian (Bokmål) | Norwegian (Nynorsk) | Persian | Polish | Portuguese | Romanian | Russian | Serbian | Slovak | Slovenian | Spanish | Swedish | Turkish | Ukrainian | Urdu

Here's a quick tutorial on how to create tables and query the MySQL server on the shell.

  • You've got to have an MySQL account on Shellium first.
  • Connect to your MySQL account by logging in to your shell account using SSH then type mysql.
  • Type CREATE DATABASE <database name>;
  • Type USE <database name>;
  • To create a table in the database:

Type

 CREATE TABLE <table name> (<variable name> <data type>, <variable name> <data type>, ...);

A list of SQL data types can be found at: List of SQL data types

  • To add values to your newly created table:

Type

 INSERT INTO <table name> VALUES 
 (<add one row of your values, using ' ' marks for non-numeric data and separating data with commas>);

This must be done for each row you wish to add to the table.

  • To query a table's data in the database:

Type

 SELECT <variable name or *> FROM <table name>;
  • To update a table's data in the database:

Type

 UPDATE <table name> SET <variable name> = <value>, <variable name> = <value>...;  
  • To delete all table's data in the database:

Type

 DELETE FROM <table name>;
  • To delete some table's data in the database:

Type

 DELETE FROM <table name> WHERE <criteria>;

e.g

 DELETE FROM users WHERE name = 'lame';

Other queries and commands can be found here: SQL Tutorial

  • To finish your database and log out of the SQL server, type \q then log out of the shell.

Alternatively, you can combine all of your SQL commands into a text file and direct it to MySQL with the following command:

 mysql -u <user name> -p <password> -h <host> <database name> <name of text file>

Files containing SQL commands generally have the ".sql" suffix (e.g. commands.sql).

Personal tools
Namespaces

Variants
Actions
Navigation
Indexes
SHellium Sites
Toolbox