Linux下MySQL server和client安裝


一、安裝方法

       安裝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選項表示匹配時忽略大小寫

       [root@DevTJ-todo-15070919100 /]# 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選項,忽略依賴關系:

     [root@DevTJ-todo-15070919100 /]# rpm -e mysql-5.1.61-1.el6_2.1.x86_64 --nodeps

     [root@DevTJ-todo-15070919100 /]# rpm -e perl-DBD-MySQL-4.013-3.el6.x86_64 --nodeps

     [root@DevTJ-todo-15070919100 /]# rpm -e mysql-libs-5.1.61-1.el6_2.1.x86_64 --nodeps

四、添加mysql組和mysql用戶,用於設置mysql安裝目錄文件所有者和所屬組

       [root@DevTJ-todo-15070919100 /]# groupadd mysql
       [root@DevTJ-todo-15070919100 /]# useradd -r -g mysql mysql    (-r參數表示mysql用戶是系統用戶,不可用於登錄系統)

五、安裝

    1.將二進制文件解壓至指定目錄,比如/usr/local

       [root@DevTJ-todo-15070919100 /]# cd /usr/local

       [root@DevTJ-todo-15070919100 /usr/local]# tar zxf mysql-5.5.45-linux2.6-x86_64.tar.gz

       文件夾名字太長,做一個符號鏈接[root@DevTJ-todo-15070919100 /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.改變所屬的組和用戶

     [root@DevTJ-todo-15070919100 /usr/local/mysql]# chown -R mysql .
     [root@DevTJ-todo-15070919100 /usr/local/mysql]# chgrp -R mysql .

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

     [root@DevTJ-todo-15070919100 /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,那么還必須指定目錄參數,如

      [root@DevTJ-todo-15070919100 /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目錄下所有文件的所有者。

      [root@DevTJ-todo-15070919100 /usr/local/mysql]# chown -R root .
      [root@DevTJ-todo-15070919100 /usr/local/mysql]# chown -R mysql data .

    6.將配置文件復制到/etc/my.cnf

      [root@DevTJ-todo-15070919100 /usr/local/mysql]# cp support-files/my-medium.cnf /etc/my.cnf

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

      a.將scripts/mysql.server服務腳本復制到/etc/init.d,並重命名為mysqld

      [root@DevTJ-todo-15070919100 /usr/local/mysql]# cp support-files/mysql.server /etc/init.d/mysqld

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

          [root@DevTJ-todo-15070919100 /usr/local/mysql]# chkconfig --add mysqld

        查看添加是否成功:

           [root@DevTJ-todo-15070919100 /usr/local/mysql]# chkconfig --list mysqld
        mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off

六、修改配置,啟動

      1.修改配置

       [root@DevTJ-todo-15070919100 /usr/local/mysql]# vim /etc/my.cnf

       初始配置只有:

 

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

     2.啟動。

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

       [root@DevTJ-todo-15070919100 /usr/local/mysql]# service mysqld start
       Starting MySQL... SUCCESS!

       b.添加用戶,重啟mysql。

補充,安裝mysql client

      [root@DevTJ-todo-15070919100]#rpm -ivh MySQL-client-5.5.28-1.linux2.6.x86_64.rpm


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM