最终环境 : ubuntu 10.10 + ruby 1.8.7 + rails 2.3.5 + mysql 5.1
换了新工作,重新搭建开发环境,鉴于之前mysql遇到问题,总是不好解决,束手无策,甚至找不到 mysql 安装哪去了,所以这次主要想编译安装mysql,这样有利于了解mysql

1,下载ruby1.8.7 (http://www.ruby-lang.org/en/news/2010/08/16/ruby-1-8-7-p302-is-released/)

wget ftp://ftp.ruby-lang.org/pub/ruby/1.8/ruby-1.8.7-p302.tar.bz2

2,安装依赖的库

sudo apt-get install build-essential 
sudo apt-get install autoconf 
sudo apt-get install zlib1g-dev 
sudo apt-get install openssl libssl-dev

3,编译安装ruby

tar -jxvf ruby-1.8.7-p302.tar.bz2 
cd ruby-1.8.7-p302/
autoconf
./configure --prefix=/usr/local/system/ruby
make
sudo make install

4,ruby 加到PATH 中

vim ~/.bashrc
export PATH="$PATH:/usr/local/system/ruby/bin"

5,ruby -v

安装rubygems(http://rubyforge.org/frs/?group_id=126&release_id=43601)

1,下载

wget http://rubyforge.org/frs/download.php/70696/rubygems-1.3.7.tgz

2,解压

tar -zvxf rubygems-1.3.7.tgz

3,安装

cd rubygems-1.3.7/
wxianfeng@ubuntu:~/Desktop/rubygems-1.3.7$ ruby setup.rb 
ERROR:  While executing gem ... (Errno::EACCES)
    Permission denied - /usr/local/system/ruby/lib/ruby/site_ruby/1.8/rubygems
wxianfeng@ubuntu:~/Desktop/rubygems-1.3.7$ sudo ruby setup.rb 
[sudo] password for wxianfeng: 
sudo: ruby: command not found
改变权限
cd /usr/local
sudo chmod -R 777 system/ 
再次安装就ok了,不然你以后还会遇到这个问题

4,gem -v

安装rails 2.3.5

>gem install rails -v 2.3.5 --no-ri --no-rdoc

编译安装 mysql

1,下载并且编译安装
download (http://downloads.mysql.com/archives.php?p=mysql-5.1) 从archives 找到 ,注意下载的是source包

sudo apt-get install g++ libncurses5-dev # 安装依赖的库
sudo  groupadd mysql  # 建立mysql用户组
sudo  useradd -g mysql mysql # 添加用户mysql
tar -zvxf mysql-5.1.51.tar.gz 
cd mysql-5.1.51/
./configure --prefix=/usr/local/system/mysql --with-charset=utf8 --with-collation=utf8_general_ci --with-extra-charsets=latin1(all) --with-plugins=innobase(all)  # config 很重要,括号里是或者
make
sudo make install
sudo cp support-files/my-medium.cnf /etc/my.cnf # 配置文件

注意mysql sock文件安默认装在tmp路径下 /tmp/mysql.sock,编译的时候 —with-plugins=all 建议加上 不然你会发现编译后不支持innodb引擎,那就麻烦了!

2, 初始化数据库并修改目录权限

cd /usr/local/system/mysql
sudo bin/mysql_install_db --user=mysql
sudo chown -R root .
sudo chown -R mysql /usr/local/system/mysql/var
sudo chgrp -R mysql .

3,启动mysql

bin/mysqld_safe --user=mysql &
netstat -antup | grep 3306
sudo cp /usr/local/system/mysql/share/mysql/mysql.server /etc/init.d/mysql
sudo killall mysqld # kill 刚刚启动的mysql
sudo /etc/init.d/mysql start|stop|restart|status # 重启mysql

4,添加PATH

>vim ~/.bashrc
export PATH="$PATH:/usr/local/system/mysql/bin"
wxianfeng@ubuntu:/usr/local/system/mysql/bin$ mysql --version
mysql  Ver 14.14 Distrib 5.1.51, for pc-linux-gnu (i686) using  EditLine wrapper

5, 修改mysql root 密码

>sudo /etc/init.d/mysql start --skip-grant-tables
>mysql -uroot -p mysql
>update user set password=passsword('root') where user='root'; 
重启mysql
就ok了 root 账户的密码为root

6,怎么判断我的mysql是编译安装的

wxianfeng@ubuntu:~$ mysql --version
mysql  Ver 14.14 Distrib 5.1.51, for pc-linux-gnu (i686) using  EditLine wrapper

如果你是apt-get 安装的话就显示 for ubuntu-linux-gnu
yum 安装的话就显示 for redhat-linux-gnu 了

遇到的问题:

1,
>mysql -uroot -p
Can’t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock’ (2)

>mysql -uroot -p --socket=/tmp/mysql.sock 可以启动,所以是sock问题
后来发现 my.cnf 有两个配置文件,/etc/mysql/my.cnf 多了一个这个,里面sock路径指定不一样所致,rename 掉
>mv /etc/mysql/my.cnf /etc/mysql/my_cnf.bak

2,

Starting MySQL. * Manager of pid-file quit without updating file. 错误

wxianfeng@ubuntu:/usr/local/system/shell$ /etc/init.d/mysql start 
Starting MySQL. * Manager of pid-file quit without updating file.

需要加sudo

3,查看mysql data目录

root@ubuntu:/usr/local/system/mysql/var# ps auxf | grep mysql
root     25756  0.0  0.0   4012   764 pts/3    S+   15:32   0:00  |           \_ grep --color=auto mysql
root     25000  0.0  0.0   4904  1400 ?        S    14:22   0:00 /bin/sh /usr/local/system/mysql/bin/mysqld_safe --datadir=/usr/local/system/mysql/var --pid-file=/usr/local/system/mysql/var/ubuntu.pid
mysql    25106  0.0  0.8 119652 16568 ?        Sl   14:22   0:00  \_ /usr/local/system/mysql/libexec/mysqld --basedir=/usr/local/system/mysql --datadir=/usr/local/system/mysql/var --user=mysql --log-error=/usr/local/system/mysql/var/ubuntu.err --pid-file=/usr/local/system/mysql/var/ubuntu.pid --socket=/tmp/mysql.sock --port=3306

可以看出在var下 ,注意 var目录的用户是 mysql ,必须root用户才能cd进入

sudo su # 切换到root用户

4,启动rails project报错:因为mysql gem的版本过高的原因

uninitialized constant MysqlCompat::MysqlRes (NameError)
>sudo apt-get install libmysqlclient-dev
>gem install mysql -v=2.7 --no-ri --no-rdoc

SEE:
http://blog.sitearth.com/ubuntu%E4%B8%8A%E6%90%AD%E5%BB%BAlamp%E7%8E%AF%E5%A2%83%E7%AC%94%E8%AE%B0%E2%80%94%E2%80%94mysql%E6%BA%90%E7%A0%81%E5%AE%89%E8%A3%85%E5%8F%8A%E9%85%8D%E7%BD%AE/
http://51jsp.cn/html/ror/2010/0327/14859.html
see:http://qichunren.javaeye.com/blog/577556

This entry was posted on Mon, 22 Nov 2010 14:50:00 GMT and Posted in , , , . You can follow any any response to this entry through the Atom feed. You can leave a comment or a trackback from your own site.

Tags , , ,


Trackbacks

Use the following link to trackback from your own site:
http://wxianfeng.com/trackbacks?article_id=100

Comments

Leave a comment