mysql 三种安装方式:RPM 二进制包和源代码

mysql的三种安装方式:RPM 二进制包和源代码

本次安装的系统平台为redhat 5

一、使用RPM包进行安装

首先可以从安装光盘中或者到mysql的网站上下载对应版本的rpm包如下:
MySQL-server-community-5.1.38-0.rhel5.i386.rpm
MySQL-client-community-5.1.38-0.rhel5.i386.rpm

接着我们可以使用rpm命令进行安装:
rpm -ivh MySQL-server-community-5.1.38-0.rhel5.i386.rpm
rpm -ivh MySQL-client-community-5.1.38-0.rhel5.i386.rpm

二、安装二进制包

步骤如下:

1、用root登录系统,增加mysql用户和组

groupadd mysql
useradd -g mysql mysql

2、解压二进制包,假如二进制包放在/home/mysql下,我们在解压后并增加一个符号链接

tar xvfz mysql-5.1.38-linux-i686-glibc23.tar.gz
ln -s mysql-5.1.38-linux-i686-glibc23 mysql

3、在数据库目录下创建系统数据库的表,--user表示这些数据库和表的所有者为此用户

cd mysql
./scripts/mysql_install_db --user=mysql

4、设置目录权限,将data目录的所有者改为mysql,其它目录的文件的所有者为root

chown -R root:mysql .
chown -R mysql:mysql data

5、启动mysql

./bin/mysqld_safe --user=mysql &

三、源码安装mysql

1、用root登录系统,增加mysql用户和组

groupadd mysql
useradd -g mysql mysql

2、解压源码包,并进入解压后的目录

tar xvfz mysql-5.1.38.tar.gz
cd mysql-5.1.38

3、用configure工具来编译源代码,这里我们可以使用很多的参数,具体可以用configure --help来查看,这里我们将mysql安装到/usr/local/mysql下

./configuer --prefix=/usr/local/mysql
make
make install

4、选择一个样例配置文件,并复制到/etc/下改名为my.cnf

cp support-files/my-medium.cnf /etc/my.cnf

5、在数据库目录下创建系统数据库的表,--user表示这些数据库和表的所有者为此用户

cd /usr/local/mysql
./bin/mysql_install_db --user=mysql

6、设置目录权限,将var目录的所有者更改为mysql,其它目录和文件的所有者为root

chown -R root .
chown -R mysql var
chgrp -R mysql .

7、启动mysql

./bin/mysqld_safe --user=mysql &

/

我选择源码安装:

1.安装make编译器

下载地址: http://www.gnu.org/software/make/

[c-sharp] view plain copy print ?
  1. tar zxvf make-3.82.tar.gz
  2. cd make-3.82
  3. ./configure
  4. make
  5. make install
tar zxvf make-3.82.tar.gz cd make-3.82 ./configure make make install

2.安装bison

下载地址:http://www.gnu.org/software/bison/

[c-sharp] view plain copy print ?
  1. tar zxvf bison-2.5.tar.gz
  2. cd bison-2.5
  3. ./configure
  4. make
  5. make install
tar zxvf bison-2.5.tar.gz cd bison-2.5 ./configure make make install

3.安装gcc-c++

下载地址:http://www.gnu.org/software/gcc/

[c-sharp] view plain copy print ?
  1. tar zxvf gcc-c++-4.4.4.tar.gz
  2. cd gcc-c++-4.4.4
  3. ./configure
  4. make
  5. make install
tar zxvf gcc-c++-4.4.4.tar.gz cd gcc-c++-4.4.4 ./configure make make install

4.安装cmake

下载地址:http://www.cmake.org/

[c-sharp] view plain copy print ?
  1. tar zxvf cmake-2.8.4.tar.gz
  2. cd cmake-2.8.4
  3. ./configure
  4. make
  5. make install
tar zxvf cmake-2.8.4.tar.gz cd cmake-2.8.4 ./configure make make install

5.安装ncurses

下载地址:http://www.gnu.org/software/ncurses/

[c-sharp] view plain copy print ?
  1. tar zxvf ncurses-5.8.tar.gz
  2. cd ncurses-5.8
  3. ./configure
  4. make
  5. make install
