Ubuntu 10.04 下源码编译mysql5.5.x

Ubuntu 10.04 下源码编译mysql5.5.x

1. 安装cmake
   $ sudo apt-get install cmake

2. 安装libncurses5-dev
   $ sudo apt-get install libncurses5-dev

$ rm CMakeCache.txt

$ cmake . -LH           # 查看支持的参数

$ sudo apt-get install bison

$ rm CMakeCache.txt

$ cmake . -LH

$ rm CMakeCache.txt

$ cmake . \
-DCMAKE_INSTALL_PREFIX:PATH=/opt/apps/mysql-5.5.21/  \
-DMYSQL_DATADIR:PATH=/opt/apps/mysql-5.5.21/data/ \
-DSYSCONFDIR=/opt/etc/mysql-5.5.21/ \
-DMYSQL_DATADIR=/opt/var/mysql-5.5.21/ \
-DMYSQL_UNIX_ADDR=/opt/tmp/mysql-5.5.21/mysql.sock \
-DMYSQL_TCP_PORT=3306 \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \            # 这步如果没有,会出现COLLATION 'latin1_swedish_ci' is not valid for CHARACTER SET 'utf8'
-DEXTRA_CHARSETS=gb2312,gbk

$ make
$ make install

$ sudo cp support-files/my-medium.cnf /etc/my.cnf

$ sudo groupadd mysql

$ sudo useradd -g mysql mysql

$ sudo chown -R mysql:mysql /opt/var/mysql-5.5.21/

$ sudo chown -R mysql:mysql /opt/tmp/mysql-5.5.21/

$ ln -s /opt/apps/mysql-5.5.21/ /opt/apps/mysql

$ sudo /opt/apps/mysql-5.5.21/scripts/mysql_install_db \
--user=mysql \
--basedir=/opt/apps/mysql-5.5.21 \
--datadir=/opt/var/mysql-5.5.21 \
--tmpdir=/opt/tmp/mysql-5.5.21

################################################################################
# 执行后的提示
# 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/apps/mysql-5.5.21/bin/mysqladmin -u root password 'new-password'
# /opt/apps/mysql-5.5.21/bin/mysqladmin -u root -h tony-laptop password 'new-password'
#
# Alternatively you can run:
# /opt/apps/mysql-5.5.21/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/apps/mysql-5.5.21 ; /opt/apps/mysql-5.5.21/bin/mysqld_safe &
#
# You can test the MySQL daemon with mysql-test-run.pl
# cd /opt/apps/mysql-5.5.21/mysql-test ; perl mysql-test-run.pl
################################################################################

$ sudo /opt/apps/mysql/bin/mysqld_safe &        # 总是启动不成功

查看日志
$ sudo cat /opt/apps/mysql-5.5.21/data/tony-laptop.err
  /opt/apps/mysql-5.5.21/bin/mysqld: File './mysql-bin.index' not found (Errcode: 13)
  errcode13,一般就是权限问题,mysql用户是否对数据库目录内的所有文件具有写的权限,查看一下权限,发现不对,修改:
  $ sudo chown mysql:mysql -R /opt/apps/mysql/data/

再次启动,出现了新的问题:
Fatal error: Can't open and lock privilege tables: Table 'mysql.host' doesn't exist
$ sudo /opt/apps/mysql-5.5.21/scripts/mysql_install_db --user=mysql \
--basedir=/opt/apps/mysql-5.5.21 \
--datadir=/opt/apps/mysql-5.5.21/data/ \             # 上面我怎么写成了var的权限了,编译的时候,data应该放到var下的
--tmpdir=/opt/tmp/mysql-5.5.21
再次启动就ok了

$ /opt/apps/mysql-5.5.21/bin/mysqladmin -u root password 'new-password'  # 设置超级管理密码

$ ln -s /opt/apps/mysql-5.5.21/bin/mysql /usr/bin/mysql       # 创建快捷链接

$ mysql -uroot -p             # 测试登录

$ sudo mv support-files/mysql.server /etc/init.d/mysql       # 设置开机自动启动

$ sudo chmod +x /etc/init.d/mysql        # 给与可执行权限

$ sudo /etc/init.d/mysql start          # 启动

$ sudo update-rc.d mysql defaults 99     # 开机自动启动

你可能感兴趣的:(ubuntu)