Working with data 7
W
ORKING WITH DATA
If you are using CocoaMySQL, go to the Query tab. If you are using the command line,
make sure you are in the mysql command line, and remember to end your statements with
semicolons.
From this point on, I'm assuming that you have access to a MySQL database and that your
username and password have been set up to let you work on that database.
Connect
If you are not connected to your MySQL server, connect to your server the same way you
did earlier.
Change password
It is a good idea to change your password regularly. Usually, your initial password is sent to
you by way of e mail. E mail is notoriously insecure, so it is always a good idea to change
your password as soon as you connect the first time.
set password = old_password(`
NEWPASSWORD
')
Choose database
In CocoaMySQL, you'll choose your database from the pull down menu in the upper left.
On the command line, you'll choose your database by typing use
DATABASENAME
; and
pressing the return key on your keyboard.
Choose the music database.
About Tables and Columns
All of your data in MySQL is stored in tables. When you view tables, they look a lot like
spreadsheets. Each table consists of rows and columns. A row is one record; it is one set of
data. A column is a field: it is one piece of data that each record has.
For example, if you are keeping a database of your record albums, you will have a row for
Alice Cooper's Brutal Planet . You will have a column for the artist's name ( Alice Cooper )
and the album name ( Brutal Planet ).
Basic field types
In MySQL, you must specify what kind of data will go into columns. The two field types
you'll use most often are probably varchar and int. These are strings or text, and numbers.
The title of an album and the artist is an example of text. If you also keep track of the year
that the album came out, this is a number.
With varchar, you need to specify the maximum size of the text. If you specify a size that is
too low, extra text will be truncated. You can always go back and change your mind,
however.