数据库学习之--RedHat EL55下Mysql源码包安装

时间:2023-01-12 17:07:36

数据库学习之--RedHat EL55下Mysql源码包安装

系统环境

操作系统:RedHat EL55

DB Soft:  Mysql 5.6.4-m7

    Mysql 在linux下的安装方式有两种版本,一种为Binary(二进制),另外一种为Source(源码包),本文为Source Install方式。

1、安装前的准备

解压安装包


[oracle@ogg ~]$ ls

[cpp] view plaincopyprint?
  1. mysql-5.6.4-m7  mysql-5.6.4-m7.tar.gz  mysql-5.6.4-m7.tar.zip  ogg  oradiag_oracle  Readme--?+?.htm  

[oracle@ogg ~]$ cd mysql-5.6.4-m7

[cpp] view plaincopyprint?
  1. [oracle@ogg mysql-5.6.4-m7]$ ls  
  2. BUILD        CMakeLists.txt   COPYING              extra               libmysql     mysql-test  README   sql-bench   support-files  vio  
  3. BUILD-CMAKE  cmd-line-utils   dbug                 include             libmysqld    mysys       regex    sql-common  tests          win  
  4. client       config.h.cmake   Docs                 INSTALL-SOURCE      libservices  packaging   scripts  storage     unittest       zlib  
  5. cmake        configure.cmake  Doxyfile-perfschema  INSTALL-WIN-SOURCE  man          plugin      sql      strings     VERSION  

[oracle@ogg mysql-5.6.4-m7]$ tar zxvf mysql-5.6.4-m7.tar.gz

[cpp] view plaincopyprint?
  1. mysql-5.6.4-m7/mysql-test/lib/My/SafeProcess/  
  2. mysql-5.6.4-m7/mysql-test/lib/My/SafeProcess/safe_process.cc  
  3. mysql-5.6.4-m7/mysql-test/lib/My/SafeProcess/safe_kill_win.cc  
  4. mysql-5.6.4-m7/mysql-test/lib/My/SafeProcess/safe_process_win.cc  
  5. mysql-5.6.4-m7/mysql-test/lib/My/SafeProcess/Base.pm  
  6. mysql-5.6.4-m7/mysql-test/lib/My/SafeProcess/CMakeLists.txt  
  7. ……  

查看官方安装文档:INSTALL-SOURCE

 To install and use a MySQL binary distribution, the basic command

  sequence looks like this:

[cpp] view plaincopyprint?
  1. shell> groupadd mysql  
  2. shell> useradd -r -g mysql mysql  
  3. shell> cd /usr/local  
  4. shell> tar zxvf /path/to/mysql-VERSION-OS.tar.gz  
  5. shell> ln -s full-path-to-mysql-VERSION-OS mysql  
  6. shell> cd mysql  
  7. shell> chown -R mysql .  
  8. shell> chgrp -R mysql .  
  9. shell> scripts/mysql_install_db --user=mysql  
  10. shell> chown -R root .  
  11. shell> chown -R mysql data  
  12. # Next command is optional  
  13. shell> cp support-files/my-medium.cnf /etc/my.cnf  
  14. shell> bin/mysqld_safe --user=mysql &  
  15. # Next command is optional  
  16. shell> cp support-files/mysql.server /etc/init.d/mysql.server  

 For example, with a compressed tar file source distribution on Unix, the basic installation command

sequence looks like this:

[cpp] view plaincopyprint?
  1. # Preconfiguration setup  
  2. shell> groupadd mysql  
  3. shell> useradd -r -g mysql mysql  
  4. # Beginning of source-build specific instructions  
  5. shell> tar zxvf mysql-VERSION.tar.gz  
  6. shell> cd mysql-VERSION  
  7. shell> cmake .  
  8. shell> make  
  9. shell> make install  
  10. # End of source-build specific instructions  
  11. # Postinstallation setup  
  12. shell> cd /usr/local/mysql  
  13. shell> chown -R mysql .  
  14. shell> chgrp -R mysql .  
  15. shell> scripts/mysql_install_db --user=mysql  
  16. shell> chown -R root .  
  17. shell> chown -R mysql data  
  18. # Next command is optional  
  19. shell> cp support-files/my-medium.cnf /etc/my.cnf  
  20. shell> bin/mysqld_safe --user=mysql &  
  21. # Next command is optional  
  22. shell> cp support-files/mysql.server /etc/init.d/mysql.server  

