编译安装MySQL 5.5


:Mr.zhou  阅读: 3,052 次

  当前环境

[root@mysql ~]# uname -rn
mysql.z-dig.com 2.6.32-504.el6.x86_64
[root@mysql ~]# 

  从官网下载 MySQL 5.5的源码包

[root@mysql ~]# cd /usr/local/src/
[root@mysql src]# wget http://dev.mysql.com/get/Downloads/MySQL-5.5/mysql-5.5.45-linux2.6-x86_64.tar.gz
[root@mysql src]#

  安装编译软件 CMake 及依赖

[root@mysql src]# yum -y install cmake ncurses-devel

  解压源码包 编译 安装

[root@mysql src]# tar xf mysql-5.5.45.tar.gz 
[root@mysql src]# 

[root@mysql src]# cd mysql-5.5.45
[root@mysql mysql-5.5.45]# cmake . \
> -DCMAKE_INSTALL_PREFIX=/usr/local/mysql-5.5.45 \
> -DMYSQL_DATADIR=/usr/local/mysql-5.5.45/data \
> -DMYSQL_UNIX_ADDR=/usr/local/mysql-5.5.45/tmp/mysql.sock \
> -DDEFAULT_CHARSET=utf8 \
> -DDEFAULT_COLLATION=utf8_general_ci \
> -DENABLED_LOCAL_INFILE=1 \
> -DWITH_INNOBASE_STORAGE_ENGINE=1 \
> -DWITH_FEDERATED_STORAGE_ENGINE=1 \
> -DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
> -DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 \
> -DWITHOUT_PARTITION_STORAGE_ENGINE=1 \
> -DWITH_ZLIB=bundled \
> -DWITH_READLINE=1 \
> -DWITH_EMBEDDED_SERVER=1 \
> -DWITH_DEBUG=0
...
-- Configuring done
-- Generating done
-- Build files have been written to: /usr/local/src/mysql-5.5.45
[root@mysql mysql-5.5.45]# 

[root@mysql mysql-5.5.45]# make 
...
[100%] Built target my_safe_process
[root@mysql mysql-5.5.45]#

[root@mysql mysql-5.5.45]# make install

  创建 mysql 用户

[root@mysql mysql-5.5.45]# useradd -s /sbin/nologin -M mysql
[root@mysql mysql-5.5.45]# id mysql
uid=500(mysql) gid=500(mysql) groups=500(mysql)
[root@mysql mysql-5.5.45]# 

  创建软链接、加入系统环境变量、更改安装目录的属主属组

[root@mysql mysql-5.5.45]# ln -s /usr/local/mysql-5.5.45/ /usr/local/mysql
[root@mysql mysql-5.5.45]# echo 'export PATH=/usr/local/mysql/bin/:$PATH'>>/etc/profile
[root@mysql mysql-5.5.45]# source /etc/profile
[root@mysql mysql-5.5.45]# chown -R mysql.mysql /usr/local/mysql/
[root@mysql mysql-5.5.45]# 

  复制配置文件(根据服务器配置选择相应的配置文件)及启动脚本

[root@mysql mysql-5.5.45]# cd /usr/local/mysql/support-files/
[root@mysql support-files]# ls my-*
[root@mysql support-files]# cp my-huge.cnf /etc/my.cnf 
cp: overwrite `/etc/my.cnf'? y
[root@mysql support-files]# 

[root@mysql support-files]# cp mysql.server /etc/init.d/mysqld

  初始化数据库(数据库保存路径为 安装时指定的位置)

[root@mysql support-files]# sh /usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data/ --user=mysql
Installing MySQL system tables...
150721 23:56:58 [Warning] 'THREAD_CONCURRENCY' is deprecated and will be removed in a future release.
150721 23:56:58 [Note] /usr/local/mysql/bin/mysqld (mysqld 5.5.45-log) starting as process 16812 ...
OK
Filling help tables...
150721 23:56:58 [Warning] 'THREAD_CONCURRENCY' is deprecated and will be removed in a future release.
150721 23:56:58 [Note] /usr/local/mysql/bin/mysqld (mysqld 5.5.45-log) starting as process 16820 ...
OK
...
[root@mysql support-files]# 

  启动MySQL

[root@mysql support-files]# /etc/init.d/mysqld start
Starting MySQL.. SUCCESS! 
[root@mysql support-files]# 

[root@mysql support-files]# lsof -i :3306
COMMAND   PID  USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
mysqld  17115 mysql   11u  IPv4  52461      0t0  TCP *:mysql (LISTEN)
[root@mysql support-files]# 

  修改 MySQL 默认管理用户 root 密码

[root@mysql support-files]# mysqladmin -uroot password '123456'

  登陆数据库

[root@mysql support-files]# mysql -uroot -p123456
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.5.45-log Source distribution

Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> SHOW DATABASES;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test               |
+--------------------+
4 rows in set (0.01 sec)

mysql> \q
Bye
[root@mysql support-files]# 

转载请注明原文链接:http://www.z-dig.com/to-compile-and-install-mysql-5-5.html



正文部分到此结束