Linux下用Tar方式安装MySQL方法步骤(一)

2014-11-24 17:39:11 · 作者: · 浏览: 1

2.安装MySQL 6.0.6


# groupadd mysql
# useradd -g mysql mysql
# tar xzvf mysql-6.0.6-alpha.tar.gz
# cd mysql-6.0.6-alpha
# ./configure --prefix=/usr/local/mysql
# make
# make install
# cp support-files/my-medium.cnf /etc/my.cnf
# cd /usr/local/mysql
# chown -R mysql .
# chgrp -R mysql .
# bin/mysql_install_db --user=mysql
# chown -R root .
# chown -R mysql var
# bin/mysqld_safe --user=mysql &


详解如下:


1)建立相应目录和组:
# mkdir /usr/local/mysql
# groupadd mysql
# useradd -g mysql mysql //useradd -g mysql -d /usr/local/mysql name


2)开始安装mysql
# tar xzvf mysql-6.0.6-alpha.tar.gz //解压缩


# cd mysql-6.0.6-alpha //进入解压后的文件目录


# ./configure --prefix=/usr/local/mysql \ //设定安装目录
--enable-thread-safe-client \ //编译线程安全版的客户端库
--without-debug \ //关闭debug功能
--with-extra-charsets=gb2312 \ //添加gb2312中文字符支持
--enable-assembler \ //使用一些字符函数的汇编版本
--with-raid \ //激活raid支持


# make //编译


# make install //安装


3)copy配置文件
有large,medium,small三个环境下的,根据机器性能选择,如果负荷比较大,可修改里面的一些变量的内存使用值
# cp support-files/my-medium.cnf /etc/my.cnf //复制配置文件


4)更改目录权限和组
# cd /usr/local/mysql
# chown -R mysql .
# chgrp -R mysql .


5)建立数据库和表
# bin/mysql_install_db --user=mysql //初始化授权


注:如果报以下错误
Installing MySQL system tables...
[ERROR] /usr/local/mysql/libexec/mysqld: unknown option '--skip-federated'
[ERROR] Aborting
[Note] /usr/local/mysql/libexec/mysqld: Shutdown complete
只要将/etc/my.cnf文件中的skip-federated注释掉即可


6)再次更改目录权限和组
# chown -R root .
# chown -R mysql var


7)启动MySQL服务
# bin/mysqld_safe --user=mysql &
//启动MySQL(The & character tells the operating system to run MySQL in the background;
//it is ignored by MySQL itself.
//如果报错,注意及时查看/usr/local/mysql/var/下的日志文件)


8)设置MySQL启动服务
# cp /usr/local/mysql/share/mysql/mysql.server /etc/init.d/mysqld
# chkconfig --add mysqld //在自动启动列表里添加mysqld
# chkconfig --level 345 mysqld on


9)修改MySQL密码
# /usr/local/mysql/bin/mysqladmin -u root password 'new-password' //修改密码
# /usr/local/mysql/bin/mysqladmin -u root -h localhost password 'new-password'
// 将localhost替换成你的主机域名,比如:zhaorg.csu.edu.cn


10)登录mysql数据库


# mysql -u root -p
Enter password: root
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 18 to server version: 5.0.19-log
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> use mysql;
mysql>delete from user where password=""; //删除用于本机匿名连接的空密码帐号
mysql>flush privileges;
mysql>quit


(或者,也可运行如下命令(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.)


11)关闭MySQL服务


# /usr/local/mysql/bin/mysqladmin -u root -p new-password shutdown //关闭MySQL


3.安装Apache 2.2.9


# tar zvxf httpd-2.2.9.tar.gz


# cd httpd-2.2.9


# ./configure --enable-modules=all --enable-so //DSO capability


# make


# make install


启动Apache服务
# /usr/local/apache2/bin/apachectl start


关闭Apache服务
# /usr/local/apache2/bin/apachectl stop


重启Apache服务
# /usr/local/apache2/bin/apachectl restart


设置Apache启动服务
#cp /usr/local/apache2/bin/apachectl /etc/init.d/httpd


更改相应的配置文件
#vi /usr/local/apache2/conf/httpd.conf


DocumentRoot "/usr/local/apache2/htdocs"