重庆思庄Oracle、Redhat认证学习论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 8433|回复: 10
打印 上一主题 下一主题

源码安装mysql的过程

[复制链接]
跳转到指定楼层
楼主
发表于 2015-4-4 23:20:39 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
前言:从mysql 5.5版本开始,mysql源码安装开始使用cmake了,编译安装跟以前的版本有点不一样了。

一,安装步骤:

    1.安装前准备工作

       a.下载mysql源代码包,到mysql下载页面选择MYSQL Community Serve Source Code 版本

          注意:不要选择Linux-Generic版本,此版本为已经编译好的二进制版本

       b.检查本机Linux是否已安装好make,bison,cmake,gcc-c++,ncurses,如果尚未安装,先安装以上包,安装方法如下:

         注意:一般系统都会默认安装有make,gcc-c++.

         1.安装make编译器

            下载地址:http://www.gnu.org/software/make/

  1. # tar zxvf make-3.82.tar.gz    
  2. # cd make-3.82    
  3. # ./configure    
  4. # make    
  5. # make install   

            也可用:yum install make.i686 安装此包

        

       2.安装bison

          下载地址:http://www.gnu.org/software/bison/      

  1. <span style="font-size:13px;"># tar zxvf bison-2.5.tar.gz    
  2. # cd bison-2.5    
  3. # ./configure    
  4. # make    
  5. # make install </span>  

        也可用:yum install bison.i686 安装此包
         

3.安装gcc-c++

下载地址:http://www.gnu.org/software/gcc

  1. # tar zxvf gcc-c++-4.4.4.tar.gz    
  2. # cd gcc-c++-4.4.4    
  3. # ./configure    
  4. # make    
  5. # make install  

            也可用:yum install gcc-c++.i686 安装此包

4.安装cmake

下载地址:http://www.cmake.org/

  1. # tar zxvf cmake-2.8.4.tar.gz    
  2. # cd cmake-2.8.4    
  3. # ./configure    
  4. # make    
  5. # make install  

              也可用:yum install  cmake.i686 安装此包

         

5.安装ncurses

下载地址:http://www.gnu.org/software/ncurses/

  1. # tar zxvf ncurses-5.8.tar.gz    
  2. # cd ncurses-5.8    
  3. # ./configure    
  4. # make    
  5. # make install  

           也可用:yum install ncurses.i686 安装此包

         2.添加mysql用户与组

  1. #groupadd mysql  
  2. #useradd -g mysql -s /sbin/nologin -M mysql  

         3.mysql的源码编译

  1. #tar zxvf mysql-5.5.13.tar.gz  
  2. #cd mysql-5.5.13  
  3. #rm CMakeCache.txt  
  4. #cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql55/  -DMYSQL_DATADIR=/usr/local/mysql55/data  -DWITH_INNOBASE_STORAGE_ENGINE=1  -DMYSQL_TCP_PORT=3306  -DMYSQL_UNIX_ADDR=/usr/local/mysql55/data/mysql.sock  -DMYSQL_USER=mysql  -DWITH_DEBUG=0  
  5. #make   
  6. #make install  

       4.编译完成后,安装数据库

  1. # cd /usr/local/mysql    
  2. # chown -R mysql .    
  3. # chgrp -R mysql .    
  4. # scripts/mysql_install_db --user=mysql  --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data  
  5. # chown -R root .   
  6. # chown -R mysql ./data  

          某次安装完数据库完后,启动不了数据库,查看日志显示:Can't open the mysql.plugin table...2009-06-01 00:52Can't open the mysql.plugin table. Please run mysql_upgrade to create it.

解决方法:重新执行数据库安装过程,并带上   

  1. --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data  
于是搞定

   5.下面的命令是可选的,将mysql的配置文件拷贝到/etc      

cp support-files/my-medium.cnf /etc/my.cnf

