mysql安装一 --- 源码包安装

1.登陆http://www.mysql.com/ 或者 www.oracle.com

2.
3.
4.
上面如果不能加载,禁用代理软件
5.
6.
7.
8.
9.上传

10.md5校验安装包的完整性

  1. [root@db2 ~]# md5sum ./mysql-5.6.26.tar.gz
  2. 733e1817c88c16fb193176e76f5b818f ./mysql-5.6.26.tar.gz

与上面的md5对照,如果一致说明安装包完整无缺
11.解压

  1. [root@db2 ~]# tar -xzvf mysql-5.6.26.tar.gz

源码目录说明:源码包目录.md

正式安装

1.安装cmake

下载地址:http://www.cmake.org/ 或者 http://yunpan.cn/cHgpTUaYRqjnc 访问密码 384d

  1. tar -xzvf cmake-3.3.1.tar.gz
  2. cd cmake-3.3.1
  3. ./configure
  4. make
  5. make install

需要安装gcc
yum install gcc
yum install gcc-c++

2.创建mysql安装目录和数据文件目录
  1. [root@db2 ~]# mkdir -p /usr/local/mysql
  2. [root@db2 ~]# mkdir -p /usr/local/mysql/data
3.创建用户和组
  1. groupadd mysql
  2. useradd -r -g mysql mysql
4.安装mysql
  1. tar -xzvf mysql-5.6.26.tar.gz
  2. [root@db2 ~]# cd mysql-5.6.26
  3. cmake . \
  4. -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
  5. -DMYSQL_DATADIR=/usr/local/mysql/data \
  6. -DSYSCONFDIR=/etc \
  7. -DWITH_MYISAM_STORAGE_ENGINE=1 \
  8. -DWITH_INNOBASE_STORAGE_ENGINE=1 \
  9. -DWITH_MEMORY_STORAGE_ENGINE=1 \
  10. -DWITH_READLINE=1 \
  11. -DMYSQL_UNIX_ADDR=/var/lib/mysql/mysql.sock \
  12. -DMYSQL_TCP_PORT=3306 \
  13. -DENABLED_LOCAL_INFILE=1 \
  14. -DWITH_PARTITION_STORAGE_ENGINE=1 \
  15. -DEXTRA_CHARSETS=all \
  16. -DDEFAULT_CHARSET=utf8 \
  17. -DDEFAULT_COLLATION=utf8_general_ci
  18. [root@db2 mysql-5.6.26]# make && make install

参数说明:
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql //安装目录
-DINSTALL_DATADIR=/usr/local/mysql/data //数据库存放目录
-DDEFAULT_CHARSET=utf8     //使用utf8字符
-DDEFAULT_COLLATION=utf8_general_ci //校验字符
-DEXTRA_CHARSETS=all     //安装所有扩展字符集
-DENABLED_LOCAL_INFILE=1    //允许从本地导入数据

编译的参数可以参考http://dev.mysql.com/doc/refman/5.5/en/source-configuration-options.html

** 注意事项:**
重新编译时,需要清除旧的对象文件和缓存信息。

  1. # make clean
  2. # rm -f CMakeCache.txt
  3. # rm -rf /etc/my.cnf

5.配置

  1. [root@db2 ~]# chown -R mysql:mysql /usr/local/mysql
  2. [root@db2 ~]# cp mysql-5.6.26/support-files/my-small.cnf /usr/local/mysql/my.cnf
  3. 编辑my.cnf
  4. mysqld标签下添加如下内容:
  5. basedir=/usr/local/mysql
  6. datadir=/usr/local/mysql/data

(1)初始化配置
进入安装路径,执行初始化配置脚本,创建系统自带的数据库和表

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

(2)设置环境变量

  1. PATH=$PATH:$HOME/bin:/usr/local/mysql/bin:/usr/local/mysql/lib
  2. export PATH
  3. . .bash_profile

6.启动服务

(1)手动启动mysql服务

  1. [root@ rhel5~]# cd /usr/local/mysql
  2. [root@ rhel5 mysql]# ./bin/mysqld_safe --user=mysql &   //启动MySQL,但不能停止
  3. 启动日志写在此文件下:/usr/local/mysql/data/localhost.err
  4. [root@db2 bin]# ps -ef | grep mysql
  5. root 22979 58621 0 22:56 pts/1 00:00:00 /bin/sh ./bin/mysqld_safe --user=mysql
  6. mysql 23069 22979 0 22:56 pts/1 00:00:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/usr/local/mysql/data/db2.err --pid-file=/usr/local/mysql/data/db2.pid
  7. root 23119 58621 0 22:57 pts/1 00:00:00 grep mysql
  8. 关闭MySQL服务
  9. [root@db2 mysql]# ./bin/mysqladmin -u root -p shutdown
  10. Enter password:
  11. 150917 23:03:57 mysqld_safe mysqld from pid file /usr/local/mysql/data/db2.pid ended
  12. [1]+ Done ./bin/mysqld_safe --user=mysql  
  13. //这里MySQL的root用户还没有配置密码,所以为空值。需要输入密码时,直接点回车键即可。

