源码编译安装mysql
1、安装相关的软件包
1 2 3 4 5 6 7 8 | cd / home / bill / tools / tar xf cmake - 2.8 . 8.tar .gz cd cmake - 2.8 . 8 . / configure #CMake has bootstrapped. Now run gmake. gmake gmake install cd .. / |
2、安装依赖包
1 2 | 依赖包<br>如果需要可以换一下yum源:http: / / mirrors.aliyun.com / help / centos yum install ncurses - devel - y<br>yum - y install gcc gcc - c + + git <br>yum - y install autoconf |
3、开始安装mysql
1 2 3 | 创建用户和组 groupadd mysql useradd mysql - s / sbin / nologin - M - g mysql |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | 解压编译MySQL tar zxf mysql - 5.5 . 32.tar .gz cd mysql - 5.5 . 32 cmake . - DCMAKE_INSTALL_PREFIX = / usr / local / mysql \ - DMYSQL_DATADIR = / usr / local / mysql / data \ - DDEFAULT_CHARSET = utf8 \ - DDEFAULT_COLLATION = utf8_general_ci \ - DEXTRA_CHARSETS = gbk,gb2312,utf8,ascii \ - DENABLED_LOCAL_INFILE = ON \ - DWITH_INNOBASE_STORAGE_ENGINE = 1 \ - DWITH_FEDERATED_STORAGE_ENGINE = 1 \ - DWITH_BLACKHOLE_STORAGE_ENGINE = 1 \ - DWITHOUT_EXAMPLE_STORAGE_ENGINE = 1 \ - DWITHOUT_PARTITION_STORAGE_ENGINE = 0 \ - DWITH_FAST_MUTEXES = 1 \ - DWITH_ZLIB = bundled \ - DENABLED_LOCAL_INFILE = 1 \ - DWITH_READLINE = 1 \ - DWITH_EMBEDDED_SERVER = 1 \ - DWITH_DEBUG = 0 <br><br> ##-DMYSQL_UNIX_ADDR=/application/mysql-5.5.32/tmp/mysql.sock \## |
有的时候此时会比较怪异,可能需要将解压完后的包删除重新解压,然后执行上面的编译。
1 | make && make install |
4、配置
1)设置目录权限
1 | cd / usr / local / mysql<br><br>chown - R root:mysql . / / 把当前目录中所有文件的所有者设为root,所属组为mysqlchown - R mysql:mysql data |
3)将mysql的启动服务添加到系统服务中
1 | cp support - files / mysql.server / etc / init.d / mysql |
2)创建系统数据库的表
注:在启动MySQL服务时,会按照一定次序搜索my.cnf,先在/etc目录下找,找不到则会搜索"$basedir/my.cnf",在本例中就是 /usr/local/mysql/my.cnf,这是新版MySQL的配置文件的默认位置!
注意:在CentOS 6.4版操作系统的最小安装完成后,在/etc目录下会存在一个my.cnf,需要将此文件更名为其他的名字,如:/etc/my.cnf.bak,否则,该文件会干扰源码安装的MySQL的正确配置,造成无法启动。
在使用"yum update"更新系统后,需要检查下/etc目录下是否会多出一个my.cnf,如果多出,将它重命名成别的。否则,MySQL将使用这个配置文件启动,可能造成无法正常启动等问题。这个可以参考最下面。
1 | #scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data<br>scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql |
4)启动服务
1 2 | chkconfig mysql on service mysql start - - 启动MySQL |
5)设置环境变量
1 2 3 | vi / root / .bash_profile<br> 在PATH = $PATH:$HOME / bin 添加参数为: PATH = / usr / local / mysql / bin : / usr / local / mysql / lib:$PATH:$HOME / bin <br><br>不关机立即生效<br>source / root / .bash_profile |
==========================================================================================================================================
mysql5.1.72编译
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | . / configure \ - - prefix = / application / mysql5. 1.72 \ - - with - unix - socket - path = / application / mysql5. 1.72 / tmp / mysql.sock \ - - localstatedir = / application / mysql5. 1.72 / data \ - - enable - assembler \ - - enable - thread - safe - client \ - - with - mysqld - user = mysql \ - - with - big - tables \ - - without - debug \ - - with - pthread \ - - enable - assembler \ - - with - extra - charsets = complex \ - - with - readline \ - - with - ssl \ - - with - embedded - server \ - - enable - local - infile \ - - with - plugins = partition,innobase \ - - with - mysqld - ldflags = - all - static \ - - with - client - ldflags = - all - static #--with-plugin-PLUGIN \ |
出现的问题:
1 2 | checking for termcap functions library... configure: error: No curses / termcap library found yum - y install ncurses - devel |
下面的这种情况可以查看上面的4.2
cp support-files/my-medium.cnf /etc/my.cnf
将mysql的配置文件copy到/etc目录下,并更名为my.cnf
my-small.cnf 最小配置安装,内存<=64M,数据数量最少
my-large.cnf 内存=512M
my-medium.cnf 32M<内存<64M,或者内存有128M,但是数据库与web服务器公用内存
my-huge.cnf 1G<内存<2G,服务器主要运行mysql
my-innodb-heavy-4G.cnf 最大配置安装,内存至少4G
参考,my.cnf
http://www.ha97.com/3455.html
http://www.cnblogs.com/fly1988happy/archive/2011/11/21/2257682.html
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步