2、准备源码安装所需要的工具和库文件(RedHat 安装光盘)

[cpp] view plaincopyprint?
  1. [root@ogg ~]# rpm -qa |grep make  
  2. automake-1.11.1-1.2.el6.noarch  
  3. make-3.81-19.el6.i686  
  4.   
  5. [root@ogg ~]# rpm -qa |grep bison  
  6. bison-2.4.1-5.el6.i686  
  7.   
  8. [root@ogg ~]# rpm -qa |grep gcc  
  9. gcc-c++-4.4.4-13.el6.i686  
  10. libgcc-4.4.4-13.el6.i686  
  11. gcc-4.4.4-13.el6.i686  
  12. gcc-gfortran-4.4.4-13.el6.i686  
  13. compat-libgcc-296-2.96-144.el6.i686  
  14.   
  15. [root@ogg ~]# rpm -qa |grep cmake  
  16.   
  17. [root@ogg ~]# rpm -qa |grep ncur  
  18. ncurses-base-5.7-3.20090208.el6.i686  
  19. ncurses-libs-5.7-3.20090208.el6.i686  
  20. ncurses-5.7-3.20090208.el6.i686  
  21. ncurses-devel-5.7-3.20090208.el6.i686  
  22.   
  23. 挂载RedHat安装光盘  
  24. [root@ogg ~]# mount /dev/cdrom /media/  
  25. mount: block device /dev/sr0 is write-protected, mounting read-only  
  26. [root@ogg ~]# cd /media/  
  27. [root@ogg media]# cd Server/  
  28. [root@ogg Server]# ls  
  29. Packages  repodata  TRANS.TBL  
  30. [root@ogg Server]# cd Packages/  
  31.   
  32. [root@ogg Packages]# ls |grep make  
  33. automake-1.11.1-1.2.el6.noarch.rpm  
  34. imake-1.0.2-11.el6.i686.rpm  
  35. make-3.81-19.el6.i686.rpm  
  36. makebootfat-1.4-10.el6.i686.rpm  
  37. pacemaker-1.1.2-7.el6.i686.rpm  
  38. pacemaker-libs-1.1.2-7.el6.i686.rpm    

对于RedHat EL55系统,安装光盘不包含cmake文件,需要从网上下载安装

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


[root@rh55 soft]# ls
cmake-3.2.3  cmake-3.2.3.tar.gz  
[root@rh55 soft]# tar zxvf cmake-3.2.3.tar.gz 

cmake-3.2.3/Utilities/cmliblzma/liblzma/delta/delta_decoder.h
cmake-3.2.3/Utilities/cmliblzma/liblzma/delta/delta_encoder.c
cmake-3.2.3/Utilities/cmliblzma/liblzma/delta/delta_encoder.h
cmake-3.2.3/Utilities/cmliblzma/liblzma/delta/delta_private.h
cmake-3.2.3/Utilities/cmliblzma/liblzma/liblzma.pc.in
cmake-3.2.3/Utilities/cmliblzma/liblzma/liblzma_w32res.rc
cmake-3.2.3/Utilities/cmliblzma/liblzma/lz/lz_decoder.c
cmake-3.2.3/Utilities/cmliblzma/liblzma/lz/lz_decoder.h
cmake-3.2.3/Utilities/cmliblzma/liblzma/lz/lz_encoder.c
cmake-3.2.3/Utilities/cmliblzma/liblzma/lz/lz_encoder.h
cmake-3.2.3/Utilities/cmliblzma/liblzma/lz/lz_encoder_hash.h
cmake-3.2.3/Utilities/cmliblzma/liblzma/lz/lz_encoder_hash_table.h
cmake-3.2.3/Utilities/cmliblzma/liblzma/lz/lz_encoder_mf.c
cmake-3.2.3/Utilities/cmliblzma/liblzma/lzma/fastpos.h
cmake-3.2.3/Utilities/cmliblzma/liblzma/lzma/fastpos_table.c
cmake-3.2.3/Utilities/cmliblzma/liblzma/lzma/fastpos_tablegen.c
cmake-3.2.3/Utilities/cmliblzma/liblzma/lzma/lzma2_decoder.c
cmake-3.2.3/Utilities/cmliblzma/liblzma/lzma/lzma2_decoder.h
cmake-3.2.3/Utilities/cmliblzma/liblzma/lzma/lzma2_encoder.c
......
通过源码包编译安装cmake:


