Centos 6.2(x64)下编译安装MySQL-5.5.22

 

  
  
  
  

  1. ========================Centos 6.2(x64)下编译安装MySQL-5.5.22========================
  2. 软件源码包存放位置  /usr/local
    源码包编译安装位置  /usr/local/mysql
  3. ###########################################################################################
    #                                                                                         #
    #  现在的5.5以后的MySQL都使用Cmake进行编译安装,所以在安装MySQL之前我们首先要把Cmake装在我们的系统。#
    #                                                                                         #
    ###########################################################################################
  4. 我们所需要的软件源码包有以下:
          cmake-2.8.7.tar.gz
          mysql-5.5.22.tar.gz(mysql版本可以更新)
    1、安装Cmake
    #安装所需依赖关系
    yum -y install ntp vim-enhanced gcc gcc-c++ flex bison autoconf automake bzip2-devel
  5. ncurses-devel zlib-devel libjpeg-devel libpng-devel libtiff-devel freetype-devel
  6. libXpm-devel gettext-devel  pam-devel libtool libtool-ltdl openssl openssl-devel
  7. fontconfig-devel libxml2-devel curl-devel  libicu libicu-devel libmcrypt libmcrypt-devel
  8. libmhash libmhash-devel
  9. 安装 mcrypt时如果提示libmcrypt没有找到 运行
      export LD_LIBRARY_PATH=/usr/local/libmcrypt/lib:/usr/local/mhash/lib
      export LDFLAGS="-L/usr/local/mhash/lib/ -I/usr/local/mhash/include"
      export CFLAGS="-I/usr/local/mash/include/"
      ./configure --prefix=/usr/local/mcrypt --with-libmcrypt --prefix=/usr/local/libmcrypt
  10. #下载Cmake的源码包
    #编译安装
    tar zxvf cmake-2.8.7.tar.gz
  11. cd cmake-2.8.7
  12. ./configure && make && make install
    2、编译安装配置MySQL#
      创建所需目录   mkdir -pv /usr/local/mysql/data //同时创建mysql和data两个目录并输出创建信息
      创建mysql组      groupadd mysql
      创建mysql用户    useradd -g mysql -s /sbin/nologin mysql
                         
    #解压源码包tar -zxvf 源码包路径 -C /usr/src/   本人常解压在此目录下面
                cd /usr/src/mysql目录
    #cmake编译

  13. cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql5 -DMYSQL_UNIX_ADDR=/usr/local/mysql5/mysql.sock
  14. -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS=all
  15. -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1
  16. -DWITH_READLINE=1 -DENABLED_LOCAL_INFILE=1 -DMYSQL_DATADIR=/usr/local/mysql5/data
  17. -DMYSQL_USER=mysql -DMYSQL_TCP_PORT=3306

  18. ==============================================================================
    参数说明:
    -DCMAKE_INSTALL_PREFIX=/usr/local/mysql //安装目录
    -DMYSQL_DATADIR=/usr/local/mysql/data //数据库存放目录
    -DWITH_MYISAM_STORAGE_ENGINE=1 //安装myisam存储引擎
    -DWITH_INNOBASE_STORAGE_ENGINE=1 //安装innodb存储引擎
    -DWITH_ARCHIVE_STORAGE_ENGINE=1 //安装archive存储引擎
    -DWITH_BLACKHOLE_STORAGE_ENGINE=1 //安装blackhole存储引擎
    -DENABLED_LOCAL_INFILE=1 //允许从本地导入数据
    -DDEFAULT_CHARSET=utf8   //使用utf8字符
    -DDEFAULT_COLLATION=utf8_general_ci //校验字符
    -DEXTRA_CHARSETS=all   //安装所有扩展字符集
    -DMYSQL_TCP_PORT=3306 //MySQL监听端口
    -DMYSQL_USER=mysql //MySQL用户名
  19. -DWITH-EMBEDDED_SERVER=1 //编译成embedded MySQL library (libmysqld.a)
    -DSYSCONFDIR=/etc //MySQL配辑文件
    -DMYSQL_UNIX_ADDR=/tmp/mysqld.sock //Unix socket 文件路径
    -DWITH_READLINE=1 //快捷键功能
    -DWITH_SSL=yes //SSL
    -DWITH_MEMORY_STORAGE_ENGINE=1 //安装memory存储引擎
    -DWITH_FEDERATED_STORAGE_ENGINE=1 //安装frderated存储引擎
    -DWITH_PARTITION_STORAGE_ENGINE=1 //安装数据库分区
    -DINSTALL_PLUGINDIR=/usr/local/mysql/plugin //插件文件及配置路径
  20. =========================================================================================
    #安装
    make && make install
  21.  
  22. #复制配置文件(源码目录下面)
    cp support-files/my-medium.cnf /etc/my.cnf
    #设置权限
    chmod +x /usr/local/mysql
    chown -R mysql:mysql /usr/local/mysql
    chown -R mysql:mysql /usr/local/mysql/data
    #配置开机自动启动
    cp support-files/mysql.server /etc/init.d/mysqld
    chmod +x /etc/init.d/mysqld
    chkconfig --add mysqld
    chkconfig mysqld on
    #修改配置文件
    vim /etc/my.cnf
    #在[mysqld]中添加:
    datadir = /usr/local/mysql/data
    log-error = /usr/local/mysql/data/error.log
    pid-file = /usr/local/mysql/data/www.pid     //(此处的pid文件名称要与主机名称一致)
    user = mysql
    tmpdir = /tmp
    #保存退出

  23. #初始化数据库
    /usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql
  24. --datadir=/usr/local/mysql/data

  25. #手动启动MySQL
    service mysqld start
  26. 加入环境变量,在/etc/profile文件中最后加入:

  27. export PATH=/usr/local/mysql/bin:$PATH
  28. 修改默认的mysql最大连接数(默认只有151),打开/etc/my.cnf文件,在[mysqld]的下面加入:
  29. max_connections=1000,然后重启mysql即可生效,查看最大连接数:

  30. mysql>show VARIABLES LIKE '%conn%';
  31. ###############################################################################
    #                                                                           #
    #此时如果启动失败,查看日志,如果提示字符集无效,修改my.cnf配置文件,添加下面设置         #
    #[client]                                                                     #
  32. #linux环境下面设置此值                                                          #
    #default-character-set=utf8                                                 #
  33. #                                                                             #
    #[mysqld]                                                                     #
    #character-set-server=utf8                                                    #
    #保存退出后重新初始化数据库                                                       #
  34. #                                  #
    #/usr/local/mysql/scripts/mysql_install_db --user=mysql #
  35. #--basedir=/usr/local/mysql --datadir=/usr/local/mysql/data   #
    # #
    ###############################################################################

  36. #测试MySQL是否启动
    #查看是否有mysql进程
    ps -ef | grep mysql
    #查看是否有mysql端口
    netstat -tnlp | grep 3306
  37. 如果提示[ERROR] Plugin 'InnoDB' init function returned error,把安装目录下面的ib_logfile0
  38. 和ib_logfile1删除或者重命名
  39. 重启Mysqld服务
  40. 设置Mysql程序执行路径
    export PATH=$PATH:/usr/local/mysql/bin
    echo "PATH=$PATH:/usr/local/mysql/bin" >> /etc/profile
    #读取MySQL的版本信息mysqladmin version

  41. ===========================到此MySQL编译安装完成=========================================
  42. #######################################################
    #                                                     #
    #     第一次登录默认为空密码                          #
    #                                                     #
    #      mysql -u root                                  #
    #                                                     #
    #      修改root登录数据库的密码                       #
    #                                                     #
    #     mysqladmin -u root password "自定义的密码"       #
    #                                                     #
    #######################################################
  43.   

你可能感兴趣的:(linux,mysql,centos)