Linux下如何安装配置源代码版本的MySQL

62次阅读
没有评论

共计 7343 个字符,预计需要花费 19 分钟才能阅读完成。

这篇文章主要为大家展示了“Linux 下如何安装配置源代码版本的 MySQL”,内容简而易懂,条理清晰,希望能够帮助大家解决疑惑,下面让丸趣 TV 小编带领大家一起研究并学习一下“Linux 下如何安装配置源代码版本的 MySQL”这篇文章吧。

操作系统版本:Red Hat Enterprise Linux Server release 5 (Tikanga)
MySQL 版本:
安装文件:MySQL-community-5.1.45-1.rhel5.src.rpm

 1. 释放源代码包

    使用的安装文件是一个 source RPM,首先要将其内容释放:

方法一:

[root@redhat5-db-1 software]# rpm -i MySQL-community-5.1.45-1.rhel5.src.rpm
error: cannot create %sourcedir /usr/src/redhat/SOURCES
[root@redhat5-db-1 software]# mkdir -p /usr/src/redhat/SOURCES
[root@redhat5-db-1 software]# rpm -i MySQL-community-5.1.45-1.rhel5.src.rpm
warning: user mysqldev does not exist – using root
warning: group mysqldev does not exist – using root
warning: user mysqldev does not exist – using root
warning: group mysqldev does not exist – using root
[root@redhat5-db-1 software]# ls /usr/src/redhat/*
/usr/src/redhat/SOURCES:
mysql-5.1.45.tar.gz

/usr/src/redhat/SPECS:
mysql-5.1.45.rhel5.spec

[@more@] 方法二:

[root@redhat5-db-1 software]# rpm2cpio MySQL-community-5.1.45-1.rhel5.src.rpm | cpio -idmv
mysql-5.1.45.rhel5.spec
mysql-5.1.45.tar.gz
43995 blocks
[root@redhat5-db-1 software]# ls
mysql-5.1.45.rhel5.spec  mysql-5.1.45.tar.gz  MySQL-community-5.1.45-1.rhel5.src.rpm

注:无论使用哪种方法,都会在释放源代码包的同时,释放另一个文件 mysql-5.1.45.rhel5.spec。它是一个 RPM SPEC 文件,可以通过 rpmbuild 命令创建 MySQL 的源代码文件或二进制程序(-bp 选项在 /usr/src/redhat/BUILD 目录下创建源代码文件,-bb 选项在 /usr/src/redhat/RPM 目录下创建二进制程序),这里不再赘述。

 2. 安装前的准备工作

 1) 创建用户和组

[root@redhat5-db-1 software]# groupadd mysql
[root@redhat5-db-1 software]# useradd -g mysql mysql
[root@redhat5-db-1 software]# id mysql
uid=502(mysql) gid=504(mysql) groups=504(mysql)

 2) 准备必要的目录

[root@redhat5-db-1 software]# mkdir -p /opt/mysql /data/mysql
[root@redhat5-db-1 software]# chown mysql:mysql /opt/mysql /data/mysql

 3) 安装必要的 RPM

    需要安装 ncurses-devel,否则编译时会报如下错误:

checking for termcap functions library… configure: error: No curses/termcap library found

    在 Red Hat EL 5 安装光盘中找到该 RPM,进行安装:

[root@redhat5-db-1 software]# mount -o ro /dev/cdrom /mnt/cdrom
[root@redhat5-db-1 software]# rpm -ivh /mnt/cdrom/Server/ncurses-devel-5.5-24.20060715.i386.rpm
warning: /mnt/cdrom/Server/ncurses-devel-5.5-24.20060715.i386.rpm: Header V3 DSA signature: NOKEY, key ID 37017186
Preparing…                ########################################### [100%]
  1:ncurses-devel          ########################################### [100%]

 4) 解压源代码包

[root@redhat5-db-1 software]# tar -zxf mysql-5.1.45.tar.gz
[root@redhat5-db-1 software]# ls -p
mysql-5.1.45/  mysql-5.1.45.rhel5.spec  mysql-5.1.45.tar.gz  MySQL-community-5.1.45-1.rhel5.src.rpm

 3. 安装 MySQL

 1)CONFIGURE

[root@redhat5-db-1 software]# su – mysql
[mysql@redhat5-db-1 ~]$ cd /opt/software/mysql-5.1.45
[mysql@redhat5-db-1 mysql-5.1.45]$ ./configure –prefix=/opt/mysql –localstatedir=/data/mysql –with-plugins=innobase
checking build system type… i686-pc-linux-gnu
checking host system type… i686-pc-linux-gnu
checking target system type… i686-pc-linux-gnu
checking for a BSD-compatible install… /usr/bin/install -c

……

config.status: executing depfiles commands
config.status: executing libtool commands
/bin/rm: cannot remove `libtoolT : No such file or directory
config.status: executing default commands

Thank you for choosing MySQL!

Remember to check the platform specific part of the reference manual
for hints about installing MySQL on your platform.
Also have a look at the files in the Docs directory.

注:–prefix 选项指定 MySQL 程序的路径;–localstatedir 选项指定 MySQL 数据文件的路径;–with-plugins=innobase 指定 MySQL 服务器包含 InnoDB 功能。

 2)MAKE

[mysql@redhat5-db-1 mysql-5.1.45]$ make
Making all in .
make[1]: Entering directory `/opt/software/mysql-5.1.45
make abi_headers= include/mysql/plugin.h include/mysql.h do_abi_check
make[2]: Entering directory `/opt/software/mysql-5.1.45

……

Making all in win
make[1]: Entering directory `/opt/software/mysql-5.1.45/win
make[1]: Nothing to be done for `all .
make[1]: Leaving directory `/opt/software/mysql-5.1.45/win

 3)MAKE-INSTALL

