May 4, 2010

Install MySQL

I just referenced this section of a file on my laptop because it has direct links and I was too lazy to think through installing mysql. Then, I decided to post it so I can link to it from another post I'm writing. Enjoy.

Installation of MySQL v5.1

  1. Open the Safari browser then go to http://dev.mysql.com/downloads/mysql/5.1.html
  2. Download the latest version (today it's 5.1.46) either 32 or 64 bit (we use 32)
  3. Note: I recommend the DMG version, instead of the TAR archive because it has a handy pkg that, with one click, sets mysql server to run at startup.
    Snow Leopard (10.6):
    click the "Download" button under Mac OS X ver. 10.6 (x86, 32-bit), DMG Archive
    or
    Leopard (10.5):
    Mac OS X 10.5 (x86, 32-bit), Compressed DMG Archive
  4. On the next screen, you can ignore the login boxes by choosing

    "» No thanks, just take me to the downloads!"

    and select a mirror
  5. Double click on the mysql-5.1.46-osx10.6-x86.dmg file in the window opened by the download.
  6. Click the mysql-5.1.46-osx10.6-x86.pkg file to install mysql
  7. Optionally, once done, double click the "MySQLStartupItem.pkg" to automatically configure your Mac to launch the mysql server on startup
  8. Start the database by entering, /usr/local/mysql/bin/mysql –u root –p (no password needed).
  9. NOTE: if you get the error:
    “Can't connect to local MySQL server through socket '/tmp/mysql.sock'”
    Then, that means the mysql server is not running. One work-around to solve this problem is to enter a command similar to the following:
    sudo /usr/local/mysql/bin/mysqld_safe
    (enter your OS X login password, when prompted) Then, open a new terminal window and proceed
  10. List all databases by entering,
    SHOW DATABASES; 
  11. Create a new database,
    CREATE DATABASE myDatabase
  12. where myDatabase is the name of the new database.

  13. Use the database by entering, USE myDatabase
  14. Create a table in the new database by entering
    CREATE TABLE example_table (
             id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
             data VARCHAR(100),
             cur_timestamp TIMESTAMP(8)
           );
  15. Display the table by entering
    SHOW TABLES;
  16. Add a value to the table by entering
    INSERT INTO example_table (data) VALUES (‘the current time is’)
  17. View the all data in the table by entering
    SELECT * FROM example_table;
  18. In order to create users, enter
    CREATE USER ‘userBob’@’localhost’ INDENTIFIED BY ‘s3kr1tP4$$W0RD’;
  19. In order to grant permissions to users for local and remote connections to the database, enter
    GRANT ALL PRIVILEGES on myDatabase.* TO 'userBob'@’%’

No comments:

Post a Comment