- 论坛徽章:
- 0
|
Normal
0
7.8 磅
0
2
false
false
false
EN-US
ZH-CN
X-NONE
/* Style Definitions */
table.MsoNormalTable
{mso-style-name:普通表格;
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-priority:99;
mso-style-qformat:yes;
mso-style-parent:"";
mso-padding-alt:0cm 5.4pt 0cm 5.4pt;
mso-para-margin:0cm;
mso-para-margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:10.0pt;
font-family:"Times New Roman","serif";}
1. 准备和安装
在安装MySQL之前,请确定系统已经安装了GCC包,以便make编译。
1.1. 创建角色、组和目录
首先,创建mysql用户和组,命令如下:
shell> groupadd mysql
shell> useradd -g mysql mysql
由于configure程序和make并不会直接创建目录,所以需要提前手动创建mysql安装目录和数据库目录。
shell> mkdir /usr/local/mysql
shell> mkdir /data/mydb
1.2. 解压安装包
然后,解压mysql 5.0.37的源码安装包。
shell> tar -xzvf mysql-5.0.37.tar.gz
1.3. Configure和编译安装
进入解压出来的目录mysql-5.0.37:
shell>cd mysql-5.0.37
用configure程序对安装进行设置:
shell>./configure --prefix=/usr/local/mysql --localstatedir=/data/mydb
--with-charset=utf8 --with-extra-charsets=all
参数说明:
--prefix mysql程序安装目录
--localstatedir 数据目录
--with-charset 默认字符集
--with-extra-charset 附带字符集
设置好后,进行编译和安装:
shell>make && make install
2. 权限设置和初始化
2.1. 权限设置
安装完毕,现在要为数据库初始化和实例运行做准备。
u
首先,确定/tmp目录是否有所有用户的写权限,如没有请设置:
shell>chmod 777 /etc
u
设置数据目录的所有者和用户组
shell>chown -R mysql /data/mydb
shell>chgrp -R mysql /data/mydb
u
设置MySQL安装目录的所有者和用户组
shell>chown -R root /usr/local/mysql
shell>chgrp -R mysql /usr/local/mysql
1.
2.
2.1.
2.2. 初始化数据库
权限设置完毕后,进入/usr/local/mysql/bin目录,对数据库进行初始化。
shell>cd /usr/local/mysql/bin
然后执行mysql_install_db脚本,以mysql用户对数据库进行初始化:
shell>./mysql_install_db --user=mysql
--datadir=/data/mydb
执行完毕后查看/data/mydb目录下是否已经创建了mysql和test目录。如果有,则初始化成功。
2.3. 配置文件
在运行数据库实例之前,要把配置文件放到/etc下,MySQL提供了几种典型的数据库配置文件,可以根据需要选择,供选择的配置文件在/usr/local/mysql/share/mysql下,我们选择my-medium.cnf,拷贝到/etc下,重命名为my.cnf
shell>cp /usr/local/mysql/share/mysql/my-medium.cnf
/etc/my.cnf
然后根据服务器进行参数调整:
shell>vi /etc/my.cnf
3. 运行数据库
3.1. 运行数据库
配置完毕后,就可以运行mysql实例了,注意要以mysql用户启动。
shell>/usr/local/mysql/bin/mysqld_safe --user=mysql &
3.2. 设置开机自动启动
shell>vi /etc/rc.local
然后在最后添加下面的粗体字:
#!/bin/sh
#
# This script will be executed *after* all the
other init scripts.
# You can put your own initialization stuff in
here if you don't
# want to do the full Sys V style init stuff.
touch /var/lock/subsys/local
/usr/local/mysql/bin/mysqld_safe
--user=mysql &
4. 命令行步骤总览
shell>
groupadd
mysql
shell>
useradd -g
mysql mysql
shell>
mkdir
/usr/local/mysql
shell>
mkdir
/data/mydb
shell>
tar -xzvf mysql-5.0.37.tar.gz
shell>
cd mysql-5.0.37
shell>
./configure
--prefix=/usr/local/mysql --localstatedir=/data/mydb --with-charset=utf8 --with-extra-charsets=all
shell>
make
&& make install
shell>
chmod 777
/etc
shell>
chown -R
mysql /data/mydb
shell>
chgrp -R
mysql /data/mydb
shell>
chown -R
root /usr/local/mysql
shell>
chgrp -R
mysql /usr/local/mysql
shell>
cd
/usr/local/mysql/bin
shell>
./mysql_install_db
--user=mysql --datadir=/data/mydb
shell>
cp
/usr/local/mysql/share/mysql/my-medium.cnf /etc/my.cnf
shell>
vi
/etc/my.cnf
shell>
/usr/local/mysql/bin/mysqld_safe
--user=mysql &
本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u1/36085/showart_2103838.html |
|