• 登录
  • Subscribe RSS Feed
 

使用源码包安装MySQL

06月 14, 2010

         在linux下安装MySQL:(1)可以使用现成的rpm包来直接安装,这种方式快速简单。(2)还可以使用源码包来自己编译安装,这种方式可以自己对MySQL的安装进行定制,如:对于MySQL软件的安装目录自己制定等。下面我将记录使用第二种方式安装的步骤:

首先:下载MySQL源码包(http://dev.mysql.com/downloads/mysql/)。可以在linux服务器上直接wget,下载后,核对md5sum计算结果是否和官方网站给出的信息一样。

[zhuxu@xentest8-vm1 ~]$ wget http://ftp.jaist.ac.jp/pub/mysql/Downloads/MySQL-5.1/mysql-5.1.47.tar.gz
--2010-06-14 23:41:17--  http://ftp.jaist.ac.jp/pub/mysql/Downloads/MySQL-5.1/mysql-5.1.47.tar.gz
Resolving ftp.jaist.ac.jp... 150.65.7.130
Connecting to
ftp.jaist.ac.jp|150.65.7.130|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 23817441 (23M) [application/x-gzip]
Saving to: `mysql-5.1.47.tar.gz'

100%[=================================>] 23,817,441  4.99M/s   in 6.9s   

2010-06-14 23:41:24 (3.30 MB/s) - `mysql-5.1.47.tar.gz' saved [23817441/23817441]

[zhuxu@xentest8-vm1 ~]$
[zhuxu@xentest8-vm1 ~]$ md5sum mysql-5.1.47.tar.gz
02b9964b3966832f3d6bc87524bfd73f  mysql-5.1.47.tar.gz

其次:准备安装,详细过程可以参考MySQL的官方在线文档MySQL Installation Using a Source Distribution

(一)创建MySQL组和用户

[zhuxu@xentest8-vm1 ~]$ sudo su - root
Password:
[root@xentest8-vm1 ~]# id mysql
id: mysql: No such user
[root@xentest8-vm1 ~]# groupadd mysql
[root@xentest8-vm1 ~]# useradd -g mysql mysql
[root@xentest8-vm1 ~]# id mysql
uid=51233(mysql) gid=10003(mysql) groups=10003(mysql)

(二)编译安装MySQL(安装在/home/mysql/mysql-5.1.47目录中)

[root@xentest8-vm1 zhuxu]# cd /home/zhuxu/
[root@xentest8-vm1 zhuxu]# ls
mysql-5.1.47.tar.gz
[root@xentest8-vm1 zhuxu]# tar -zxf mysql-5.1.47.tar.gz
[root@xentest8-vm1 zhuxu]# ls
mysql-5.1.47  mysql-5.1.47.tar.gz
[root@xentest8-vm1 zhuxu]# cd mysql-5.1.47
[root@xentest8-vm1 mysql-5.1.47]# ./configure --prefix=/home/mysql/mysql-5.1.47
[root@xentest8-vm1 mysql-5.1.47]# make
[root@xentest8-vm1 mysql-5.1.47]# make install

(三)修改权限和创建配置文件

[root@xentest8-vm1 mysql-5.1.47]# cp support-files/my-medium.cnf /etc/my.cnf
[root@xentest8-vm1 mysql-5.1.47]# chown mysql:mysql /etc/my.cnf
[root@xentest8-vm1 mysql-5.1.47]# chown -R mysql:mysql /home/mysql/mysql-5.1.47/

(四)初始化MySQL(用户表和权限表等)和启动MySQL

#到MySQL软件目录下,创建MySQL数据文件目录data
[root@xentest8-vm1 mysql-5.1.47]# cd /home/mysql/mysql-5.1.47/
[root@xentest8-vm1 mysql-5.1.47]# mkdir data
[root@xentest8-vm1 mysql-5.1.47]# chown -R mysql:mysql data
#回到源码包安装目录下,运行脚本mysql_install_db初始化
[root@xentest8-vm1 scripts]# cd /home/zhuxu/mysql-5.1.47/scripts
[root@xentest8-vm1 scripts]# ./mysql_install_db --user=mysql \
> --datadir=/home/mysql/mysql-5.1.47/data/
Installing MySQL system tables...
100615  1:05:43 [Warning] '--skip-locking' is deprecated and will be removed in a future release. Please use '--skip-external-locking' instead.
OK
Filling help tables...
100615  1:05:43 [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:

/home/mysql/mysql-5.1.47/bin/mysqladmin -u root password 'new-password'
/home/mysql/mysql-5.1.47/bin/mysqladmin -u root -h xentest8-vm1.corp.xxxx.com password 'new-password'

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

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

Please report any problems with the /home/mysql/mysql-5.1.47/bin/mysqlbug script!
[root@xentest8-vm1 scripts]#
#到MySQL安装目录启动服务
[root@xentest8-vm1 scripts]# /home/mysql/mysql-5.1.47/bin/mysqld_safe --user=mysql &
[1] 20597
[root@xentest8-vm1 scripts]# 100615 01:08:25 mysqld_safe Logging to '/home/mysql/mysql-5.1.47/data/xentest8-vm1.corp.xxxx.com.err'.
100615 01:08:25 mysqld_safe Starting mysqld daemon with databases from /home/mysql/mysql-5.1.47/data

[root@xentest8-vm1 scripts]#
[root@xentest8-vm1 scripts]# ps -ef | grep mysqld
root     20597  7764  0 01:08 pts/5    00:00:00 /bin/sh /home/mysql/mysql-5.1.47/bin/mysqld_safe --user=mysql
mysql    20696 20597  0 01:08 pts/5    00:00:00 /home/mysql/mysql-5.1.47/libexec/mysqld --basedir=/home/mysql/mysql-5.1.47 --datadir=/home/mysql/mysql-5.1.47/data --user=mysql --log-error=/home/mysql/mysql-5.1.47/data/xentest8-vm1.corp.xxxx.com.err --pid-file=/home/mysql/mysql-5.1.47/data/xentest8-vm1.corp.xxxx.com.pid --socket=/tmp/mysql.sock --port=3306
root     20705  7764  0 01:08 pts/5    00:00:00 grep mysqld
[root@xentest8-vm1 scripts]#

(五)问题
在后面使用的时候发现不加选项的编译安装没有INNODB存储引擎以及GBK字符集

mysql> show engines;
+------------+---------+-----------------------------------------------------------+--------------+------+------------+
| Engine     | Support | Comment                                                   | Transactions | XA   | Savepoints |
+------------+---------+-----------------------------------------------------------+--------------+------+------------+
| CSV        | YES     | CSV storage engine                                        | NO           | NO   | NO         |
| MRG_MYISAM | YES     | Collection of identical MyISAM tables                     | NO           | NO   | NO         |
| MEMORY     | YES     | Hash based, stored in memory, useful for temporary tables | NO           | NO   | NO         |
| MyISAM     | DEFAULT | Default engine as of MySQL 3.23 with great performance    | NO           | NO   | NO         |
+------------+---------+-----------------------------------------------------------+--------------+------+------------+
4 rows in set (0.00 sec)

mysql> show character set;
+----------+-----------------------------+---------------------+--------+
| Charset  | Description                 | Default collation   | Maxlen |
+----------+-----------------------------+---------------------+--------+
| dec8     | DEC West European           | dec8_swedish_ci     |      1 |
| cp850    | DOS West European           | cp850_general_ci    |      1 |
| hp8      | HP West European            | hp8_english_ci      |      1 |
| koi8r    | KOI8-R Relcom Russian       | koi8r_general_ci    |      1 |
| latin1   | cp1252 West European        | latin1_swedish_ci   |      1 |
| latin2   | ISO 8859-2 Central European | latin2_general_ci   |      1 |
| swe7     | 7bit Swedish                | swe7_swedish_ci     |      1 |
| ascii    | US ASCII                    | ascii_general_ci    |      1 |
| hebrew   | ISO 8859-8 Hebrew           | hebrew_general_ci   |      1 |
| koi8u    | KOI8-U Ukrainian            | koi8u_general_ci    |      1 |
| greek    | ISO 8859-7 Greek            | greek_general_ci    |      1 |
| cp1250   | Windows Central European    | cp1250_general_ci   |      1 |
| latin5   | ISO 8859-9 Turkish          | latin5_turkish_ci   |      1 |
| armscii8 | ARMSCII-8 Armenian          | armscii8_general_ci |      1 |
| utf8     | UTF-8 Unicode               | utf8_general_ci     |      3 |
| cp866    | DOS Russian                 | cp866_general_ci    |      1 |
| keybcs2  | DOS Kamenicky Czech-Slovak  | keybcs2_general_ci  |      1 |
| macce    | Mac Central European        | macce_general_ci    |      1 |
| macroman | Mac West European           | macroman_general_ci |      1 |
| cp852    | DOS Central European        | cp852_general_ci    |      1 |
| latin7   | ISO 8859-13 Baltic          | latin7_general_ci   |      1 |
| cp1251   | Windows Cyrillic            | cp1251_general_ci   |      1 |
| cp1256   | Windows Arabic              | cp1256_general_ci   |      1 |
| cp1257   | Windows Baltic              | cp1257_general_ci   |      1 |
| binary   | Binary pseudo charset       | binary              |      1 |
| geostd8  | GEOSTD8 Georgian            | geostd8_general_ci  |      1 |
+----------+-----------------------------+---------------------+--------+
26 rows in set (0.00 sec)

这个时候只能把原先的目录mv掉,然后重新配置编译(按照苏普编译安装MySQL),选项如下:

[mysql@xentest8-vm1 mysql_install]$ ./configure --prefix=/home/mysql/mysql-5.1.47 \
> --with-extra-charsets=latin1,gbk,utf8 \
> --with-plugins=partition,heap,innobase,myisam,myisammrg,csv

#完成后查看
mysql> show engines;
+------------+---------+------------------------------------------------------------+--------------+------+------------+
| Engine     | Support | Comment                                                    | Transactions | XA   | Savepoints |
+------------+---------+------------------------------------------------------------+--------------+------+------------+
| MRG_MYISAM | YES     | Collection of identical MyISAM tables                      | NO           | NO   | NO         |
| CSV        | YES     | CSV storage engine                                         | NO           | NO   | NO         |
| MyISAM     | DEFAULT | Default engine as of MySQL 3.23 with great performance     | NO           | NO   | NO         |
| InnoDB     | YES     | Supports transactions, row-level locking, and foreign keys | YES          | YES  | YES        |
| MEMORY     | YES     | Hash based, stored in memory, useful for temporary tables  | NO           | NO   | NO         |
+------------+---------+------------------------------------------------------------+--------------+------+------------+
5 rows in set (0.00 sec)

mysql> show character set;
+----------+-----------------------------+---------------------+--------+
| Charset  | Description                 | Default collation   | Maxlen |
+----------+-----------------------------+---------------------+--------+
| dec8     | DEC West European           | dec8_swedish_ci     |      1 |
| cp850    | DOS West European           | cp850_general_ci    |      1 |
| hp8      | HP West European            | hp8_english_ci      |      1 |
| koi8r    | KOI8-R Relcom Russian       | koi8r_general_ci    |      1 |
| latin1   | cp1252 West European        | latin1_swedish_ci   |      1 |
| latin2   | ISO 8859-2 Central European | latin2_general_ci   |      1 |
| swe7     | 7bit Swedish                | swe7_swedish_ci     |      1 |
| ascii    | US ASCII                    | ascii_general_ci    |      1 |
| hebrew   | ISO 8859-8 Hebrew           | hebrew_general_ci   |      1 |
| koi8u    | KOI8-U Ukrainian            | koi8u_general_ci    |      1 |
| greek    | ISO 8859-7 Greek            | greek_general_ci    |      1 |
| cp1250   | Windows Central European    | cp1250_general_ci   |      1 |
| gbk      | GBK Simplified Chinese      | gbk_chinese_ci      |      2 |
| latin5   | ISO 8859-9 Turkish          | latin5_turkish_ci   |      1 |
| armscii8 | ARMSCII-8 Armenian          | armscii8_general_ci |      1 |
| utf8     | UTF-8 Unicode               | utf8_general_ci     |      3 |
| cp866    | DOS Russian                 | cp866_general_ci    |      1 |
| keybcs2  | DOS Kamenicky Czech-Slovak  | keybcs2_general_ci  |      1 |
| macce    | Mac Central European        | macce_general_ci    |      1 |
| macroman | Mac West European           | macroman_general_ci |      1 |
| cp852    | DOS Central European        | cp852_general_ci    |      1 |
| latin7   | ISO 8859-13 Baltic          | latin7_general_ci   |      1 |
| cp1251   | Windows Cyrillic            | cp1251_general_ci   |      1 |
| cp1256   | Windows Arabic              | cp1256_general_ci   |      1 |
| cp1257   | Windows Baltic              | cp1257_general_ci   |      1 |
| binary   | Binary pseudo charset       | binary              |      1 |
| geostd8  | GEOSTD8 Georgian            | geostd8_general_ci  |      1 |
+----------+-----------------------------+---------------------+--------+
27 rows in set (0.00 sec)

posted in 其他 by Orz DBA

Follow comments via the RSS Feed | 发表评论 | Trackback URL

1 Comment to "使用源码包安装MySQL"

  1. orzdba wrote:

    /home/mysql/mysql-5.1.47/bin/mysqld_safe --user=mysql &
    这边的命令是“--user”,有2个“-”,发表文章被后自动转换成下面命令
    /home/mysql/mysql-5.1.47/bin/mysqld_safe –user=mysql &

Leave Your Comment

 
Powered by BlogCN.com - WordPress and MySQL. Theme by Shlomi Noach, openark.org