千家信息网

MySQL源码安装的方法介绍

发表于:2024-11-25 作者:千家信息网编辑
千家信息网最后更新 2024年11月25日,本篇内容主要讲解"MySQL源码安装的方法介绍",感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习"MySQL源码安装的方法介绍"吧!MYSQL的安装分三种:命令
千家信息网最后更新 2024年11月25日MySQL源码安装的方法介绍

本篇内容主要讲解"MySQL源码安装的方法介绍",感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习"MySQL源码安装的方法介绍"吧!

MYSQL的安装分三种:命令行安装、二进制安装和源码安装
命令行安装相对而言简单,我们就不做过多陈述,今天就着重讲讲MYSQL的源码安装
编译安装过程描述:

  • 1.下载源代码

  • 2.检查源码编译所需的依赖包是否齐全

  • 3.解压编译

  • 4.make && make install

  • 5.初始化数据目录

  • 6.数据库权限设置

  • 7.定义启动方式

软件安装的常规约定:

  • 软件安装包放在/usr/local/src下

  • 软件根目录basedir在/usr/local/xxx下,如:/usr/local/mysql

  • 配置文件在/etc/下,如:/etc/my.cnf

  • 数据目录datadir一般放在单独的磁盘上

  • mysql服务名为mysqld

========
准备
========
#创建数据目录
[root@xxx ~]# mkdir /data/mysql
#创建根目录
[root@xxx ~]# mkdir /usr/local/mysqlrp
#进入软件存放目录
[root@xxx ~]# cd /usr/local/src/
[root@xxx src]# mv /root/mysql-5.6.24.tar.gz .
[root@xxx src]# tar -zxvf mysql-5.6.24.tar.gz
[root@xxx src]# cd mysql-5.6.24
#检查cmake是否安装,如果未安装,请使用yum install cmake或其它方式安装
[root@xxx mysql-5.6.24]# which cmake
/usr/bin/cmake
#安装必备的依赖包
[root@xxx mysql-5.6.24]# yum install ncurses-devel
[root@xxx mysql-5.6.24]# yum install bison
#=======
编译
#=======
cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysqlrp \
-DMYSQL_DATADIR=/data/mysql \
-DSYSCONFDIR=/etc \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DMYSQL_UNIX_ADDR=/tmp/mysql.sock \
-DMYSQL_TCP_PORT=3306 \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DEXTRA_CHARSETS=all \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci

[root@xxx mysql-5.6.24]# ls /usr/local/mysqlrp/
[root@xxx mysql-5.6.24]#
[root@xxx mysql-5.6.24]# ls /data/mysql/
[root@xxx mysql-5.6.24]#
[root@xxx mysql-5.6.24]# make
[root@xxx mysql-5.6.24]# ls /usr/local/mysqlrp/
[root@xxx mysql-5.6.24]# ls /data/mysql/
[root@xxx mysql-5.6.24]#
#make install时才会在根目录下生成文件
[root@xxx mysql-5.6.24]# make install
[root@xxx mysql-5.6.24]# ls /usr/local/mysqlrp/
bin data include lib mysql-test scripts sql-bench
COPYING docs INSTALL-BINARY man README share support-files
[root@xxx mysql-5.6.24]# ls /data/mysql/
[root@xxx mysql-5.6.24]#
[root@xxx mysql-5.6.24]# cd /usr/local/mysqlrp/
#创建mysql管理用户及组
[root@xxx mysqlrp]# groupadd mysql
[root@xxx mysqlrp]# useradd mysql -g mysql
#修改配置文件,修改根目录、数据目录位置。
[root@xxx local]# vi /etc/my.cnf
...
[mysqld]
basedir=/usr/local/mysqlrp
datadir=/data/mysql
#初始化数据目录
[root@xxx mysqlrp]# ./scripts/mysql_install_db --user=mysql --defaults-file=/etc/my.cnf &
#制作mysql服务mysqld
[root@xxx mysqlrp]# cp support-files/mysql.server /etc/init.d/mysqld
#修改各个目录对应权限
[root@xxx mysqlrp]#chown -R mysql.mysql /usr/local/mysqlrp
[root@xxx mysqlrp]#chown -R mysql.mysql /data/mysql
[root@xxx mysqlrp]#chown mysql.mysql /etc/my.cnf
[root@xxx mysqlrp]#chown mysql.mysql /etc/init.d/mysqld
[root@xxx mysqlrp]#chmod -R 755 /usr/local/mysqlrp
[root@xxx mysqlrp]#chmod -R 755 /data/mysql
root@xxx mysqlrp]#chmod 644 /etc/my.cnf
[root@xxx mysqlrp]#chmod 755 /etc/init.d/mysqld
#启动mysql服务
[root@xxx local]# service mysqld start
Starting MySQL.
[ OK ]

