1. #1
    jbrent95
    jbrent95's Avatar Become A Pro!
    Join Date: 12-07-09
    Posts: 1,221
    Betpoints: 1450

    Any advice for a mySQL newb?

    I've decided to take the time and put in the effort to learn some mySQL and mySQL Workbench basics. Co you have any advice as to how to get started, or can you recommend a tutorial or reference?

    I've started with a copy of Baseball Hacks and a beginning mySQL reference book, but I don't seem to be getting very far.

  2. #2
    splash
    splash's Avatar Become A Pro!
    Join Date: 05-25-09
    Posts: 38

    What are you trying to do with it? I started learning about 6 months ago. I'm lucky in that I see real life practical applications of MSSQL at work, so that helps. The best way to learn is to build or get a hold of a database and practice pulling the data you need.
    Points Awarded:

    jbrent95 gave splash 2 SBR Point(s) for this post.


  3. #3
    jgilmartin
    jgilmartin's Avatar Become A Pro!
    Join Date: 03-31-09
    Posts: 1,119

    Quote Originally Posted by splash View Post
    The best way to learn is to build or get a hold of a database and practice pulling the data you need.
    This. It is a little bit confusing at first, but what I did was first did the actual database creation (i.e. setting up the table and fields) using phpmyadmin. Then, I read and followed the tutorial at http://www.tizag.com/mysqlTutorial/ to learn how to connect to the database. From there I just looked up whatever I wanted to do in the Tizag tutorial.

    Two resources that helped a lot:
    http://www.pantz.org/software/mysql/mysqlcommands.html - Has some more advanced code examples
    http://csv2sql.evandavey.com/ - Converts a CSV file into SQL statements
    Points Awarded:

    jbrent95 gave jgilmartin 10 SBR Point(s) for this post.


  4. #4
    Optional
    Optional's Avatar Moderator
    Join Date: 06-10-10
    Posts: 57,803
    Betpoints: 9216

    There are about 50 self paced free training courses here: scriptschool.com

    Got me started from zero knowledge to creating php/mysql database driven websites in no time.
    Points Awarded:

    jbrent95 gave Optional 10 SBR Point(s) for this post.


  5. #5
    Flight
    Update your status
    Flight's Avatar Become A Pro!
    Join Date: 01-27-09
    Posts: 1,979

    For loading CSV data into SQL, MySQL Workbench 5.2.25 supports the LOAD DATA INFILE command.

    Code:
    LOAD DATA LOCAL INFILE 'C:/Data/NFL2009_season.csv'
        INTO TABLE db.nfl2009season
        FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
        LINES TERMINATED BY '\n';
    The Baseball Hacks book should get you started coming up with ideas for queries. It is really limitless with what you can do, so start off by asking questions like "What do I want to see?" For instance, I want to see how the Seahawks fared against the spread in 2008, a single SQL query should give me that information. Now put some thought into what that query should be. Then you can tweak your parameters further, like how did the Seahawks do against the spread when the total was above 45?

    This is where having SQL queries available becomes really powerful - instant custom views into large data sets.
    Points Awarded:

    jbrent95 gave Flight 10 SBR Point(s) for this post.


  6. #6
    Flight
    Update your status
    Flight's Avatar Become A Pro!
    Join Date: 01-27-09
    Posts: 1,979

    Another tip: Stay away from web-based stuff. Do everything local, at least for learning. You don't need php, phpmyadmin, html, etc. Keep it simple until you own a data set and know how to use it.

  7. #7
    jbrent95
    jbrent95's Avatar Become A Pro!
    Join Date: 12-07-09
    Posts: 1,221
    Betpoints: 1450

    Quote Originally Posted by Flight View Post
    For loading CSV data into SQL, MySQL Workbench 5.2.25 supports the LOAD DATA INFILE command.

    Code:
    LOAD DATA LOCAL INFILE 'C:/Data/NFL2009_season.csv'
        INTO TABLE db.nfl2009season
        FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
        LINES TERMINATED BY '\n';
    The Baseball Hacks book should get you started coming up with ideas for queries. It is really limitless with what you can do, so start off by asking questions like "What do I want to see?" For instance, I want to see how the Seahawks fared against the spread in 2008, a single SQL query should give me that information. Now put some thought into what that query should be. Then you can tweak your parameters further, like how did the Seahawks do against the spread when the total was above 45?

    This is where having SQL queries available becomes really powerful - instant custom views into large data sets.

    The problem that I have with the Baseball Hacks guide is loading the bbdatabank.sql data. Everytime I try to load it from the command line, I get an access denied error. When I completely start over and try to load data file with Workbench, I get the tables but there is no data. I am assuming, that after going through a tutorial or 2, I will be able to get past this step.

  8. #8
    Flight
    Update your status
    Flight's Avatar Become A Pro!
    Join Date: 01-27-09
    Posts: 1,979

    Does Workbench issue an error? (other than stating 0 records inserted)

    Are you trying to load CSV data, or are you running a series of INSERT queries?

    If you are using CSV data, make sure your LOAD DATA query matches your csv format. The sample query I gave usually works. If there is a header line in the CSV data, don't forget to add "IGNORE 1 LINES" to the query.

    If you are still struggling, check the reference manual for LOAD DATA.

  9. #9
    splash
    splash's Avatar Become A Pro!
    Join Date: 05-25-09
    Posts: 38

    Quote Originally Posted by Flight View Post
    Another tip: Stay away from web-based stuff. Do everything local, at least for learning. You don't need php, phpmyadmin, html, etc. Keep it simple until you own a data set and know how to use it.
    I've been using phpmyadmin. Is workbench better? I do find phpmyadmin annoying to use. I'm used to MS SQL Server Management Studio at work. Is there a better gui for mysql?

  10. #10
    roasthawg
    roasthawg's Avatar Become A Pro!
    Join Date: 11-09-07
    Posts: 2,990

    Setup xampp on your computer.

  11. #11
    gohabsgo
    gohabsgo's Avatar Become A Pro!
    Join Date: 03-19-10
    Posts: 1,903
    Betpoints: 204

    This site is the best for the basic stuff

    http://www.w3schools.com/sql/default.asp

  12. #12
    Flight
    Update your status
    Flight's Avatar Become A Pro!
    Join Date: 01-27-09
    Posts: 1,979

    Quote Originally Posted by splash View Post
    I've been using phpmyadmin. Is workbench better? I do find phpmyadmin annoying to use. I'm used to MS SQL Server Management Studio at work. Is there a better gui for mysql?
    MS SQL Studio is fine. So is MySQL Workbench.

    My point was to simplify the learning curve and get to the stuff that matters - the data. Don't get slugged down in learning a new language like PHP. phpmyadmin is nice for remote administration. For the newb in this thread, just stick to your local PC.

    Quote Originally Posted by roasthawg
    Setup xampp on your computer.
    Xampp is a great toolset and I recommend it - but again, not for newbs. Too much learning curve, too many tools, too many new languages. Go ahead and set it up since it's free and easy... but stick to the data! (I often find myself wasting time with tools and computer tasks when I should be focusing on sports data.)

  13. #13
    Maverick22
    Maverick22's Avatar Become A Pro!
    Join Date: 04-10-10
    Posts: 807
    Betpoints: 58

    Your best bet is to find an "SQL CookBook". Yea i know it sounds crazy.

    But what a book like this will do is detail "situations" and then show you how to solve them using a given language ( in this case, mysql)

    For example it might say... "How to determine what fields are present in table 1, but not in table 2","How To List All The Fields Sorted in descended order by last name", and so forth. I would check amazon, and look for a random page preview for something that does this...

    This will be alot easier than sitting down to a "mysql for beginners book"

  14. #14
    arwar
    arwar's Avatar Become A Pro!
    Join Date: 07-09-09
    Posts: 208
    Betpoints: 1544

    mySQL and PHP go hand in hand and both are open source (free) you can also install an Apache webserver (or IIS if you are m$oft type) all on your PC so your query results, etc. can be displayed in browser. i have whole library of mySQL & PHP .pdf books. if anyone is interested then PM

  15. #15
    uva3021
    uva3021's Avatar Become A Pro!
    Join Date: 03-01-07
    Posts: 537
    Betpoints: 381

    Download XAMPP

    http://sourceforge.net/projects/xampp/

    And I'd learn PHP, and you can use that to control your SQL database

  16. #16
    jbrent95
    jbrent95's Avatar Become A Pro!
    Join Date: 12-07-09
    Posts: 1,221
    Betpoints: 1450

    I finally figured out the proper procedure and syntax to load the bbdatabank database from the windows command prompt. I was never able to load it with MySQL Workbench. My next task will be to create a database from the Retrosheets play-by-play data.

  17. #17
    Miz
    Miz's Avatar Become A Pro!
    Join Date: 08-30-09
    Posts: 695
    Betpoints: 3162

    I have a very useful set of literature on this topic. You can PM me and I will email it to you.

    I worked through the example below and it really helped me begin to understand how to create and access tables in an efficient manner.

    I find that maximizing efficiency is just as important as knowing how to execute them in the command prompt.

    http://theopensourcery.com/mysload.htm

Top