Linux下MySQL server和client安裝

來源:互聯網
上載者:User

標籤:

一、安裝方法

       安裝MySQL主要有兩種方法:一種是通過原始碼進行編譯安裝,適合進階使用者自己定製MySQL的特性;另一種比較簡單的是使用已經編譯過的二進位檔案進行安裝。二進位檔案安裝又分為不針對特定平台的通用安裝方法,即.tar.gz壓縮檔;另一種是使用RPM或其他包進行安裝,這種方式會自動完成系統的相關配置。本次記錄使用.tar.gz檔案安裝過程。

二、下載檔案

       mysql-5.5.45-linux2.6-x86_64.tar.gz(附件中有)

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

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

       [[email protected] /]# rpm -qa|grep -i mysql
       perl-DBD-MySQL-4.013-3.el6.x86_64
       mysql-libs-5.1.61-1.el6_2.1.x86_64
       mysql-5.1.61-1.el6_2.1.x86_64

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

     [[email protected] /]# rpm -e mysql-5.1.61-1.el6_2.1.x86_64 --nodeps

     [[email protected] /]# rpm -e perl-DBD-MySQL-4.013-3.el6.x86_64 --nodeps

     [[email protected] /]# rpm -e mysql-libs-5.1.61-1.el6_2.1.x86_64 --nodeps

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

       [[email protected] /]# groupadd mysql
       [[email protected] /]# useradd -r -g mysql mysql    (-r參數表示mysql使用者是系統使用者,不可用於登入系統)

五、安裝

    1.將二進位檔案解壓至指定目錄,比如/usr/local

       [[email protected] /]# cd /usr/local

       [[email protected] /usr/local]# tar zxf mysql-5.5.45-linux2.6-x86_64.tar.gz

       檔案夾名字太長,做一個符號連結[[email protected] /usr/local]# ln -s mysql-5.5.45-linux2.6-x86_64 mysql

    2.查看下/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

 

    3.改變所屬的組和使用者

     [[email protected] /usr/local/mysql]# chown -R mysql .
     [[email protected] /usr/local/mysql]# chgrp -R mysql .

   4.執行mysql_install_db指令碼,對mysql中的data目錄進行初始化並建立一些系統資料表格。mysql服務的進程mysqld運行時要訪問data目錄,所以必須由mysqld的使用者(前面設定的mysql)執行這個指令碼,或者由root執行並加上參數--user=mysql:

     [[email protected] /usr/local/mysql]# scripts/mysql_install_db --user=mysql

     執行情況:

Installing MySQL system tables...
150809 11:20:06 [Note] ./bin/mysqld (mysqld 5.5.45) starting as process 28004 ...
OK
Filling help tables...
150809 11:20:06 [Note] ./bin/mysqld (mysqld 5.5.45) starting as process 28011 ...
OK

To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:

./bin/mysqladmin -u root password ‘new-password‘
./bin/mysqladmin -u root -h DevTJ-todo-15070919100 password ‘new-password‘

Alternatively you can run:
./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.

See the manual for more instructions.

You can start the MySQL daemon with:
cd . ; ./bin/mysqld_safe &

You can test the MySQL daemon with mysql-test-run.pl
cd ./mysql-test ; perl mysql-test-run.pl

Please report any problems at http://bugs.mysql.com/

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

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

    --basedir=/opt/mysql/mysql \

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

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

      [[email protected] /usr/local/mysql]# chown -R root .
      [[email protected] /usr/local/mysql]# chown -R mysql data .

    6.將設定檔複製到/etc/my.cnf

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

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

      a.將scripts/mysql.server服務指令碼複製到/etc/init.d,並重新命名為mysqld

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

       b.通過chkconfig命令將mysqld服務加入到開機啟動服務

          [[email protected] /usr/local/mysql]# chkconfig --add mysqld

        查看添加是否成功:

           [[email protected] /usr/local/mysql]# chkconfig --list mysqld
        mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off

六、修改配置,啟動

      1.修改配置

       [[email protected] /usr/local/mysql]# vim /etc/my.cnf

       初始配置只有:

 

     可根據個人需要進行配置。

     2.啟動。

       a.重啟系統mysqld就會自動啟動,或者直接手動啟動msql。

       [[email protected] /usr/local/mysql]# service mysqld start
       Starting MySQL... SUCCESS!

       b.添加使用者,重啟mysql。

補充,安裝mysql client

      [[email protected]]#rpm -ivh MySQL-client-5.5.28-1.linux2.6.x86_64.rpm

Linux下MySQL server和client安裝

聯繫我們

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