#=======
#源码编译常见依赖包
#=======
kernel-headers-2.6.32-358.el6.x86_64.rpm
glibc-headers-2.12-1.107.el6.x86_64.rpm
glibc-devel-2.12-1.107.el6.x86_64.rpm
cpp-4.4.7-3.el6.x86_64.rpm
gcc-4.4.7-3.el6.x86_64.rpm
libstdc++-devel-4.4.7-3.el6.x86_64.rpm
gcc-c++-4.4.7-3.el6.x86_64.rpm
autoconf-2.63-5.1.el6.noarch.rpm
automake-1.11.1-4.el6.noarch.rpm
zlib-1.2.3-29.el6.x86_64.rpm
ncurses-devel-5.7-3.20090208.el6.x86_64.rpm
libgcrypt-1.4.5-9.el6_2.2.x86_64.rpm
libtool-2.2.6-15.5.el6.x86_64.rpm
bison-2.4.1-5.el6.x86_64.rpm

#=======
#附实验2则,解释常见疑问
#实验1说明,数据目录初始化的时候,必须在根目录basedir下初始化目录(具体数据目录可以自定义),使用初始化脚本进行初始化。
#实验2说明,数据库在编译的时候会修改源码里面的内容,例如src/mysql-5.6.24/support-files/mysql.server ,会将根目录修改为编译时指定的根目录
# 数据库编译时指定数据目录,安装完成后mysql工具没有指定数据目录且根目录下没有data目录会优先将编译时指定的数据目录作为自己的数据目录
#=======