[root@rh55 cmake-3.2.3]# ./configure --prefix=/usr/local/cmake

CMake 3.2.3, Copyright 2000-2015 Kitware, Inc.
Found GNU toolchain
C compiler on this system is: gcc
C++ compiler on this system is: g++
Makefile processor on this system is: gmake
g++ is GNU compiler
g++ has setenv
g++ has unsetenv
g++ does not have environ in stdlib.h
g++ has STL in std:: namespace
g++ has ANSI streams
g++ has streams in std:: namespace
g++ has sstream
g++ has operator!=(string, char*)
g++ has stl iterator_traits
g++ has standard template allocator
g++ has allocator<>::rebind<>
g++ does not have non-standard allocator<>::max_size argument
g++ has stl containers supporting allocator objects
g++ has stl wstring
g++ has header cstddef
g++ requires template friends to use <>
g++ supports member templates
g++ has standard template specialization syntax
g++ has argument dependent lookup
.......
[root@rh55 cmake-3.2.3]# make
Scanning dependencies of target cmIML_test
[ 0%] Building C object Utilities/KWIML/test/CMakeFiles/cmIML_test.dir/test.c.o
[ 0%] Building C object Utilities/KWIML/test/CMakeFiles/cmIML_test.dir/test_ABI_C.c.o
[ 0%] Building C object Utilities/KWIML/test/CMakeFiles/cmIML_test.dir/test_INT_C.c.o
[ 0%] Building C object Utilities/KWIML/test/CMakeFiles/cmIML_test.dir/test_include_C.c.o
[ 1%] Building CXX object Utilities/KWIML/test/CMakeFiles/cmIML_test.dir/test_ABI_CXX.cxx.o
[ 1%] Building CXX object Utilities/KWIML/test/CMakeFiles/cmIML_test.dir/test_INT_CXX.cxx.o
[ 1%] Building CXX object Utilities/KWIML/test/CMakeFiles/cmIML_test.dir/test_include_CXX.cxx.o
Linking CXX executable cmIML_test
[ 1%] Built target cmIML_test
Scanning dependencies of target cmsys
[ 1%] Building C object Source/kwsys/CMakeFiles/cmsys.dir/ProcessUNIX.c.o
[ 1%] Building C object Source/kwsys/CMakeFiles/cmsys.dir/Base64.c.o
[ 2%] Building C object Source/kwsys/CMakeFiles/cmsys.dir/EncodingC.c.o
[ 2%] Building C object Source/kwsys/CMakeFiles/cmsys.dir/MD5.c.o
[ 2%] Building C object Source/kwsys/CMakeFiles/cmsys.dir/Terminal.c.o
[ 2%] Building C object Source/kwsys/CMakeFiles/cmsys.dir/System.c.o
[ 2%] Building C object Source/kwsys/CMakeFiles/cmsys.dir/String.c.o
[ 2%] Building CXX object Source/kwsys/CMakeFiles/cmsys.dir/Directory.cxx.o
[ 3%] Building CXX object Source/kwsys/CMakeFiles/cmsys.dir/DynamicLoader.cxx.o
[ 3%] Building CXX object Source/kwsys/CMakeFiles/cmsys.dir/EncodingCXX.cxx.o
[ 3%] Building CXX object Source/kwsys/CMakeFiles/cmsys.dir/Glob.cxx.o
......
[100%] Built target foo
[root@rh55 cmake-3.2.3]# make install
[  1%] Built target cmIML_test
[ 4%] Built target cmsys
[ 4%] Built target cmsysTestDynload
[ 5%] Built target cmsys_c
[ 5%] Built target cmsysTestProcess
[ 5%] Built target cmsysTestSharedForward
[ 6%] Built target cmsysTestsC
[ 8%] Built target cmsysTestsCxx
[ 10%] Built target cmzlib
[ 28%] Built target cmcurl
[ 28%] Built target LIBCURL
[ 29%] Built target cmcompress
[ 30%] Built target cmbzip2
[ 41%] Built target cmliblzma
[ 58%] Built target cmlibarchive
[ 59%] Built target cmexpat
[ 59%] Built target cmjsoncpp
[ 66%] Built target cmForm
[ 84%] Built target CMakeLib
[ 87%] Built target CPackLib
[ 95%] Built target CTestLib
......
Installing: /usr/local/cmake/bin/cmake
-- Installing: /usr/local/cmake/bin/ctest
-- Installing: /usr/local/cmake/bin/cpack
-- Installing: /usr/local/cmake/share/cmake-3.2/include/cmCPluginAPI.h
-- Installing: /usr/local/cmake/share/cmake-3.2/editors/vim/cmake-help.vim
-- Installing: /usr/local/cmake/share/cmake-3.2/editors/vim/cmake-indent.vim
-- Installing: /usr/local/cmake/share/cmake-3.2/editors/vim/cmake-syntax.vim
-- Installing: /usr/local/cmake/share/cmake-3.2/editors/emacs/cmake-mode.el
-- Installing: /usr/local/cmake/share/aclocal/cmake.m4
-- Installing: /usr/local/cmake/share/cmake-3.2/completions/cmake
-- Installing: /usr/local/cmake/share/cmake-3.2/completions/cpack
-- Installing: /usr/local/cmake/share/cmake-3.2/completions/ctest
安装完成校验:
[root@rh55 ~]# cd /usr/local/cmake
[root@rh55 cmake]# ls -l
total 12
drwxr-xr-x 2 root root 4096 Jun  9 17:47 bin
drwxr-xr-x 3 root root 4096 Jun  9 17:47 doc
drwxr-xr-x 4 root root 4096 Jun  9 17:47 share
[root@rh55 cmake]# cd bin
[root@rh55 bin]# ls -l
total 41812
-rwxr-xr-x 1 root root 10054392 Jun  9 17:46 ccmake
-rwxr-xr-x 1 root root  9969999 Jun  9 17:46 cmake
-rwxr-xr-x 1 root root 10764389 Jun  9 17:46 cpack
-rwxr-xr-x 1 root root 11948376 Jun  9 17:46 ctest
建立可执行文件查找路径:
[root@rh55 bin]# cat /etc/profile
export PATH=$PATH:/usr/local/cmake/bin


