Linux环境下源码编译安装MySQL5.1

1、源码安装MySQL 5.1 GA

创建组和用户:

  • [root@mysqldb2 ~]# groupadd mysql

    [root@mysqldb2 ~]# useradd -g mysql mysql

解压缩安装包:

  • [root@mysqldb2 ~]$ cd /data/software/

    [root@mysqldb2 software]$ tar xvfz mysql-5.1.51.tar.gz 

    [root@mysqldb2 software]$ cd mysql-5.1.51

进入mysql安装包目录,执行configure并加载适当参数:

  •  [root@mysqldb2 mysql-5.1.51]# ./configure --prefix=/usr/local/mysql/ --with-server-suffix=-junsansi-edition --enable-assembler --enable-local-infile --enable-thread-safe-client --with-big-tables --with-charset=utf8  --with-extra-charsets=gbk,gb2312,utf8,ascii  --with-readline --with-ssl --with-embedded-server --with-pthread --with-mysqld-user=mysql --with-mysqld-ldflags=-all-static --with-client-ldflags=-all-static --with-plugins=partition,innobase,innodb_plugin > /home/jss/mysql_setuplogs_configure.log 2>&1

提示:configure支持的选项非常多,详细的参数及说明建议参考官方文档,也可以通过./configure --help查看,这里仅列出常用及推荐使用的选项。

  • --prefix=PREFIX:指定程序安装路径;
  • --enable-assembler:使用汇编模式;
  • --enable-local-infile:启用对LOAD DATA LOCAL INFILE语法的支持(默认不支持);
  • --enable-profiling:Build a version with query profiling code (req.community-features)
  • --enable-thread-safe-client:使用编译客户端;
  • --with-big-tables:启用32位平台对4G大表的支持;
  • --with-charset=CHARSET:指定字符集;
  • --with-collation=:默认collation;
  • --with-extra-charsets=CHARSET,CHARSET,...:指定附加的字符集;
  • --with-fast-mutexes:Compile with fast mutexes
  • --with-readline:
  • --with-ssl:启用SSL的支持;
  • --with-server-suffix=:添加字符串到版本信息;
  • --with-embedded-server:编译embedded-server;
  • --with-pthread:强制使用pthread类库;
  • --with-mysqld-user=:指定mysqld守护进程的用户;
  • --with-mysqld-ldflags=:静态编译MySQL服务器端;
  • --with-client-ldflags=:静态编译MySQL客户端;
  • --with-plugins=PLUGIN,PLUGIN,...:MySQL服务器端支持的组件(默认为空),可选值较多:
    • partition:MySQL Partitioning Support;
    • daemon_example:This is an example plugin daemon;
    • ftexample:Simple full-text parser plugin;
    • archive:Archive Storage Engine;
    • blackhole:Basic Write-only Read-never tables;
    • csv:Stores tables in text CSV format,强制安装;
    • example:Example for Storage Engines for developers;
    • federated:Connects to tables on remote MySQL servers;
    • heap:Volatile memory based tables,强制安装;
    • ibmdb2i:IBM DB2 for i Storage Engine;
    • innobase:Transactional Tables using InnoDB;
    • innodb_plugin:Transactional Tables using InnoDB;
    • myisam:Traditional non-transactional MySQL tables,强制安装;
    • myisammrg:Merge multiple MySQL tables into one,强制安装;
    • ndbcluster:High Availability Clustered tables;
  • --with-plugin-PLUGIN:强制指定的插件链接至MySQL服务器;
  • --with-zlib-dir=:向MySQL提供一个自定义的压缩类库地址;
  • --without-server:仅安装MySQL客户端;
  • --without-query-cache:不要编译查询缓存;
  • --without-geometry:不要编译geometry-related部分;
  • --without-debug:编译为产品版,放弃debugging代码;
  • --without-ndb-debug:禁用special ndb debug特性;
  • 提示:执行Configure时如果报bin/rm: cannot remove `libtoolt¨: No such file or directory错误,可按照下列步骤解决:

    1、确认libtool是否已经安装,如果没有安装的话,则先安装libtool

    # rpm -qa | grep libtool

    # yum -y install libtool

    2、分别执行以下三条命令:

    # autoreconf --force --install

    # libtoolize --automake --force

    # automake --force --add-missing

    再重新编译安装,问题解决!

继续执行编译:

  • [root@mysqldb2 mysql-5.1.51]# make > /home/jss/mysql_setuplogs_make.log 2>&1

     [root@mysqldb2 mysql-5.1.51]# make install > /home/jss/mysql_setuplogs_makeinstall.log 2>&1

修改相关路径权限:

  • [root@mysqldb2 mysql-5.1.51]# cd /usr/local/

     [root@mysqldb2 local]# chown -R mysql:mysql mysql

复制程序文件到/usr/bin目录下,方便调用:

  •  [root@mysqldb2 local]# cp /usr/local/mysql/bin/mysql* /usr/bin/

至此,MySQL数据库软件安装完成,此时已可使用mysql命令行工具连接其它MySQL数据库服务器了。

2. 创建数据库

创建目录并修改权限:

  • [root@mysqldb2 local]# cd /data

    [root@mysqldb2 data]# mkdir mysqldata

    [root@mysqldb2 data]# cd mysqldata

    [root@mysqldb2 mysqldata]# mkdir 3306

    [root@mysqldb2 mysqldata]# cd 3306

    [root@mysqldb2 3306]# mkdir data binlog tmp innodb_ts innodb_log

    [root@mysqldb2 3306]# cd /data

    [root@mysqldb2 data]# chown -R mysql:mysql mysqldata

创建数据库:

  • [root@mysqldb2 local]# cd mysql/

    [root@mysqldb2 mysql]# bin/mysql_install_db --user=mysql --datadir=/data/mysqldata/3306/data

    Installing MySQL system tables...

    OK

    Filling help tables...

    OK

    To start mysqld at boot time you have to copy

    support-files/mysql.server to the right place for your system

    PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !

    To do so, start the server, then issue the following commands:

    /usr/local/mysql/bin/mysqladmin -u root password ¨new-password¨

    /usr/local/mysql/bin/mysqladmin -u root -h mysqldb2 password ¨new-password¨

    Alternatively you can run:

    /usr/local/mysql/bin/mysql_secure_installation

    which will also give you the option of removing the test

    databases and anonymous user created by default.  This is

    strongly recommended for production servers.

    See the manual for more instructions.

    You can start the MySQL daemon with:

    cd /usr/local/mysql ; /usr/local/mysql/bin/mysqld_safe &

    You can test the MySQL daemon with mysql-test-run.pl

    cd /usr/local/mysql/mysql-test ; perl mysql-test-run.pl

    Please report any problems with the /usr/local/mysql/bin/mysqlbug script!

编辑和修改my.cnf配置文件,下列内容仅供参考:

  • [root@mysqldb2 mysql]# vi /data/mysqldata/3306/my.cnf

    [client]
    port = 3306
    socket = /data/mysqldata/3306/mysql.sock
    character-set-server = utf8

    # Here follows entries for some specific programs

    # The MySQL server
    [mysqld]
    port = 3306
    user = mysql
    socket = /data/mysqldata/3306/mysql.sock
    pid-file = /data/mysqldata/3306/mysql.pid
    basedir = /usr/local/mysql
    datadir = /data/mysqldata/3306/data
    tmpdir = /data/mysqldata/3306/tmp
    open_files_limit = 10240
    server-id = 303306
    lower_case_table_names = 1
    character-set-server = utf8
    skip-name-resolve

    max_connections = 1000
    max_connect_errors = 100000
    max_allowed_packet = 512M
    max_heap_table_size = 1024M
    max_length_for_sort_data = 4096
    back_log=100
    interactive_timeout = 600
    wait_timeout = 600

    default-storage-engine = InnoDB

    net_buffer_length = 8K
    sort_buffer_size = 2M
    join_buffer_size = 4M
    read_buffer_size = 2M
    read_rnd_buffer_size = 16M

    query_cache_size = 128M
    query_cache_limit = 2M
    query_cache_min_res_unit = 2k

    thread_cache_size = 300
    table_open_cache = 1024
    tmp_table_size = 256M

    #*********** Logs related settings ***********
    log-bin = /data/mysqldata/3306/binlog/mysql-bin
    binlog_format=row
    binlog_cache_size=32m
    max_binlog_cache_size=512m
    max_binlog_size=512m
    long_query_time = 3
    log_output = FILE
    log-error = /data/mysqldata/3306/mysql-error.log
    slow_query_log = 1
    slow_query_log_file = /data/mysqldata/3306/slow_statement.log
    log_queries_not_using_indexes 
    general_log = 0
    general_log_file = /data/mysqldata/3306/general_statement.log
    expire-logs-days = 14

    #*********** MyISAM Specific options ***********
    key_buffer_size = 32M
    bulk_insert_buffer_size = 64M
    myisam_sort_buffer_size = 128M
    myisam_max_sort_file_size = 10G
    myisam_repair_threads = 1
    myisam_recover

    #*********** INNODB Specific options ***********
    innodb_file_per_table
    transaction-isolation = READ-COMMITTED

    innodb_additional_mem_pool_size = 16M
    innodb_buffer_pool_size = 1024M
    innodb_data_home_dir = /data/mysqldata/3306/innodb_ts
    innodb_data_file_path = ibdata1:2048M:autoextend

    innodb_file_io_threads = 4
    innodb_thread_concurrency = 0
    innodb_log_buffer_size = 16M
    innodb_log_file_size = 256M
    innodb_log_files_in_group = 2

    innodb_log_group_home_dir = /data/mysqldata/3306/innodb_log
    innodb_flush_log_at_trx_commit = 2
    innodb_max_dirty_pages_pct = 80
    innodb_lock_wait_timeout = 120
    innodb_flush_method=O_DIRECT

    [mysqldump]
    quick
    max_allowed_packet = 512M

    [mysql]
    no-auto-rehash
    # Remove the next comment character if you are not familiar with SQL
    #safe-updates

    [myisamchk]
    key_buffer_size = 32M
    sort_buffer_size = 20M
    read_buffer_size = 2M
    write_buffer_size = 2M

    [mysqlhotcopy]
    interactive-timeout

    [mysqld_safe]
    open-files-limit = 8192

启动数据库:

  • [root@mysqldb2 mysql]# mysqld_safe --defaults-file=/data/mysqldata/3306/my.cnf &

设置超级用户密码:

  • [root@mysqldb2 mysql]# mysqladmin -uroot password ¨verysafe¨ -S /data/mysqldata/3306/mysql.sock 

可以通过netstat或ps等命令查看mysqld是否正常加载,由于默认指定mysqld端口号为3306,因此通过netstat查看是否存在3306端口即可,例如:

  • [root@mysqldb2 mysql]# netstat -lnt

    Active Internet connections (only servers)

    Proto Recv-Q Send-Q Local Address               Foreign Address             State      

    tcp        0      0 127.0.0.1:2208              0.0.0.0:*                   LISTEN      

    tcp        0      0 0.0.0.0:864                 0.0.0.0:*                   LISTEN      

    tcp        0      0 0.0.0.0:11111               0.0.0.0:*                   LISTEN      

    tcp        0      0 0.0.0.0:3306                0.0.0.0:*                   LISTEN      

    tcp        0      0 0.0.0.0:111                 0.0.0.0:*                   LISTEN      

    tcp        0      0 0.0.0.0:16851               0.0.0.0:*                   LISTEN      

            0      0 0.0.0.0:21                  0.0.0.0:*                   LISTEN      

3. 创建第2个数据库

源码安装最大的优点就是灵活(缺点当然也很明显:复杂),不过能够创建一个数据库出来,再创建第二个自然也不在话下,事实上创建第2个数据库与第1个从步骤上看,基本也没什么区别,只要注意修改相关路径,和mysql运行的端口号即可。

创建目录并修改权限:

  • [root@mysqldb2 mysql]# mkdir /data/mysqldata/3307

    [root@mysqldb2 mysql]# cd /data/mysqldata/3307/

    [root@mysqldb2 3307]# mkdir data binlog tmp innodb_ts innodb_log

    [root@mysqldb2 3307]# cd /data/mysqldata

    [root@mysqldb2 mysqldata]# chown mysql:mysql 3307 -R

复制初始化参数文件:

  • [root@mysqldb2 3307]# cp ../3306/my.cnf ./

修改初始化参数值,主要为路径和端口:

  • [root@mysqldb2 3307]# vi my.cnf 

命令符下输入:

  •  s/3306/3307/g

替换文件中所有3306为3307

编辑server-id的值,指定一个与3306数据库不同的值,比如说303307:

  • server-id = 303307

创建数据库:

  • [root@mysqldb2 3307]# mysql_install_db --user=mysql --datadir=/data/mysqldata/3307/data

    Installing MySQL system tables...

    OK

    Filling help tables...

    OK

    ..........

    ..........

启动数据库:

  • [root@mysqldb2 3307]# mysqld_safe --defaults-file=/data/mysqldata/3307/my.cnf &

设置超级用户密码:

  • [root@mysqldb2 3307]# mysqladmin -uroot password ¨verysafe¨ -S /data/mysqldata/3307/mysql.sock 

随后,就可以通过mysql登录了:

  • [root@mysqldb2 3307]# mysql -uroot -p¨verysafe¨ -S /data/mysqldata/3307/mysql.sock 

    Welcome to the MySQL monitor.  Commands end with ; or \g.

    Your MySQL connection id is 2

    Server version: 5.1.51-log Source distribution

    Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.

    This software comes with ABSOLUTELY NO WARRANTY. This is free software,

    and you are welcome to modify and redistribute it under the GPL v2 license

    Type ¨help;¨ or ¨\h¨ for help. Type ¨\c¨ to clear the current input statement.

    mysql> 

通过这种方式,还可以非常轻松的创建第三、四....或更多数据库。当然了,如果是要同时创建多个新库的话,也许接下来用cp的方式会更快捷一些,不过这就跟mysql_install_db没什么关系了~~~


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值