(2)设置自动启动mysql

  1. [root@db2 mysql]# cp support-files/mysql.server /etc/init.d/mysql
  2. [root@db2 mysql]# chkconfig mysql on
  3. [root@db2 mysql]# service mysql start
  4. Starting MySQL. [ OK ]

错误

  1. [root@db2 mysql-5.6.26]# cmake .
  2. -- Running cmake version 3.3.1
  3. -- Could NOT find Git (missing: GIT_EXECUTABLE)
  4. -- MySQL 5.6.26
  5. -- Packaging as: mysql-5.6.26-Linux-i686
  6. -- Could NOT find Threads (missing: Threads_FOUND)
  7. -- Could NOT find Threads (missing: Threads_FOUND)
  8. -- Check if the system is big endian
  9. -- Searching 16 bit integer
  10. CMake Error at /usr/local/share/cmake-3.3/Modules/TestBigEndian.cmake:51 (message):
  11. no suitable type found
  12. Call Stack (most recent call first):
  13. configure.cmake:628 (TEST_BIG_ENDIAN)
  14. CMakeLists.txt:398 (INCLUDE)
  15. -- Configuring incomplete, errors occurred!
  16. See also "/root/mysql-5.6.26/CMakeFiles/CMakeOutput.log".
  17. See also "/root/mysql-5.6.26/CMakeFiles/CMakeError.log".

解决办法:
删除目录,重新解压mysql包

  1. -- Could NOT find Curses (missing: CURSES_LIBRARY CURSES_INCLUDE_PATH)
  2. CMake Error at cmake/readline.cmake:85 (MESSAGE):
  3. Curses library not found. Please install appropriate package,
  4. remove CMakeCache.txt and rerun cmake.On Debian/Ubuntu, package name is libncurses5-dev, on Redhat and derivates it is ncurses-devel.
  5. Call Stack (most recent call first):
  6. cmake/readline.cmake:128 (FIND_CURSES)
  7. cmake/readline.cmake:202 (MYSQL_USE_BUNDLED_EDITLINE)
  8. CMakeLists.txt:409 (MYSQL_CHECK_EDITLINE)
  9. -- Configuring incomplete, errors occurred!
  10. See also "/root/mysql-5.6.26/CMakeFiles/CMakeOutput.log".
  11. See also "/root/mysql-5.6.26/CMakeFiles/CMakeError.log".

解决:
yum install ncurses-devel
rm -rf CMakeCache.txt
重新执行
cmake .

  1. [ 50%] Building C object sql/CMakeFiles/sql.dir/__/sql-common/my_time.c.o
  2. [ 50%] Building C object sql/CMakeFiles/sql.dir/__/sql-common/my_user.c.o
  3. [ 51%] Building C object sql/CMakeFiles/sql.dir/__/sql-common/pack.c.o
  4. [ 51%] Building CXX object sql/CMakeFiles/sql.dir/__/sql-common/client_authentication.cc.o
  5. [ 51%] Building CXX object sql/CMakeFiles/sql.dir/event_data_objects.cc.o
  6. [ 51%] Building CXX object sql/CMakeFiles/sql.dir/event_db_repository.cc.o
  7. [ 51%] Building CXX object sql/CMakeFiles/sql.dir/event_parse_data.cc.o
  8. [ 51%] Building CXX object sql/CMakeFiles/sql.dir/event_queue.cc.o
  9. [ 51%] Building CXX object sql/CMakeFiles/sql.dir/event_scheduler.cc.o
  10. [ 51%] Building CXX object sql/CMakeFiles/sql.dir/events.cc.o
  11. [ 51%] Building CXX object sql/CMakeFiles/sql.dir/mysqld.cc.o
  12. [ 51%] Building CXX object sql/CMakeFiles/sql.dir/sql_client.cc.o
  13. [ 51%] Linking CXX static library libsql.a
  14. /usr/bin/ar: CMakeFiles/sql.dir/rpl_handler.cc.o: No such file or directory
  15. make[2]: *** [sql/libsql.a] Error 1
  16. make[1]: *** [sql/CMakeFiles/sql.dir/all] Error 2
  17. make: *** [all] Error 2

服务启动失败:

或者

解决:

注:在启动MySQL服务时,会按照一定次序搜索my.cnf,先在/etc目录下找,找不到则会搜索”$basedir/my.cnf”,在本例中就是 /usr/local/mysql/my.cnf,这是新版MySQL的配置文件的默认位置!

注意:在rhel 6.4版操作系统的最小安装完成后,在/etc目录下会存在一个my.cnf,需要将此文件更名为其他的名字,如:/etc/my.cnf.bak,否则,该文件会干扰源码安装的MySQL的正确配置,造成无法启动。

在使用”yum update”更新系统后,需要检查下/etc目录下是否会多出一个my.cnf,如果多出,将它重命名成别的。否则,MySQL将使用这个配置文件启动,可能造成无法正常启动等问题。

  1. mv /etc/my.cnf /etc/my.cnf.bak




posted @ 2016-01-22 14:54  hao_xiaoyu  阅读(3093)  评论(0编辑  收藏  举报