[mysql@redhat5-db-1 mysql-5.1.45]$ make install
Making install in .
make[1]: Entering directory `/opt/software/mysql-5.1.45
make abi_headers= include/mysql/plugin.h include/mysql.h do_abi_check
make[2]: Entering directory `/opt/software/mysql-5.1.45

……

Making install in win
make[1]: Entering directory `/opt/software/mysql-5.1.45/win
make[2]: Entering directory `/opt/software/mysql-5.1.45/win
make[2]: Nothing to be done for `install-exec-am .
make[2]: Nothing to be done for `install-data-am .
make[2]: Leaving directory `/opt/software/mysql-5.1.45/win
make[1]: Leaving directory `/opt/software/mysql-5.1.45/win
[mysql@redhat5-db-1 mysql-5.1.45]$ ls /opt/mysql
bin  docs  include  lib  libexec  mysql-test  share  sql-bench

 4. 安装后的工作

 1) 创建选项文件

[root@redhat5-db-1 ~]# cp /opt/software/mysql-5.1.45/support-files/my-medium.cnf /etc/my.cnf
[root@redhat5-db-1 ~]# chown mysql:mysql /etc/my.cnf

    可以通过修改其内容对 MySQL 服务器进行配置。这里只简单取消 InnoDB 相关参数所在行的注释:

# Uncomment the following if you are using InnoDB tables
innodb_data_home_dir = /data/mysql/
innodb_data_file_path = ibdata1:10M:autoextend
innodb_log_group_home_dir = /data/mysql/
# You can set .._buffer_pool_size up to 50 – 80 %
# of RAM but beware of setting memory usage too high
innodb_buffer_pool_size = 16M
innodb_additional_mem_pool_size = 2M
# Set .._log_file_size to 25 % of buffer pool size
innodb_log_file_size = 5M
innodb_log_buffer_size = 8M
innodb_flush_log_at_trx_commit = 1
innodb_lock_wait_timeout = 50

 2) 设置环境变量

    在 mysql 的 HOME 目录下的.bash_profile 文件中添加如下内容:

# Added by ggyy on March 31st, 2010
PATH=$PATH:/opt/mysql/bin
export PATH

 3) 初始化 MySQL

[mysql@redhat5-db-1 ~]$ /opt/mysql/bin/mysql_install_db
Installing MySQL system tables…
100331 18:21:59 [Warning] –skip-locking is deprecated and will be removed in a future release. Please use –skip-external-locking instead.
OK
Filling help tables…
100331 18:22:00 [Warning] –skip-locking is deprecated and will be removed in a future release. Please use –skip-external-locking instead.
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:

/opt/mysql/bin/mysqladmin -u root password new-password
/opt/mysql/bin/mysqladmin -u root -h redhat5-db-1 password new-password

Alternatively you can run:
/opt/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 /opt/mysql ; /opt/mysql/bin/mysqld_safe

You can test the MySQL daemon with mysql-test-run.pl
cd /opt/mysql/mysql-test ; perl mysql-test-run.pl

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

[mysql@redhat5-db-1 ~]$ ls /data/mysql
mysql  mysql-bin.000001  mysql-bin.000002  mysql-bin.index  test

 3) 启动和关闭 MySQL

    启动 MySQL 服务器,测试登陆:

[mysql@redhat5-db-1 ~]$ /opt/mysql/bin/mysqld_safe
[1] 3028
[mysql@redhat5-db-1 ~]$ 100331 18:27:18 mysqld_safe Logging to /data/mysql/redhat5-db-1.err .
100331 18:27:18 mysqld_safe Starting mysqld daemon with databases from /data/mysql

mysql select version();
+————+
| version()  |
+————+
| 5.1.45-log |
+————+
1 row in set (0.00 sec)

mysql show variables like have_innodb
+—————+——-+
| Variable_name | Value |
+—————+——-+
| have_innodb   | YES   |
+—————+——-+
1 row in set (0.00 sec)

    可以使用 mysql.server 脚本启动和关闭 MySQL 服务器,它位于解压的源代码目录下的 support-files 子目录中。该目录下还有许多其它有用的文件、脚本,可以考虑将其复制到 MySQL 程序目录下,并在.bash_profile 文件里的 PATH 中添加相应路径。

[mysql@redhat5-db-1 ~]$ cp -pr /opt/software/mysql-5.1.45/support-files /opt/mysql
[mysql@redhat5-db-1 ~]$ chmod u+x /opt/mysql/support-files/mysql.server
[mysql@redhat5-db-1 ~]$ which mysql.server
/opt/mysql/support-files/mysql.server
[mysql@redhat5-db-1 ~]$ mysql.server stop
Shutting down MySQL.100331 18:58:49 mysqld_safe mysqld from pid file /data/mysql/redhat5-db-1.pid ended
                                                          [ OK  ]

以上是“Linux 下如何安装配置源代码版本的 MySQL”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注丸趣 TV 行业资讯频道!

正文完
 
丸趣
版权声明:本站原创文章,由 丸趣 2023-07-27发表,共计7343字。
转载说明:除特殊说明外本站除技术相关以外文章皆由网络搜集发布,转载请注明出处。
评论(没有评论)