cmake安装成功后,安装mysql源码包:

3、源码安装,检测编译环境

[root@rh55 mysql-5.6.4-m7]# cmake ./

[cpp] view plaincopyprint?
  1. -- The C compiler identification is GNU  
  2. -- The CXX compiler identification is GNU  
  3. -- Check for working C compiler: /usr/bin/gcc  
  4. -- Check for working C compiler: /usr/bin/gcc -- works  
  5. -- Detecting C compiler ABI info  
  6. -- Detecting C compiler ABI info - done  
  7. -- Check for working CXX compiler: /usr/bin/c++  
  8. -- Check for working CXX compiler: /usr/bin/c++ -- works  
  9. -- Detecting CXX compiler ABI info  
  10. -- Detecting CXX compiler ABI info - done  
  11. -- Looking for SHM_HUGETLB  
  12. -- Looking for SHM_HUGETLB - found  
  13. -- MySQL 5.6.4-m7  
  14. -- Looking for sys/types.h  
  15. -- Looking for sys/types.h - found  
  16. -- Looking for stdint.h  
  17. -- Looking for stdint.h - found  

......

[cpp] view plaincopyprint?
  1. -- Performing Test HAVE_IB_GCC_ATOMIC_BUILTINS  
  2. -- Performing Test HAVE_IB_GCC_ATOMIC_BUILTINS - Success  
  3. -- Performing Test HAVE_IB_ATOMIC_PTHREAD_T_GCC  
  4. -- Performing Test HAVE_IB_ATOMIC_PTHREAD_T_GCC - Success  
  5. -- Check size of pthread_t  
  6. -- Check size of pthread_t - done  
  7. -- Performing Test HAVE_PEERCRED  
  8. -- Performing Test HAVE_PEERCRED - Success  
  9. -- Googletest 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.  
  10. -- If you are inside a firewall, you may need to use an http proxy: export http_proxy=http://foo.bar.com:80  
  11. -- Configuring done  
  12. -- Generating done  
  13. -- Build files have been written to: /home/oracle/mysql-5.6.4-m7  

