MySQL
From SHellium Wiki
(Redirected from Mysql)
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).