tar zxvf ncurses-5.8.tar.gz cd ncurses-5.8 ./configure make make install

开始安装MySQL,下载地址:http://dev.mysql.com/

http://dev.mysql.com/downloads/mysql/5.5.html#downloads

选择平台为 source code

准备工作

[c-sharp] view plain copy print ?
  1. groupadd mysql
  2. useradd -r -g mysql mysql
groupadd mysql useradd -r -g mysql mysql

解压并安装MySQL

[c-sharp] view plain copy print ?
  1. tar zxvf mysql-5.5.13.tar.gz
  2. cd mysql-5.5.13
  3. cmake . /
  4. -DCMAKE_INSTALL_PREFIX=/usr/local/mysql /
  5. -DINSTALL_DATADIR=/usr/local/mysql/data
  6. make
  7. make install
tar zxvf mysql-5.5.13.tar.gz cd mysql-5.5.13 cmake . / -DCMAKE_INSTALL_PREFIX=/usr/local/mysql / -DINSTALL_DATADIR=/usr/local/mysql/data make make install

完成后,继续下面的操作

[c-sharp] view plain copy print ?
  1. cd /usr/local/mysql
  2. chown -R mysql .
  3. chgrp -R mysql .
  4. scripts/mysql_install_db --user=mysql
  5. chown -R root .
cd /usr/local/mysql chown -R mysql . chgrp -R mysql . scripts/mysql_install_db --user=mysql chown -R root .

下面的命令是可选的,将mysql的配置文件拷贝到/etc

[c-sharp] view plain copy print ?
  1. cp support-files/my-medium.cnf /etc/my.cnf
cp support-files/my-medium.cnf /etc/my.cnf

启动mysql:

[c-sharp] view plain copy print ?
  1. bin/mysqld_safe --user=mysql &
  2. #启动mysql,看是否成功
  3. netstat -tnl|grep 3306
bin/mysqld_safe --user=mysql & #启动mysql,看是否成功 netstat -tnl|grep 3306

上面是一种启动mysql的方法,还有一种简单的方便,如下:

[c-sharp] view plain copy print ?
  1. #将mysql的启动服务添加到系统服务中
  2. cp support-files/mysql.server /etc/init.d/mysql.server
  3. #现在可以使用下面的命令启动mysql
  4. service mysql.server start
  5. #停止mysql服务
  6. service mysql.server stop
  7. #重启mysql服务
  8. service mysql.server restart
#将mysql的启动服务添加到系统服务中 cp support-files/mysql.server /etc/init.d/mysql.server #现在可以使用下面的命令启动mysql service mysql.server start #停止mysql服务 service mysql.server stop #重启mysql服务 service mysql.server restart

将mysql服务添加到开机启动项,让mysql服务开机启动

[c-sharp] view plain copy print ?
  1. chkconfig --add mysql.server
chkconfig --add mysql.server

重启机器后,mysql服务就会自动启动了。


如果报错:

[@tc_157_61 mysql]# service mysql.server start

Starting MySQL.The server quit without updating PID file (/usr/local/mysql/data/tc_157_61.pid).[FAILED]

则赋权限给data

[@tc_157_61 mysql]# chmod 777 data

[@tc_157_61 mysql]# service mysql.server start

Starting MySQL...[  OK  ]


(7)修改MySQL的root用户的密码以及打开远程连接

[root@ rhel5~]# mysql -u root mysql


mysql>use mysql;

mysql>desc user;

mysql> GRANT ALL PRIVILEGES ON *.* TO root@"%" IDENTIFIED BY "root";  //为root添加远程连接的能力。

mysql>update user set Password = password('xxxxxx') where User='root';

mysql>select Host,User,Password  from user where User='root'; 

mysql>flush privileges;

mysql>exit


重新登录:mysql -u root -p


若还不能进行远程连接,则关闭防火墙

[root@ rhel5~]# /etc/rc.d/init.d/iptables stop

注:如果不能远程连接,出现错误mysql error number 1130,则加入下面语句试试:

mysql>GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '******' WITH GRANT OPTION;

红色的部分是真正的安装步骤。

还有个地址 参考:http://www.cnblogs.com/fly1988happy/archive/2011/11/21/2257682.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值