Wednesday, September 10, 2014

Adventures With MySQL

What I knew

If you've read my intro post, you know that I'm just trying to build an app.

Turns out that to build this kind of app, I'll need to know a lot more than just the Android SDK. Because the app will involve a database, I'll need to learn how to use MySQL, a database system. And because I plan to develop a web service to go alongside the app, I'll need to learn all the languages involved in that.

So I bought another book: Learning PHP, MySQL, JavaScript, CSS, & HTML5 (3rd Edition) by Robin Nixon.


Going into today, I knew already that in the MySQL database management system (DBMS,) you can create databases. Each database is a collection of tables. Each table has columns and rows. Each column contains information of a certain kind, and each row represents one entry.


You might have a database called "library." A library is a collection of media. There are different kinds of media--say, books and movies. So, you might have one table called "books" and one called "movies". In the "books" table, you'd likely have columns like "title", "author", "ISBN", and "summary". Each row in that table would represent one book--like "The Bible", with author "God", some ISBN, and a summary like "the primary text of the Christian religion."

What I Learned Today

 You can manipulate databases from the Command Prompt. To do this, you use SQL (Structured Query Language,) which is somewhat intuitive (it's fairly similar to English.) SQL is a language, while MySQL is a DBMS (a system for managing databases.) In practical terms, if you learn SQL through experimentation, you get familiar with MySQL (or another DBMS--they're listed here, in order of popularity.) But conceptually, SQL is the language itself, while MySQL is the program that knows what to do with the language, i.e. creating, modifying, and viewing data as commands are given.

I learned how to create databases, create tables within databases, create users while granting them access to databases and/or tables, and more commands. (See below for details.)

I like the style of the Nixon book--it's direct and straightforward. Like any print source related to coding, it has gone out of date in minor ways quickly. Still, it's one of the most effective resources I've explored so far, and it feels worth the money I paid ($33 on Amazon.)

What Actually Happened Today

First problem: The WAMP (Windows, Apache, MySQL, and PHP) that the book suggests I use is called Zend Server. The book thinks Zend Server is free, probably because it (presumably) was free when the book was published. Zend Server is no longer free. So instead, I'm using a WAMP called EasyPHP.

The first problem this introduces is related to running SQL from the command line. The book tells you to type:

"C:\Program Files\Zend\MySQL55\bin\mysql" -u root

Of course, there's no Zend folder, so this doesn't work. Instead, you have to type:

"C:\Program Files (x86)\EasyPHP-DevServer-14.1VC11\binaries\mysql\bin\mysql" -u root

(Being a command line noob, it took me a few minutes to guess that I should be looking for a binary file named mysql. Before that, I tried typing this:

"C:\Program Files (x86)\EasyPHP-DevServer-14.1VC11\binaries\mysql" -u root

...which gives an error, because there's no binary file "mysql" in the "binaries" folder.)

Once I figured this out, I was good to go. I learned how to...

create databases
CREATE DATABASE publications;

create tables
USE publications;
CREATE TABLE classics;

create users and grant them access to those databases or to tables within databases
GRANT PRIVELEGES ON publications.classics TO 'jim'@'localhost'

I also learned about some of SQL's data types. I simply don't have time to recap everything I learn. (The book is over 600 pages long.) Hopefully this will be useful to people that know even less than I do about this stuff (hard to imagine since I'm such a noob.) At the very least, it helps me clarify my own understanding of the subjects.

--David Garrett
Prism Technologies, LLC

P.S. Your opinion is valuable! Was my color-coding helpful, or just distracting? What should I do differently? Use the comment section to your advantage!

No comments:

Post a Comment