点击(此处)折叠或打开

  1. #=======

  2. #实验1

  3. #=======

  4. [root@xxx mysqlrp]# mkdir /tmp/test

  5. #=======

  6. #测试进入临时目录,做数据目录初始化

  7. #=======

  8. [root@xxx mysqlrp]# cd /tmp/test/

  9. [root@xxx test]# /usr/local/mysqlrp/scripts/mysql_install_db --user=mysql &

  10. [1] 36700

  11. [root@xxx test]# FATAL ERROR: Could not find ./bin/my_print_defaults


  12. If you compiled from source, you need to run 'make install' to

  13. copy the software into the correct location ready for operation.


  14. If you are using a binary release, you must either be at the top

  15. level of the extracted archive, or pass the --basedir option

  16. pointing to that location.



  17. [1]+ Exit 1 /usr/local/mysqlrp/scripts/mysql_install_db --user=mysql

  18. [root@xxx test]# /usr/local/mysqlrp/scripts/mysql_install_db --user=mysql --datadir=/data/mysql &

  19. [1] 36704

  20. [root@xxx test]# FATAL ERROR: Could not find ./bin/my_print_defaults


  21. If you compiled from source, you need to run 'make install' to

  22. opy the software into the correct location ready for operation.


  23. If you are using a binary release, you must either be at the top

  24. level of the extracted archive, or pass the --basedir option

  25. pointing to that location.



  26. [1]+ Exit 1 /usr/local/mysqlrp/scripts/mysql_install_db --user=mysql --datadir=/data/mysql

  27. [root@xxx test]# /usr/local/mysqlrp/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysqlrp --datadir=/data/mysql &

  28. #=======

  29. #指定了根目录后总算初始化成功

  30. #=======

  31. [root@xxx mysqlrp]# cp support-files/mysql.server /etc/init.d/mysqld

  32. [root@xxx mysqlrp]# chown -R mysql.mysql /usr/local/mysql

  33. [root@xxx mysqlrp]# chown -R mysql.mysql /data/mysql/

  34. [root@xxx mysqlrp]# mkdir log

  35. [root@xxx mysqlrp]# chown -R mysql.mysql log

  36. [root@xxx mysqlrp]# ./bin/mysqld_safe --user=mysql &

  37. [1] 37694

  38. [root@xxx mysqlrp]# 151113 15:45:58 mysqld_safe Logging to '/data/mysql/zc-appname-ip-ip.err'.

  39. 151113 15:45:59 mysqld_safe Starting mysqld daemon with databases from /data/mysql

  40. 151113 15:45:59 mysqld_safe mysqld from pid file /data/mysql/zc-appname-ip-ip.pid ended


  41. [1]+ Done ./bin/mysqld_safe --user=mysql

  42. [root@xxx mysqlrp]# ps -ef|grep mysql

  43. root 37847 12729 0 15:46 pts/3 00:00:00 grep mysql

  44. #=======

  45. #试图启动,失败

  46. #=======

  47. [root@xxx local]# mv mysqlrp/ mysql

  48. [root@xxx mysqlrp]# chown -R mysql.mysql /usr/local/mysql

  49. [root@xxx local]# mv mysql/ mysqlrp

  50. [root@xxx local]# service mysqld start

  51. Starting MySQL.The server quit without updating PID file (/data/mysql/zc-appname-ip-ip.pid). [FAILED]

  52. #=======

  53. #试图启动,失败

  54. #=======

  55. [root@xxx local]# cd mysqlrp/

  56. [root@xxx mysqlrp]# ./bin/mysqld

  57. mysqld mysqld_multi mysqld_safe mysqldump mysqldumpslow

  58. [root@xxx mysqlrp]# ./bin/mysqld_safe --user=mysql&

  59. [1] 38052

  60. [root@xxx mysqlrp]# 151113 15:49:31 mysqld_safe Logging to '/data/mysql/zc-appname-ip-ip.err'.

  61. 151113 15:49:31 mysqld_safe Starting mysqld daemon with databases from /data/mysql

  62. 151113 15:49:32 mysqld_safe mysqld from pid file /data/mysql/zc-appname-ip-ip.pid ended


  63. [1]+ Done ./bin/mysqld_safe --user=mysql

  64. [root@xxx mysqlrp]# ps -ef|grep mysql

  65. root 38205 12729 0 15:49 pts/3 00:00:00 grep mysql

  66. #=======

  67. #试图启动,失败

  68. #=======

  69. [root@xxx mysqlrp]# ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql/ &

  70. #=======

  71. #初始化数据目录成功

  72. #=======

  73. [root@xxx mysqlrp]# ./scripts/mysql_install_db --user=mysql --datadir=/usr/local/mysqlrp/data/ &

  74. #=======

  75. #再次初始化数据目录,成功

  76. #=======

  77. [root@xxx mysqlrp]# ./bin/mysqld_safe --user=mysql &

  78. [1] 38312

  79. [root@xxx mysqlrp]# 151113 15:56:03 mysqld_safe Logging to '/usr/local/mysqlrp/data/zc-appname-ip-ip.err'.

  80. 151113 15:56:03 mysqld_safe Starting mysqld daemon with databases from /usr/local/mysqlrp/data


  81. [root@xxx mysqlrp]# ps -ef|grep mysql

  82. root 38312 12729 0 15:56 pts/3 00:00:00 /bin/sh ./bin/mysqld_safe --user=mysql

  83. mysql 38441 38312 3 15:56 pts/3 00:00:00 /usr/local/mysqlrp/bin/mysqld --basedir=/usr/local/mysqlrp --datadir=/usr/local/mysqlrp/data --plugin-dir=/usr/local/mysqlrp/lib/plugin --user=mysql --log-error=/usr/local/mysqlrp/data/zc-appname-ip-ip.err --pid-file=/usr/local/mysqlrp/data/zc-appname-ip-ip.pid --socket=/tmp/mysql.sock

  84. root 38465 12729 0 15:56 pts/3 00:00:00 grep mysql

  85. #=======

  86. #试图启动,成功

  87. #=======


  88. #=======

  89. #实验2

  90. #=======

  91. [root@xxx mysqlrp]# 151113 15:56:43 mysqld_safe mysqld from pid file /usr/local/mysqlrp/data/zc-appname-ip-ip.pid ended

  92. ps

  93. PID TTY TIME CMD

  94. 12729 pts/3 00:00:00 bash

  95. 38471 pts/3 00:00:00 ps

  96. [1]+ Done ./bin/mysqld_safe --user=mysql

  97. [root@xxx mysqlrp]# ps -ef|grep mysql

  98. root 38473 12729 0 15:56 pts/3 00:00:00 grep mysql

  99. [root@xxx mysqlrp]# service mysqld start

  100. Starting MySQL.The server quit without updating PID file (/[FAILED]ql/zc-appname-ip-ip.pid).

  101. [root@xxx mysqlrp]#

  102. [root@xxx local]# cp src/mysql-5.6.24/support-files/mysql.server /etc/init.d/mysqldcp: overwrite `/etc/init.d/mysqld'? y

  103. [root@xxx local]# service mysqld start

  104. /etc/init.d/mysqld: line 256: my_print_defaults: command not found

  105. /etc/init.d/mysqld: line 276: cd: /usr/local/mysqlrp: No such file or directory

  106. Starting MySQLCouldn't find MySQL server (/usr/local/mysqlr[FAILED]sqld_safe)

  107. [root@xxx local]# mv mysql mysqlrp

  108. [root@xxx local]# service mysqld start

  109. Starting MySQL.The server quit without updating PID file (/[FAILED]ql/zc-appname-ip-ip.pid).

  110. [root@xxx local]# vi /etc/my.cnf

  111. datadir=xxxx

  112. [root@xxx local]# service mysqld start

  113. Starting MySQL.

  114. [ OK ]

到此,相信大家对"MySQL源码安装的方法介绍"有了更深的了解,不妨来实际操作一番吧!这里是网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!

0