Installation of MySQL v5.1
- Open the Safari browser then go to http://dev.mysql.com/downloads/mysql/5.1.html
- Download the latest version (today it's 5.1.46) either 32 or 64 bit (we use 32) 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.
- On the next screen, you can ignore the login boxes by choosing
"» No thanks, just take me to the downloads!"
and select a mirror - Double click on the mysql-5.1.46-osx10.6-x86.dmg file in the window opened by the download.
- Click the mysql-5.1.46-osx10.6-x86.pkg file to install mysql
- Optionally, once done, double click the "MySQLStartupItem.pkg" to automatically configure your Mac to launch the mysql server on startup
- Start the database by entering, /usr/local/mysql/bin/mysql –u root –p (no password needed). NOTE: if you get the error:
- List all databases by entering,
SHOW DATABASES;
- Create a new database,
CREATE DATABASE myDatabase
- Use the database by entering, USE myDatabase
- 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) );
- Display the table by entering
SHOW TABLES;
- Add a value to the table by entering
INSERT INTO example_table (data) VALUES (‘the current time is’)
- View the all data in the table by entering
SELECT * FROM example_table;
- In order to create users, enter
CREATE USER ‘userBob’@’localhost’ INDENTIFIED BY ‘s3kr1tP4$$W0RD’;
- In order to grant permissions to users for local and remote connections to the database, enter
GRANT ALL PRIVILEGES on myDatabase.* TO 'userBob'@’%’
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
“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
where myDatabase is the name of the new database.
No comments:
Post a Comment