Difference between revisions of "MySQL basics"
Line 48: | Line 48: | ||
<code>drop table <table_name>;</code> | <code>drop table <table_name>;</code> | ||
== Inserting data into a table == | |||
INSERT INTO table_name SET | |||
-> columnName1 = value1, | |||
-> columnName2 = value2, | |||
-> etc... | |||
->; |
Revision as of 18:53, 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
INSERT INTO table_name SET
-> columnName1 = value1,
-> columnName2 = value2,
-> etc...
->;