Difference between revisions of "MySQL basics"
Line 50: | Line 50: | ||
== Inserting data into a table == | == Inserting data into a table == | ||
Two formats: | |||
INSERT INTO table_name SET | INSERT INTO table_name SET | ||
Line 60: | Line 63: | ||
->; | ->; | ||
OR | |||
INSERT INTO table_name | |||
-> (columnName1, columnName2, etc...) | |||
-> VALUES (value1, value2, etc...); | |||
mysql>SELECT * FROM table_name; | |||
mysql>SELECT columnName1, columnName2, ... FROM table_name; | |||
== Modify Columns with Functions == |
Revision as of 19:22, 16 July 2007
Getting Started with MySQL
Connecting to MySQL
To access a MySQL db you need:
- user name and password
- host name or IP
- name of db
Two ways to access MySQL directl
- command line:
- telnet
- SSH (recommended due to enhanced security)
- MySQL client programs [
mysql, mysqladmin, mysqldump
]
To access a database from the command line
mysql -u username -ppassword -h hostname databasename
Note: There is no space between the -p and the password. Password after -p is optional here. If left blank, you will be prompted to enter your password.
Using MySQL Client Programs
Install the client programs
Basic Commands
Virtually all commands are terminated with a semicolon.
The prompt '->' means MySQL is waiting for more instructions or the semicolon is missing.
Cancel current command \c
and press Enter.
MySQL will ignore anything in a command that ends with \c
and go back to beginning.
Type exit
or quit
and press Enter anytime you want to exit. These commands do not require a semicolon.
show databases;
drop database <db_name>;
create database <db_name>;
use <db_name>;
show <table_name>;
describe <table_name>;
drop table <table_name>;
Inserting data into a table
Two formats:
INSERT INTO table_name SET
-> columnName1 = value1,
-> columnName2 = value2,
-> etc...
->;
OR
INSERT INTO table_name -> (columnName1, columnName2, etc...) -> VALUES (value1, value2, etc...);
mysql>SELECT * FROM table_name;
mysql>SELECT columnName1, columnName2, ... FROM table_name;