如果原来的/etc目录下有my.cnf文件,则一定要用编译安装的my.cnf替换掉系统默认的my..cnf,否则会报如下错误:

  1. /usr/local/mysql/bin/mysqld: Table 'mysql.plugin' doesn't exist  
  2. 120406 23:57:45 [ERROR] Can't open the mysql.plugin table. Please run mysql_upgrade to create it.  
  3. 120406 23:57:45 InnoDB: The InnoDB memory heap is disabled  
  4. 120406 23:57:45 InnoDB: Mutexes and rw_locks use GCC atomic builtins  
  5. 120406 23:57:45 InnoDB: Compressed tables use zlib 1.2.3  
  6. 120406 23:57:45 InnoDB: Initializing buffer pool, size = 128.0M  
  7. 120406 23:57:45 InnoDB: Completed initialization of buffer pool  
  8. InnoDB: The first specified data file ./ibdata1 did not exist:  
  9. InnoDB: a new database to be created!  
  10. 120406 23:57:45  InnoDB: Setting file ./ibdata1 size to 10 MB  
  11. InnoDB: Database physically writes the file full: wait...  
  12. 120406 23:57:45  InnoDB: Log file ./ib_logfile0 did not exist: new to be created  
  13. InnoDB: Setting log file ./ib_logfile0 size to 5 MB  
  14. InnoDB: Database physically writes the file full: wait...  
  15. 120406 23:57:45  InnoDB: Log file ./ib_logfile1 did not exist: new to be created  
  16. InnoDB: Setting log file ./ib_logfile1 size to 5 MB  
  17. InnoDB: Database physically writes the file full: wait...  
  18. InnoDB: Doublewrite buffer not found: creating new  
  19. InnoDB: Doublewrite buffer created  
  20. InnoDB: 127 rollback segment(s) active.  
  21. InnoDB: Creating foreign key constraint system tables  
  22. InnoDB: Foreign key constraint system tables created  
  23. 120406 23:57:46  InnoDB: Waiting for the background threads to start  
  24. 120406 23:57:47 InnoDB: 1.1.8 started; log sequence number 0  
  25. 120406 23:57:47 [ERROR] /usr/local/mysql/bin/mysqld: Can't create/write to file '/var/run/mysqld/mysqld.pid' (Errcode: 2)  
  26. 120406 23:57:47 [ERROR] Can't start server: can't create PID file: No such file or directory  
  27. 120406 23:57:47 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended  



       6.启动mysql:       

  1. # bin/mysqld_safe --user=mysql &    
  2. # #启动mysql,看是否成功    
  3. # netstat -tnl|grep 3306  
  4. # 或者  
  5. # ps -aux|grep 'mysql'  

   可选步骤:设置root 密码:

/usr/local/mysql/bin/mysqladmin -u root password 'new-password'
/usr/local/mysql/bin/mysqladmin -u root -h localhost.localdomain password 'new-password'  

此步骤需要在数据库启动之后才能执行成功

  7.配置自启动

  1. # cp support-files/mysql.server /etc/init.d/mysqld  
  2. # chmod +x /etc/init.d/mysqld  
  3. # chkconfig –add mysqld  

      或者这样启动:    

  1. # #将mysql的启动服务添加到系统服务中    
  2. # cp support-files/mysql.server /etc/init.d/mysql.server    
  3. # #现在可以使用下面的命令启动mysql    
  4. # service mysql.server start    
  5. # #停止mysql服务    
  6. # service mysql.server stop    
  7. # #重启mysql服务    
  8. # service mysql.server restart   

8

为了方便,将mysql 的bin目录加到PATH中
export PATH=/usr/local/mysql/bin:$PATH
     


附:

关于重新编译问题:

Dealing with Problems Compiling MySQL

The solution to many problems involves reconfiguring. If you do reconfigure, take note of the following:

  • If CMake is run after it has previously been run,it may use information that was gathered during its previousinvocation. This information is stored inCMakeCache.txt. WhenCMakestarts up, it looks for that file and reads its contents if it exists,on the assumption that the information is still correct. Thatassumption is invalid when you reconfigure.
  • Each time you run CMake, you must run makeagain to recompile. However, you may want to remove old object filesfrom previous builds first because they were compiled using differentconfiguration options.

To prevent old object files or configuration information from being used, run these commands on Unix before re-runningCMake:

shell> make clean
shell> rm CMakeCache.txt
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏1 支持支持 反对反对
回复

使用道具 举报

沙发
 楼主| 发表于 2015-4-5 09:33:41 | 只看该作者

如果在make时,报如下错误,一般是没有安装 libncurses5-dev 所致,在安装libncurses5-dev 后问题解决 :

。。。

