接着上一篇《Ubuntu-14.04编译安装Apache-2.4.10》,这次介绍下MySQL-5.6.16的编译安装。

  1. 安装编译MySQL源码需要的库

    phpha@asus:~/lamp$ sudo apt-get install build-essential libncurses5-dev cmake
  2. 安全前准备及目录设置

    phpha@asus:~/lamp$ sudo groupadd mysql
    phpha@asus:~/lamp$ sudo useradd -g mysql mysql
    phpha@asus:~/lamp$ sudo mkdir -p /var/mysql/
    phpha@asus:~/lamp$ sudo mkdir -p /var/mysql/data/
    phpha@asus:~/lamp$ sudo mkdir -p /var/mysql/log/
    phpha@asus:~/lamp$ sudo chmod -R 777 /var/mysql/data/
  3. 使用cmake生成安装文件

    phpha@asus:~/lamp$ tar -zxf mysql-5.6.16.tar.gz
    phpha@asus:~/lamp$ cd mysql-5.6.16
    phpha@asus:~/lamp/mysql-5.6.16$ sudo cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_UNIX_ADDR=/tmp/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS:STRING=utf8,gbk -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DENABLED_LOCAL_INFILE=1 -DMYSQL_DATADIR=/var/mysql/data
  4. 安装MySQL

    phpha@asus:~/lamp/mysql-5.6.16$ sudo make
    phpha@asus:~/lamp/mysql-5.6.16$ sudo make install
  5. 配置MySQL

    phpha@asus:~/lamp/mysql-5.6.16$ sudo chmod +w /usr/local/mysql
    phpha@asus:~/lamp/mysql-5.6.16$ sudo chown -R mysql:mysql /usr/local/mysql
    phpha@asus:~/lamp/mysql-5.6.16$ sudo chown -R mysql:mysql /var/mysql/
    phpha@asus:~/lamp/mysql-5.6.16$ sudo ln -s /usr/local/mysql/lib/libmysqlclient.so.18 /usr/lib/libmysqlclient.so.18
    phpha@asus:~/lamp/mysql-5.6.16$ sudo cp support-files/my-default.cnf /var/mysql/my.cnf
    phpha@asus:~/lamp/mysql-5.6.16$ sudo cp support-files/mysql.server /etc/init.d/mysqld
    //MySQL初始化安装
    phpha@asus:~/lamp/mysql-5.6.16$ sudo /usr/local/mysql/scripts/mysql_install_db --defaults-file=/var/mysql/my.cnf --basedir=/usr/local/mysql --datadir=/var/mysql/data --user=mysql
  6. 启动MySQL

    phpha@asus:~$ sudo service mysqld start

    结果在启动和关闭时出现了以下错误:
    ERROR! The server quit without updating PID file
    MySQL server PID file could not be found
    按照网上的解决方法,多是说权限问题。后来经过自己尝试,发现是MySQL的data目录的几个文件权限不对,更改如下:

    phpha@asus:~/var/mysql/data$ sudo chown -R mysql:mysql *
    phpha@asus:~/var/mysql/data$ sudo service mysqld start

    设置下DATA目录的文件所有者后一切正常。

标签:MySQL Ubuntu