Linux下编译安装mysql5.5

安装中需要用到的软件:
mysql源码文件:mysql-5.5.19.tar.gz
wget http://dev.mysql.com/get/Downloads/MySQL-5.5/mysql-5.5.19.tar.gz/from/http://mysql.he.net/
cmake(5.5版本没用用configure编译了)
wget http://www.cmake.org/files/v2.8/cmake-2.8.4.tar.gz
bison (不装的话编译时会有警告)
wget http://ftp.gnu.org/gnu/bison/bison-2.5.tar.gz
GNU m4(不装无法安装bison)
http://ftp.gnu.org/gnu/m4/m4-1.4.16.tar.gz
ncurses-devel(yum安装)
gcc-c++(yum安装)
1.建YUM(因为yum可以很好解决LINUX下的依存关系)
直接使用163的YUM源
vi /etc/yum/pluginconf.d/fastestmirror.conf    set  enable=0
cd /etc/yum.repos.d/
wget heep://mirrors.163.com/.help/CentOS6-Base-163.repo
yum makecache
yum update
(如果更新有问题重命名/lib/modules/2.6.32-71.el6.i686/kernel/net/ipv6即:mv /lib/modules/2.6.x/kernel/net/ipv6 /lib/modules/2.6.x/kernel/net/ipv6.bak 后重启)
2.相关说明
1) 所有下载的文件将保存在 /usr/local/src/ 目录下
2) mysql 将以mysql用户运行,而且将加入 service 开机自动运行
3) mysql 将被安装在 /usr/local/mysql/ 目录下
4) mysql 默认安装使用 utf8 字符集
5) mysql 的数据和日志文件保存在 /var/mysql/ 对应目录下
6) mysql 的配置文件保存于/var/mysql/my.cnf
3.安装 cmake
yum install gcc-c++
yum install ncurses-devel
cd /usr/local/src
tar zxvf m4-1.4.16.tar.gz
cd m4-1.4.16
./configure
make
make install
tar zxvf bison-2.5.tar.gz
cd bison-2.5
./configure
make
make install
tar zxvf cmake-2.8.4.tar.gz
cd cmake-2.8.4
./bootstrap
gmake
gmake install
 3.编译安装 MySQL 5.5.19
groupadd mysql
useradd -g mysql mysql
tar xvf mysql-5.5.19.tar.gz
cd mysql-5.5.19/
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_MEMORY_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DENABLED_LOCAL_INFILE=1 \
-DMYSQL_DATADIR=/var/mysql/data \
-DMYSQL_USER=mysql
(注:以上编译选项意思可以看BLOG另外一篇文章)
make
make install
chmod +w /usr/local/mysql
chown -R mysql:mysql /usr/local/mysql
ln -s /usr/local/mysql/lib/libmysqlclient.so.16 /usr/lib/libmysqlclient.so.16
 mkdir -p /var/mysql/
mkdir -p /var/mysql/data/
mkdir -p /var/mysql/log/
chown -R mysql:mysql /var/mysql/
cd support-files/
cp my-large.cnf /var/mysql/my.cnf
(注:Q:Starting MySQL..The server quit without updating PID file (/var/lib/mysql/localhost.localdomain.pid)
A 解决办法:
确实一般都是my.cnf配置文件的问题
/etc/my.cnf来自以下文件:
如果你的内存≤64M,则复制/usr/local/share/mysql/my-small.cnf为/etc/my.cnf
# This is for a system with little memory (<= 64M) where MySQL is only used
# from time to time and it's important that the mysqld daemon
# doesn't use much resources.
如果内存是128M,则复制/usr/local/share/mysql/my-medium.cnf为/etc/my.cnf
# This is for a system with little memory (32M - 64M) where MySQL plays
# an important part, or systems up to 128M where MySQL is used together with
# other programs (such as a web server)
如果内存是512M,则复制/usr/local/share/mysql/my-large.cnf为/etc/my.cnf
# This is for a large system with memory = 512M where the system runs mainly
# MySQL.
如果内存是1-2G,则复制/usr/local/share/mysql/my-huge.cnf为/etc/my.cnf
# This is for a large system with memory of 1G-2G where the system runs mainly
# MySQL. )
cp mysql.server /etc/init.d/mysqld
4. 配置启动MySQL 5.5.13
1) 若有需要请先修改 mysql 的配置 my.cnf
vi /var/mysql/my.cnf
   
2) mysql 初始化安装
/usr/local/mysql/scripts/mysql_install_db \
--defaults-file=/var/mysql/my.cnf \
--basedir=/usr/local/mysql \
--datadir=/var/mysql/data \
--user=mysql
3)设置环境变量
export PATH=/usr/local/mysql/bin:$PATH
直接修改vi /etc/profile(全局)或用户目录下.bashrc文件
 export PATH="$PATH:/usr/local/mysql/bin"
或者直接添加几个软连接让这些工具可以直接用,如下
ln -s /usr/local/mysql/bin/mysql /usr/bin
ln -s /usr/local/mysql/bin/mysqldump /usr/bin
ln -s /usr/local/mysql/bin/mysqladmin /usr/bin
4)将 mysql 加入开机启动
cp support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
vi /etc/init.d/mysqld (编辑此文件,查找并修改以下变量内容:)
basedir=/usr/local/mysql
datadir=/var/mysql/data
chkconfig --add mysqld
chkconfig --level 345 mysqld on
5)启动 mysql
service mysqld start


你可能感兴趣的:(mysql)