-- Check size of wint_t - done
-- Could NOT find Curses (missing:  CURSES_LIBRARY CURSES_INCLUDE_PATH)
CMake Error at cmake/readline.cmake:85 (MESSAGE):
  Curses library not found.  Please install appropriate package,

      remove CMakeCache.txt and rerun cmake.On Debian/Ubuntu, package name is libncurses5-dev, on Redhat and derivates it is ncurses-devel.
Call Stack (most recent call first):
  cmake/readline.cmake:128 (FIND_CURSES)
  cmake/readline.cmake:202 (MYSQL_USE_BUNDLED_EDITLINE)
  CMakeLists.txt:409 (MYSQL_CHECK_EDITLINE)


-- Configuring incomplete, errors occurred!
See also "/u01/mysql-5.6.23/CMakeFiles/CMakeOutput.log".
See also "/u01/mysql-5.6.23/CMakeFiles/CMakeError.log".

回复 支持 反对

使用道具 举报

板凳
 楼主| 发表于 2015-4-5 09:39:58 | 只看该作者

如果继续编译,继续报如下的错误,可以再次确认以下安装是否完成:

 

    yum install gcc gcc-c++ -y
    yum install -y ncurses-devel.x86_64
    yum install -y cmake.x86_64
    yum install -y libaio.x86_64
    yum install -y bison.x86_64

我这里遇到的是 gcc-c++没有安装正确所导致,安装gcc-c++后,问题解决。


 

-- Looking for asprintf - found
-- Check size of pthread_t
-- Check size of pthread_t - done
-- Using cmake version 2.8.12.2
-- Not building NDB
-- Performing Test HAVE_PEERCRED
CMake Error at /usr/share/cmake/Modules/CMakeCXXInformation.cmake:37 (get_filename_component):
  get_filename_component called with incorrect number of arguments
Call Stack (most recent call first):
  CMakeLists.txt:3 (PROJECT)


CMake Error: CMAKE_CXX_COMPILER not set, after EnableLanguage
CMake Error: Internal CMake error, TryCompile configure of cmake failed
-- Performing Test HAVE_PEERCRED - Failed
-- Library mysqlclient depends on OSLIBS -lpthread;m;rt;dl
-- Googlemock was not found. gtest-based unit tests will be disabled. You can run cmake . -DENABLE_DOWNLOADS=1 to automatically download and build required components from source.
-- If you are inside a firewall, you may need to use an http proxy: export http_proxy=http://example.com:80
-- Library mysqlserver depends on OSLIBS -lpthread;m;rt;crypt;dl
-- CMAKE_BUILD_TYPE: RelWithDebInfo
-- COMPILE_DEFINITIONS: HAVE_CONFIG_H
-- CMAKE_C_FLAGS:  -Wall -Wextra -Wformat-security -Wvla -Wwrite-strings -Wdeclaration-after-statement
-- CMAKE_CXX_FLAGS:
-- CMAKE_C_FLAGS_RELWITHDEBINFO: -O3 -g -fabi-version=2 -fno-omit-frame-pointer -fno-strict-aliasing -DDBUG_OFF
-- CMAKE_CXX_FLAGS_RELWITHDEBINFO:  -DDBUG_OFF
-- Configuring incomplete, errors occurred!
See also "/u01/mysql-5.6.23/CMakeFiles/CMakeOutput.log".
See also "/u01/mysql-5.6.23/CMakeFiles/CMakeError.log".

回复 支持 反对

使用道具 举报

地板
 楼主| 发表于 2015-4-5 09:41:44 | 只看该作者

 

 

我的make 命令行为:

 

cmake \
 -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
 -DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \
 -DDEFAULT_CHARSET=utf8 \
 -DDEFAULT_COLLATION=utf8_general_ci \
 -DWITH_INNOBASE_STORAGE_ENGINE=1 \
 -DWITH_ARCHIVE_STORAGE_ENGINE=1 \
 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
 -DMYSQL_DATADIR=/usr/local/mysql/data \
 -DMYSQL_TCP_PORT=3306 \
 -DENABLE_DOWNLOADS=0

回复 支持 反对

使用道具 举报

5#
 楼主| 发表于 2015-4-5 09:48:37 | 只看该作者

在运行编译命令前加一个  time  可以看到这个命令运行所需要的时间 ,如下:

 

# time make install

 

。。。

