linux 安裝mysql服務

來源:互聯網
上載者:User

標籤:

1、檢查是否已安裝,grep的-i選項表示匹配時忽略大小寫

  rpm -qa|grep -i mysql

  *可見已經安裝了庫檔案,應該先卸載,不然會出現覆蓋錯誤。注意卸:載時使用了--nodeps選項,忽略了依賴關係

  rpm -e mysql-libs-5.1.61-4.el6.x86_64 --nodeps

2、 添加mysql組和mysql使用者,用於設定mysql安裝目錄檔案所有者和所屬組。

  groupadd mysql

  useradd -r -g mysql mysql

  *useradd -r參數表示mysql使用者是系統使用者,不可用於登入系統。

3、  將二進位檔案解壓到指定的安裝目錄,我們這裡指定為/usr/local

  cd/usr/local/

  tar zxvf /path/to/mysql-cluster-gpl-7.3.11-linux-glibc2.5-x86_64.tar.gz

  *加壓後在/usr/local/產生瞭解壓後的檔案夾mysql-5.5.29-linux2.6-x86_64,這名字太長,我們為它建立一個符號連結mysql,方便輸入。

  ln -s mysql-cluster-gpl-7.3.11-linux-glibc2.5-x86_64 mysql

  /usr/local/mysql/下的目錄結構  

  

Directory

Contents of Directory

bin

Client programs and the mysqld server

data

Log files, databases

docs

Manual in Info format

man

Unix manual pages

include

Include (header) files

lib

Libraries

scripts

mysql_install_db

share

Miscellaneous support files, including error messages, sample configuration files, SQL for database installation

sql-bench

Benchmarks

 

  

e.     進入mysql檔案夾,也就是mysql所在的目錄,並更改所屬的組和使用者。

[[email protected] local]#cd mysql

[[email protected] mysql]#chown -R mysql .

[r[email protected] mysql]#chgrp -R mysql .

f.       執行mysql_install_db指令碼,對mysql中的data目錄進行初始化並建立一些系統資料表格。注意mysql服務進程mysqld運行時會訪問data目錄,所以必須由啟動mysqld進程的使用者(就是我們之前設定的mysql使用者)執行這個指令碼,或者用root執行,但是加上參數--user=mysql。

[[email protected] mysql]scripts/mysql_install_db --user=mysql

*如果mysql的安裝目錄(解壓目錄)不是/usr/local/mysql,那麼還必須指定目錄參數,如

[[email protected] mysql]scripts/mysql_install_db --user=mysql \

         --basedir=/opt/mysql/mysql \

         --datadir=/opt/mysql/mysql/data

*將mysql/目錄下除了data/目錄的所有檔案,改回root使用者所有,mysql使用者只需作為mysql/data/目錄下所有檔案的所有者。

[[email protected] mysql]chown -R root .

[[email protected] mysql]chown -R mysql data

g.     複製設定檔

[[email protected] mysql] cp support-files/my-medium.cnf /etc/my.cnf

h.  將mysqld服務加入開機自啟動項。

*首先需要將scripts/mysql.server服務指令碼複製到/etc/init.d/,並重新命名為mysqld。

[[email protected]]  cp support-files/mysql.server /etc/init.d/mysqld

*通過chkconfig命令將mysqld服務加入到自啟動服務項中。

[[email protected] mysql]#chkconfig --add mysqld

*注意服務名稱mysqld就是我們將mysql.server複製到/etc/init.d/時重新命名的名稱。

*查看是否添加成功

[[email protected] mysql]#chkconfig --list mysqld

mysqld   0:off 1:off        2:on        3:on        4:on        5:on        6:off

i.  重啟系統,mysqld就會自動啟動了。

*檢查是否啟動

[[email protected] mysql]#netstat -anp|grep mysqld

tcp        0     0 0.0.0.0:3306               0.0.0.0:*                   LISTEN      2365/mysqld        

unix  2     [ ACC ]     STREAM     LISTENING     14396 2365/mysqld        /tmp/mysql.sock

*如果不想重新啟動,那可以直接手動啟動。

[[email protected] mysql]#service mysqld start

Starting MySQL.. SUCCESS!

j.       運行用戶端程式mysql,在mysql/bin目錄中,測試能否串連到mysqld。

[[email protected] mysql]#/usr/local/mysql/bin/mysql

Welcome to the MySQLmonitor.  Commands end with ; or \g.

Your MySQL connection idis 2

Server version:5.5.29-log MySQL Community Server (GPL)

 

Copyright (c) 2000, 2012,Oracle and/or its affiliates. All rights reserved.

Oracle is a registeredtrademark of Oracle Corporation and/or its affiliates. Other names may betrademarks of their respective owners.

Type ‘help;‘ or ‘\h‘ forhelp. Type ‘\c‘ to clear the current input statement.

mysql> quit

Bye

*此時會出現mysql>命令提示字元,可以輸入sql語句,輸入quit或exit退出。為了避免每次都輸入mysql的全路徑/usr/local/mysql/bin/mysql,可將其加入環境變數中,在/etc/profile最後加入兩行命令:

MYSQL_HOME=/usr/local/mysql

export PATH=$PATH:$MYSQL_HOME/bin

這樣就可以在shell中直接輸入mysql命令來啟動用戶端程式了

[[email protected] mysql]#mysql

Welcome to the MySQLmonitor.  Commands end with ; or \g.

Your MySQL connection idis 3

Server version:5.5.29-log MySQL Community Server (GPL)

Copyright (c) 2000, 2012,Oracle and/or its affiliates. All rights reserved.

Oracle is a registeredtrademark of Oracle Corporation and/or its

affiliates. Other namesmay be trademarks of their respective

owners.

Type ‘help;‘ or ‘\h‘ forhelp. Type ‘\c‘ to clear the current input statement.

mysql>

linux 安裝mysql服務

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.