一、开发环境的安装
由于以前没有用过非windows系统,也没用过rails,所以一开始对开发环境的安装真是一头雾水,于是只有疯狂的google。以前简单用过一两天redhat,感觉安装个软件不是一般麻烦,在网上看到都说mac好用,可用了才
发现跟linux一样,安装个开发环境不是这么容易的,来来回回折腾了一周多时间。下面是我这一周多时间折腾出来的总结。
1、
mysql安装
mysql的安装可以通过macport来安装,也可以直接下载安装包安装,我两种都试过了,真是什么事都遇到了,只有都试一遍。
1.1、从macport安装mysql
macport是什么及怎么用在这里就不多讲了,以下是几个使用macport的文章,一看就会了。安装过程参考 http://beike.javaeye.com/blog/617341和 http://hqman.javaeye.com/blog/258979。
1.1.1 安装mysql
1)查找可安装的mysql
port search mysql
2)安装mysql5
sudo port install mysql5-server
###########################################################
# A startup item has been generated that will aid in
# starting mysql5-server with launchd. It is disabled
# by default. Execute the following command to start it,
# and to cause it to launch at startup:
#
# sudo port load mysql5-server
###########################################################
---> Installing mysql5-server @5.1.50_0
******************************************************
* In order to setup the database, you might want to run
* sudo -u _mysql mysql_install_db5
* if this is a new install
******************************************************
---> Activating mysql5-server @5.1.50_0
---> Cleaning mysql5-server
3)安装mysql的初始库。
sudo /opt/local/lib/mysql5/bin/mysql_install_db --user=mysql
Installing MySQL system tables...
OK
Filling help tables...
OK
To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system
PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:
/opt/local/lib/mysql5/bin/mysqladmin -u root password 'new-password'
/opt/local/lib/mysql5/bin/mysqladmin -u root -h bogon password 'new-password'
Alternatively you can run:
/opt/local/lib/mysql5/bin/mysql_secure_installation
which will also give you the option of removing the test
databases and anonymous user created by default. This is
strongly recommended for production servers.
See the manual for more instructions.
You can start the MySQL daemon with:
cd /opt/local ; /opt/local/lib/mysql5/bin/mysqld_safe &
You can test the MySQL daemon with mysql-test-run.pl
cd /opt/local/mysql-test ; perl mysql-test-run.pl
Please report any problems with the /opt/local/lib/mysql5/bin/mysqlbug script!
1.1.2 配置mysql
1)设置和取消
开机时自动启动mysql
设置开机自动启动mysql:
sudo launchctl load -w /Library/LaunchDaemons/org.macports.mysql5.plist
取消开机自动启动mysql的命令好象是下面的命令,在网上看到过,但后来找不到了:
sudo launchctl load -w /Library/LaunchDaemons/org.macports.mysql5.plist
2)通过alias启动mysql
为了简化在命令行中启动和关闭mysql的命令,可以通过设置aliases来实现,aliases就象windows中的快捷方式:
打开这个配置文件,输入以下内容:
mate ~/.profile
alias mysqlstart='sudo /opt/local/bin/mysqld_safe5 &'
alias mysqlstop='/opt/local/bin/mysqladmin5 -u root -p shutdown'
通过命令启动mysql:
mysqlstart
[1] 62478
如果没有设置aliases,则用以下命令来启动
/opt/local/share/mysql5/mysql/mysql.server start
3)验证mysql安装成功
通过以下命令来登录mysql:
mysqladmin5 -u root -p ping
或
mysql5 -u root –p
但很不幸,在执行
mysqladmin5 -u root -p ping
报以下错误:
error: 'Can't connect to local MySQL server through socket '/opt/local/var/run/mysql5/mysqld.sock' (2)'
Check that mysqld is running and that the socket: '/opt/local/var/run/mysql5/mysqld.sock' exists!
而执行
mysql5 -u root –p时报以下错误
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/opt/local/var/run/mysql5/mysqld.sock' (2)
在上面找到的文章中发现也有提到这个问题,于是按照文章中的步骤来试着解决(参考 http://beike.javaeye.com/blog/617341 ):
mate /opt/local/etc/mysql5/my.cnf并输入以下内容:
[mysqld_safe]
socket = /tmp/mysql.sock
但是修改完后执行mysql5 -u root –p还是报相同错误。
后来在javaeye.com上提问找到了答案( http://www.javaeye.com/problems/49993)。在启动时要增加参数
-host 127.0.0.1,用下面命令就可以启动了:
mysql5 -u root –host 127.0.0.1 –p
4)修改root帐户密码
mysqladmin5 -u root -h 127.0.0.1 password "ilovebritney"
1.2、从mysql官网上下载安装包进行安装
1.2.1
卸载已经安装过的mysql
通过以下命令或步骤来卸载已经安装过的mysql(参考http://qingbo.net/picky/510-snowleopard-ruby-mysql.html):
关掉 MySQL Server
sudo rm /usr/local/mysql
sudo rm -rf /usr/local/mysql*
sudo rm -rf /Library/StartupItems/MySQLCOM
sudo rm -rf /Library/PreferencePanes/My*
编辑文件 /etc/hostconfig,删掉这一行:MYSQLCOM=-YES-
rm -rf ~/Library/PreferencePanes/My*
sudo rm -rf /Library/Receipts/mysql*
sudo rm -rf /Library/Receipts/MySQL*
1.2.2 安装mysql
参考(http://2015.javaeye.com/blog/615152和http://hi.baidu.com/beyond_javy/blog/item/9d884a8259c19baf0df4d224.html)
1)下载安装包
从mysql官网上下载安装包mysql-5.1.50-osx10.6-x86_64.dmg进行安装。
2)安装mysql
双击mysql-5.1.50-osx10.6-x86_64.pkg进行mysql安装。
3)安装自动启动项目
双击MySQLStartupItem.pkg进行mysql启动项目,安装完之后就可以在电脑启动系统时自动运行mysql服务,它安装在/Library /StartupItems/MySQL/。如果你不想系统启动时运行mysql服务,请不要安装。如果你在安装后又不想使用,请删除/Library /StartupItems/MySQL/这个目录。
4) 安装系统偏好设置里的设置项
双击MySQL.prefPane,安装完后会在系统偏好增加一个mysql设置项,可以通过它来启动和关闭MySQL。
1.2.3 配置mysql
1)修改root帐户密码
执行这个命令可以修改mysql的密码:
/usr/local/mysql/bin/mysqladmin -u root password ilovebritney
2) 通过alias启动mysql
如果要快捷启动,则要先设置aliases,再用aliases来启动:
mate ~/.profile
alias mysql='/usr/local/mysql/bin/mysql'
alias mysqladmin='/usr/local/mysql/bin/mysqladmin'
以后就可以直接用mysql和mysqladmin来进行操作了。
3)登录mysql
通过mysql -u root –p来登录mysql。
4)修改mysql密码
mysqladmin -u root password ilovebritney