可以指定一下参数:

[cpp] view plaincopyprint?
  1. # -DCMAKE_INSTALL_PREFIX=/usr/local/mysql          \    #安装路径  
  2. # -DMYSQL_DATADIR=/usr/local/mysql/data            \    #数据文件存放位置  
  3. # -DSYSCONFDIR=/etc                                \    #my.cnf路径  
  4. # -DWITH_MYISAM_STORAGE_ENGINE=1                   \    #支持MyIASM引擎  
  5. # -DWITH_INNOBASE_STORAGE_ENGINE=1                 \    #支持InnoDB引擎  
  6. # -DWITH_MEMORY_STORAGE_ENGINE=1                   \    #支持Memory引擎  
  7. # -DWITH_READLINE=1                                \    #快捷键功能(我没用过)  
  8. # -DMYSQL_UNIX_ADDR=/tmp/mysqld.sock               \    #连接数据库socket路径  
  9. # -DMYSQL_TCP_PORT=3306                            \    #端口  
  10. # -DENABLED_LOCAL_INFILE=1                         \    #允许从本地导入数据  
  11. # -DWITH_PARTITION_STORAGE_ENGINE=1                \    #安装支持数据库分区  
  12. # -DEXTRA_CHARSETS=all                             \    #安装所有的字符集  
  13. # -DDEFAULT_CHARSET=utf8                           \    #默认字符  
  14. # -DDEFAULT_COLLATION=utf8_general_ci  

4、编译

[root@rh55 mysql-5.6.4-m7]# make

[cpp] view plaincopyprint?
  1. Scanning dependencies of target INFO_BIN  
  2. [  0%] Built target INFO_BIN  
  3. Scanning dependencies of target INFO_SRC  
  4. [  0%] Built target INFO_SRC  
  5. Scanning dependencies of target abi_check  
  6. [  0%] Built target abi_check  
  7. [  1%] Generating common.h  
  8. [  1%] Generating help.c  
  9. [  1%] Generating help.h  
  10. [  1%] Generating vi.h  
  11. [  1%] Generating emacs.h  
  12. [  1%] Generating fcns.c  
  13. [  1%] Generating fcns.h  
  14. Scanning dependencies of target edit  
  15. ......  

5、安装

[root@rh55 mysql-5.6.4-m7]# make install