-- Installing: /usr/local/mysql/sql-bench/bench-count-distinct

real    0m58.194s
user    0m7.304s
sys     0m10.029s

 

 

 

回复 支持 反对

使用道具 举报

6#
 楼主| 发表于 2015-4-5 10:46:09 | 只看该作者

 

把 mysql 加到path中,最好使用以下命令:

 

echo "export PATH=$PATH:/usr/local/mysql/bin">>/etc/profile 

这样,每次启动,所有用户都可以执行这个mysql了。

 

回复 支持 反对

使用道具 举报

7#
 楼主| 发表于 2015-4-5 10:50:43 | 只看该作者

cmake

 

参数说明:

-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                        //允许从本地导入数据

回复 支持 反对

使用道具 举报

8#
 楼主| 发表于 2015-4-5 11:06:38 | 只看该作者

启动服务报错:

 

[root@ mysql]# service mysqld start
Starting MySQL.......The server quit without updating PID f[失败]usr/local/mysql/mysqld.pid).
[root@ mysql]# 
查看日志报错如下:
2014-06-24 14:56:54 31726 [Note] Server socket created on IP: '::'.
2014-06-24 14:56:54 31726 [ERROR] Can't start server : Bind on unix socket: Permission denied
2014-06-24 14:56:54 31726 [ERROR] Do you already have another mysqld server running on socket: /usr/local/mysql/mysql.sock ?
2014-06-24 14:56:54 31726 [ERROR] Aborting
解决原因是:
/usr/local/mysql根目录需要赋予mysql权限
根据日志文件显示,首先检查运行权限,再看一下/usr/local/mysql/mysql.sock,发现/usr/local/mysql目录下并没有该文件,是否是没有权限写目录?
看到/usr/local/mysql目录是root用户,所以赋予mysql操作权限。
chown -R mysql.mysql /usr/local/mysql

再次运行,可以正常启动成功。

 

[root@ data]# service mysqld start
Starting MySQL. SUCCESS! 

 

[root@sztech1 ~]# mysql 
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 12
Server version: 5.6.23 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                   |
+--------------------+
+--------------------+
3 rows in set (0.00 sec)

 

[此贴子已经被作者于2015-04-05 11:09:51编辑过]
回复 支持 反对

使用道具 举报

9#
 楼主| 发表于 2015-4-5 11:16:32 | 只看该作者

安装好后,

设置默认用户帐号:

 

 

use mysql;
delete from user;
delete from db;
GRANT ALL PRIVILEGES ON *.* TO 'root'@'192.168.0.%'  identified by 'root' WITH GRANT OPTION;
GRANT PROXY ON ''@'' TO 'root'@192.168.0.%' WITH GRANT OPTION;
GRANT ALL PRIVILEGES  ON *.* TO 'root'@'localhost' identified by 'root' WITH GRANT OPTION;
GRANT PROXY ON ''@'' TO 'root'@'localhost' WITH GRANT OPTION;
flush privileges;

#删除自带的测试库


drop database test;

回复 支持 反对

使用道具 举报

10#
 楼主| 发表于 2015-4-5 11:44:17 | 只看该作者

 

安装完成后,status的结果:

 

mysql> status
--------------
mysql  Ver 14.14 Distrib 5.6.23, for Linux (x86_64) using  EditLine wrapper

Connection id:          17
Current database:
Current user:           root@localhost
SSL:                    Not in use
Current pager:          stdout
Using outfile:          ''
Using delimiter:        ;
Server version:         5.6.23 Source distribution
Protocol version:       10
Connection:             Localhost via UNIX socket
Server characterset:    utf8
Db     characterset:    utf8
Client characterset:    utf8
Conn.  characterset:    utf8
UNIX socket:            /usr/local/mysql/mysql.sock
Uptime:                 59 min 32 sec

Threads: 2  Questions: 120  Slow queries: 0  Opens: 87  Flush tables: 1  Open tables: 80  Queries per second avg: 0.033
--------------

回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|手机版|小黑屋|重庆思庄Oracle、Redhat认证学习论坛 ( 渝ICP备12004239号-4 )

GMT+8, 2024-4-26 11:28 , Processed in 0.098714 second(s), 20 queries .

重庆思庄学习中心论坛-重庆思庄科技有限公司论坛

© 2001-2020

快速回复 返回顶部 返回列表