ITPub博客

首页 > 数据库 > MySQL > 源码安装Mysql 5.5

源码安装Mysql 5.5

原创 MySQL 作者:warren20 时间:2015-07-29 19:00:19 0 删除 编辑
查看操作系统版本
  1. [root@MYSQL03 /]# uname -a
  2. Linux MYSQL03 2.6.32-431.el6.x86_64 #1 SMP Fri Nov 22 03:15:09 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux
  3. [root@MYSQL03 /]# cat /etc/redhat-release
  4. CentOS release 6.5 (Final)
所需软件:
    cmake-2.8.7.tar.gz
    mysql-5.5.23.tar.gz
    CentOS-6.5-x86_64-bin-DVD1.iso

1.配置yum源
    略

2 卸载系统自带的mysql
    [root@MYSQL03 /]# yum remove mysql-libs-5.1.71-1.el6.x86_64

2.编译安装cmake
  1. [root@MYSQL03 ~]# tar zxvf cmake-2.8.7.tar.gz -C /usr/local/src/
  2. [root@MYSQL03 ~]# cd /usr/local/src/cmake-2.8.7/
  3. [root@MYSQL03 ~]#./configure
  4. ---------------------------------------------
    CMake 2.8.7, Copyright 2000-2009 Kitware, Inc.
    ---------------------------------------------
    Error when bootstrapping CMake:
    Cannot find appropriate C compiler on this system.
    Please specify one using environment variable CC.
    See cmake_bootstrap.log for compilers attempted.


    ---------------------------------------------
    Log of errors: /usr/local/src/cmake-2.8.7/Bootstrap.cmk/cmake_bootstrap.log
    ---------------------------------------------
上面的错误是由于没有安装gcc编译器导致的,下面装gcc编译器
  1. [root@MYSQL03 cmake-2.8.7]# yum install gcc
再次安装
  1. [root@MYSQL03 cmake-2.8.7]# ./configure
  2. ---------------------------------------------
  3. CMake 2.8.7, Copyright 2000-2009 Kitware, Inc.
  4. C compiler on this system is: cc
  5. ---------------------------------------------
  6. Error when bootstrapping CMake:
  7. Cannot find appropriate C++ compiler on this system.
  8. Please specify one using environment variable CXX.
  9. See cmake_bootstrap.log for compilers attempted.
  10. ---------------------------------------------
  11. Log of errors: /usr/local/src/cmake-2.8.7/Bootstrap.cmk/cmake_bootstrap.log
  12. ---------------------------------------------
还缺少安装gcc-c++编译器, 下面安装gcc-c++编译器
  1. [root@MYSQL03 cmake-2.8.7]# yum install gcc-c++
再次安装
  1. [root@MYSQL03 cmake-2.8.7]# ./configure
  2. ......
  3. [root@MYSQL03 cmake-2.8.7]# gmake && make install
  4. .......
到这里,cmake 已经安装完成

3. 添加mysql 用户

  1. [root@MYSQL03 home]# useradd -u 27 -d /home/mysql/ -s /sbin/nologin mysql

4. 创建数据存储目录

  1. [root@MYSQL03 home]# mkdir -p /data/mysql
  2. [root@MYSQL03 home]# mkdir /data/mysql/mysql_log
  3. [root@MYSQL03 home]# chown -R mysql:mysql /data/mysql/
5. mysql编译安装
  1. [root@MYSQL03 MYSQL]# tar zxvf mysql-5.5.23.tar.gz -C /usr/local/src/
  2. [root@MYSQL03 MYSQL]# cd /usr/local/src/mysql-5.5.23/
  3. [root@MYSQL03 mysql-5.5.23]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DDEFAULT_CHARSET=utf8 -DENABLED_LOCAL_INFILE=1 -DMYSQL_DATADIR=/data/mysql/ -DWITH_EXTRA_CHARSETS=all -DWITH_READLINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DMYSQL_TCP_PORT=1333 -DDEFAULT_COLLATION=utf8_general_ci

  4. 报错
  5. .........
  6. CMake Error at cmake/readline.cmake:83 (MESSAGE):
  7.   Curses library not found. Please install appropriate package,

  8.       remove CMakeCache.txt and rerun cmake.On Debian/Ubuntu, package name is libncurses5-dev, on Redhat and derivates it is ncurses-devel.
  9. Call Stack (most recent call first):
  10.   cmake/readline.cmake:118 (FIND_CURSES)
  11.   cmake/readline.cmake:214 (MYSQL_USE_BUNDLED_READLINE)
  12.   CMakeLists.txt:268 (MYSQL_CHECK_READLINE)
