Linux下用Tar方式安裝MySQL方法步驟

來源:互聯網
上載者:User

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服務的文檔的根目錄
<Directory "/usr/local/apache2/htdocs">
//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

轉載請註明出處!多謝多謝!

幫客之家(Linuxidc)聲明:幫客之家登載此文出於傳遞更多資訊之目的,並不意味著贊同其觀點或證實其描述。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.