当前位置:Gxlcms > mysql > Linux下用Tar方式安装MySQL方法步骤

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

时间:2021-07-01 10:21:17 帮助过:100人阅读

1.安装环境操作系统:Red Hat Linux Enterprise AS 4.0数据库:MySQL 6.0.6Web服务器:Apache 2.2.9脚本语言:PHP 5.2.62.安装My

1.安装环境
操作系统:Red Hat Linux Enterprise AS 4.0
数据库:MySQL 6.0.6
Web服务器:Apache 2.2.9
脚本语言:PHP 5.2.6

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" //提供Web服务的文档的根目录

//This should be changed to whatever you set DocumentRoot to.

4.安装PHP 5.2.6

# tar xzvf php-5.2.6.tar.gz

# cd php-5.2.6

# ./configure --with-apxs2=/usr/local/apache2/bin/apxs --with-mysql=/usr/local/mysql/ \
--with-oci8=share,instantclient,/usr/lib/Oracle/10.2.0.3/client/lib //提供对Oracle数据库的支持

(注:如果MySQL采用默认安装路径--即未指定--prefix=/usr/local/mysql,则采用如下命令:
# ./configure --with-apxs2=/usr/local/apache2/bin/apxs --with-mysql
否则会报类似以下的错误:
configure: error: Cannot find MySQL header files under yes.
Note that the MySQL client library is not bundled anymore!)

# make

# make install

copy配置文件
# cp php.ini-dist /usr/local/lib/php.ini

配置Apache服务的httpd.conf文件
*在LoadModule处添加 LoadModule php5_module module/libphp5.so
*在DirectoryIndex处添加 index.php
*在AddType application处添加
AddType application/x-httpd-php .php .phtml
AddType applicatoin/x-httpd-php-source .phps

转载请注明出处!多谢多谢!

Linux公社(Linuxidc)声明:Linux公社登载此文出于传递更多信息之目的,并不意味着赞同其观点或证实其描述。

linux

人气教程排行