解决错误:
  1. [root@MYSQL03 mysql-5.5.23]# yum install ncurses-devel
  2. [root@MYSQL03 mysql-5.5.23]# rm -f CMakeCache.txt
再次执行编译:
  1. [root@MYSQL03 mysql-5.5.23]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DDEFAULT_CHARSET=utf8 -DENABLED_LOCAL_INFILE=1 -DMYSQL_DATADIR=/data/mysql/ -DWITH_EXTRA_CHARSETS=all -DWITH_READLINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DMYSQL_TCP_PORT=1333 -DDEFAULT_COLLATION=utf8_general_ci
  2. [root@MYSQL03 mysql-5.5.23]# make && make install
6. 生成mysql的配置文件
  1. [root@MYSQL03 mysql-5.5.23]# cd /usr/local/mysql/support-files/
  2. [root@MYSQL03 support-files]# cp my-medium.cnf /etc/my.cnf
在my.cnf 中添加下面几个选项

datadir = /data/mysql

skip-name-resolve

innodb_flush_log_at_trx_commit = 2

bind-address = 服务器内网网卡地址(重要:不要让他监听在0.0.0.0上)

lower_case_table_names=1

long_query_time=1

slow_query_log=1

并检查1333端口是否被占用

7. 开始安装mysql

  1. [root@MYSQL03 support-files]# cd /usr/local/mysql/scripts/
  2. [root@MYSQL03 scripts]# ./mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/data/mysql/

  3. WARNING: The host 'MYSQL03' could not be looked up with resolveip.
    This probably means that your libc libraries are not 100 % compatible
    with this binary MySQL version. The MySQL daemon, mysqld, should work
    normally with the exception that host name resolving will not work.
    This means that you should use IP addresses instead of hostnames
    when specifying MySQL privileges !
    Installing MySQL system tables...
    OK
    Filling help tables...
    OK


    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:


    /usr/local/mysql//bin/mysqladmin -u root password 'new-password'
    /usr/local/mysql//bin/mysqladmin -u root -h 127.0.0.1
    127.0.0.1 password 'new-password'


    Alternatively you can run:
    /usr/local/mysql//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 /usr/local/mysql/ ; /usr/local/mysql//bin/mysqld_safe &


    You can test the MySQL daemon with mysql-test-run.pl
    cd /usr/local/mysql//mysql-test ; perl mysql-test-run.pl


    Please report any problems with the /usr/local/mysql//scripts/mysqlbug script!

8. 启动mysql

  1. [root@MYSQL03 scripts]# cd /usr/local/mysql/support-files
  2. [root@MYSQL03 support-files]# cp mysql.server /etc/init.d/mysqld
  3. [root@MYSQL03 mysql]# vim /etc/profile
  4. 最后面加上
  5. export PATH=/usr/local/mysql/bin:$PATH

  6. [root@MYSQL03 mysql]# . /etc/profile
9. 登陆mysql 修改密码
  1. [root@MYSQL03 mysql]# mysql
  2. Welcome to the MySQL monitor. Commands end with ; or \g.
  3. Your MySQL connection id is 1
  4. Server version: 5.5.23-log Source distribution

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

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

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

  10. mysql> select user,host,password from mysql.user;
  11. +------+-----------+----------+
  12. | user | host | password |
  13. +------+-----------+----------+
  14. | root | localhost | |
  15. | root | MYSQL03 | |
  16. | root | 127.0.0.1 | |
  17. | root | ::1 | |
  18. | | localhost | |
  19. | | MYSQL03 | |
  20. +------+-----------+----------+
  21. 6 rows in set (0.00 sec)

  22. mysql> update mysql.user set password=password('123456') where user='root';
  23. Query OK, 4 rows affected (0.00 sec)
  24. Rows matched: 4 Changed: 4 Warnings: 0

  25. mysql> delete from mysql.user where user='';
  26. Query OK, 2 rows affected (0.00 sec)

  27. mysql> flush privileges;
  28. Query OK, 0 rows affected (0.00 sec)

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/30150152/viewspace-1755695/,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2015-03-03

  • 博文量
    56
  • 访问量
    321056