[cpp] view plaincopyprint?
  1. -- Installing: /usr/local/mysql/mysql-test/./extra/rpl_tests/rpl_row_sp003.test  
  2. -- Installing: /usr/local/mysql/mysql-test/./extra/rpl_tests/rpl_mts_crash_safe.inc  
  3. -- Installing: /usr/local/mysql/mysql-test/./extra/rpl_tests/rpl_stm_EE_err2.test  
  4. -- Installing: /usr/local/mysql/mysql-test/./extra/rpl_tests/rpl_ndb_apply_status.test  
  5. -- Installing: /usr/local/mysql/mysql-test/./extra/rpl_tests/rpl_mixing_engines.test  
  6. -- Installing: /usr/local/mysql/mysql-test/./extra/rpl_tests/rpl_extra_col_slave.test  
  7. -- Installing: /usr/local/mysql/mysql-test/./extra/rpl_tests/type_conversions.test  
  8. -- Installing: /usr/local/mysql/mysql-test/./extra/rpl_tests/rpl_row_func003.test  
  9. -- Installing: /usr/local/mysql/mysql-test/./extra/rpl_tests/rpl_row_sp002.test  
  10. ......  

@至此,mysql安装完成!


6、数据库配置

[java] view plaincopyprint?
  1. 初始化数据库  
  2. [root@ogg mysql]#cd /usr/local/mysql  
  3. [root@ogg mysql]# ls  
  4. bin  COPYING  data  docs  include  INSTALL-BINARY  lib  man  mysql-5.6.4-m7  mysql-test  README  scripts  share  sql-bench  support-files  
  5.   
  6. [root@ogg mysql]# chown -R mysql:mysql .  
  7.   
  8. [root@ogg mysql]# scripts/mysql_install_db --user=mysql  
  9. Installing MySQL system tables...  
  10. 140917 13:51:22 InnoDB: The InnoDB memory heap is disabled  
  11. 140917 13:51:22 InnoDB: Mutexes and rw_locks use GCC atomic builtins  
  12. 140917 13:51:22 InnoDB: Compressed tables use zlib 1.2.3  
  13. 140917 13:51:22 InnoDB: Using Linux native AIO  
  14. 140917 13:51:22 InnoDB: CPU does not support crc32 instructions  
  15. 140917 13:51:22 InnoDB: Initializing buffer pool, size = 128.0M  
  16. 140917 13:51:22 InnoDB: Completed initialization of buffer pool  
  17. InnoDB: The first specified data file ./ibdata1 did not exist:  
  18. InnoDB: a new database to be created!  
  19. 140917 13:51:22 InnoDB: Setting file ./ibdata1 size to 10 MB  
  20. InnoDB: Database physically writes the file full: wait...  
  21.   
  22. [root@ogg mysql]# chown -R mysql:mysql ./data  
  23. [root@ogg mysql]# chmod -R ug+rws .  
  24.   
  25. [root@ogg mysql]# cp support-files/my-medium.cnf /etc/my.cnf  
  26. cp: overwrite `/etc/my.cnf'? y  
  27.   
  28. 配置参数文件  
  29. [root@ogg mysql]# vi /etc/my.cnf  
  30. [mysqld]  
  31. port            = 3306  
  32. socket          = /tmp/mysql.sock  
  33. skip-external-locking  
  34. key_buffer_size = 16M  
  35. max_allowed_packet = 1M  
  36. table_open_cache = 64  
  37. sort_buffer_size = 512K  
  38. net_buffer_length = 8K  
  39. read_buffer_size = 256K  
  40. read_rnd_buffer_size = 512K  
  41. myisam_sort_buffer_size = 8M  
  42. user=mysql  
  43. datadir=/usr/local/mysql/data/mysql  
  44. default-storage-engine=MyISAM  

7、启动数据库

[root@rh55 mysql]# bin/mysqld_safe --user=mysql &

[1] 16592

[java] view plaincopyprint?
  1. [root@ogg mysql]# 140917 13:56:51 mysqld_safe Logging to '/usr/local/mysql/data/mysql/ogg.err'.  
  2. 140917 13:56:51 mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data/mysql  
  3. 140917 13:56:53 mysqld_safe mysqld from pid file /usr/local/mysql/data/mysql/ogg.pid ended  
  4. [1]+  Done                    bin/mysqld_safe --user=mysql  
  5. [root@ogg mysql]# ps -ef |grep mysql  
  6. root     16888  5955  0 13:57 pts/1    00:00:00 grep mysql  

数据库启动失败!

查看日志:

[root@rh55 mysql]# cat /usr/local/mysql/data/mysql/ogg.err

[java] view plaincopyprint?
  1. 140917 13:56:51 mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data/mysql  
  2. /usr/local/mysql/bin/mysqld: Table 'mysql.plugin' doesn't exist  
  3. 140917 13:56:51 [ERROR] Can't open the mysql.plugin table. Please run mysql_upgrade to create it.  
  4. 140917 13:56:51 InnoDB: The InnoDB memory heap is disabled  
  5. 140917 13:56:51 InnoDB: Mutexes and rw_locks use GCC atomic builtins  
  6. 140917 13:56:51 InnoDB: Compressed tables use zlib 1.2.3  
  7. 140917 13:56:51 InnoDB: Using Linux native AIO  
  8. 140917 13:56:51 InnoDB: CPU does not support crc32 instructions  
  9. 140917 13:56:51 InnoDB: Initializing buffer pool, size = 128.0M  
  10. 140917 13:56:52 InnoDB: Completed initialization of buffer pool  
  11. InnoDB: The first specified data file ./ibdata1 did not exist:  
  12. InnoDB: a new database to be created!  
  13. 140917 13:56:52 InnoDB: Setting file ./ibdata1 size to 10 MB  
  14. InnoDB: Database physically writes the file full: wait...  
  15. 140917 13:56:52 InnoDB: Log file ./ib_logfile0 did not exist: new to be created  
  16. InnoDB: Setting log file ./ib_logfile0 size to 5 MB  
  17. InnoDB: Database physically writes the file full: wait...  
  18. 140917 13:56:52 InnoDB: Log file ./ib_logfile1 did not exist: new to be created  
  19. InnoDB: Setting log file ./ib_logfile1 size to 5 MB  
  20. InnoDB: Database physically writes the file full: wait...  
  21. InnoDB: Doublewrite buffer not found: creating new  
  22. InnoDB: Doublewrite buffer created  
  23. 140917 13:56:52 InnoDB: 128 rollback segment(s) are active.  
  24. InnoDB: Creating foreign key constraint system tables  
  25. InnoDB: Foreign key constraint system tables created  
  26. 140917 13:56:52 InnoDB: Waiting for the background threads to start  
  27. 140917 13:56:53 InnoDB: 1.2.4 started; log sequence number 0  
  28. 140917 13:56:53 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 6c803c62-3e2f-11e4-9db1-0800270ccfcc.  
  29. 140917 13:56:53 [ERROR] Fatal error: Can't open and lock privilege tables: Table 'mysql.host' doesn't exist  
  30. 140917 13:56:53 mysqld_safe mysqld from pid file /usr/local/mysql/data/mysql/ogg.pid ended  

重新启动数据库

[root@rh55 mysql]# cd bin

[root@rh55 bin]# ./mysqld

./mysqld: Table 'mysql.plugin' doesn't exist
140917 13:58:17 [ERROR] Can't open the mysql.plugin table. Please run mysql_upgrade to create it.
140917 13:58:17 InnoDB: The InnoDB memory heap is disabled
140917 13:58:17 InnoDB: Mutexes and rw_locks use GCC atomic builtins
140917 13:58:17 InnoDB: Compressed tables use zlib 1.2.3
140917 13:58:17 InnoDB: Using Linux native AIO
140917 13:58:17 InnoDB: CPU does not support crc32 instructions
140917 13:58:17 InnoDB: Initializing buffer pool, size = 128.0M
140917 13:58:17 InnoDB: Completed initialization of buffer pool
140917 13:58:17 InnoDB: highest supported file format is Barracuda.
InnoDB: Log scan progressed past the checkpoint lsn 48961
140917 13:58:17  InnoDB: Database was not shut down normally!
InnoDB: Starting crash recovery.
InnoDB: Reading tablespace information from the .ibd files...
InnoDB: Restoring possible half-written data pages from the doublewrite
InnoDB: buffer...
InnoDB: Doing recovery: scanned up to log sequence number 1595695
140917 13:58:17  InnoDB: Starting an apply batch of log records to the database...
InnoDB: Progress in percents: 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
InnoDB: Apply batch completed
140917 13:58:17 InnoDB: 128 rollback segment(s) are active.
140917 13:58:17 InnoDB: Waiting for the background threads to start
140917 13:58:18 InnoDB: 1.2.4 started; log sequence number 1595695
140917 13:58:18 [Note] Recovering after a crash using mysql-bin
140917 13:58:18 [Note] Starting crash recovery...
140917 13:58:18 [Note] Crash recovery finished.
140917 13:58:18 [ERROR] Fatal error: Can't open and lock privilege tables: Table 'mysql.host' doesn't exist

数据库启动失败 

140917 13:58:18 [ERROR] Fatal error: Can't open and lock privilege tables: Table 'mysql.host' doesn't exist

解决方法:

修改/etc/my.cnf

[mysqld]

datadir=/var/lib/mysql

重新指定数据库数据文件的位置!

再次启动Database:

[root@rh55 mysql]# bin/mysqld_safe --user=mysql &

[java] view plaincopyprint?
  1. [root@ogg data]# ps -ef |grep mysql  
  2. root     16955  5955  0 14:03 pts/1    00:00:00 /bin/sh ./mysqld_safe --user=mysql  
  3. mysql    17229 16955  0 14:03 pts/1    00:00:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/var/lib/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/var/lib/mysql/ogg.err --pid-file=/var/lib/mysql/ogg.pid --socket=/tmp/mysql.sock --port=3306  
  4.   
  5. [root@ogg data]# netstat -an|grep 3306  
  6. tcp        0      0 0.0.0.0:3306                0.0.0.0:*                   LISTEN  

数据库启动成功!

配置数据库启动脚本,加入系统启动环境

[java] view plaincopyprint?
  1. [root@ogg mysql]# cp support-files/mysql.server  /etc/init.d/mysql  
  2.   
  3. [root@ogg mysql]# service mysql stop  
  4. Shutting down MySQL..140917 14:06:29 mysqld_safe mysqld from pid file /var/lib/mysql/ogg.pid ended  
  5.                                                            [  OK  ]  
  6. [1]+  Done                    ./mysqld_safe --user=mysql  (wd: /usr/local/mysql/bin)  
  7. (wd now: /usr/local/mysql)  
  8. [root@ogg data]# netstat -an|grep 3306  
  9.   
  10. [root@ogg mysql]# service mysql start  
  11. Starting MySQL..     
  12. [root@ogg data]# netstat -an|grep 3306  
  13. tcp        0      0 0.0.0.0:3306                0.0.0.0:*                   LISTEN                                        [  OK  ]  

8、连接使用mysql database

修改管理员密码
[root@rh55 mysql]# cd /usr/local/mysql/
[root@rh55 mysql]# ./bin/mysqladmin -u root password
New password:
Confirm new password:

连接数据库
[root@rh55 mysql]# ./bin/mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.4-m7-log Source distribution
Copyright (c) 2000, 2011, 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> select * from tab;
ERROR 1046 (3D000): No database selected

mysql> use mysql
Database changed

mysql> select * from tab;
ERROR 1146 (42S02): Table 'mysql.tab' doesn't exist
mysql> select host,user from mysql.user;
+-----------+------+
| host      | user |
+-----------+------+
| 127.0.0.1 | root |
| ::1       | root |
| localhost |      |
| localhost | root |
| ogg       |      |
| ogg       | root |
+-----------+------+
6 rows in set (0.00 sec)
mysql>

@至此,mysql database安装、连接成功!