基於二進制程序安裝mariadb

  • 環境:教室,默認lftp的ip地址:172.16.0.1
  • 基於二進制程序必須安裝在/usr/local目錄下,並且解壓後的目錄必須叫mysql
  • lftp 172.16.0.1獲取到Mariadb-5.5.36安裝包
    1. get到當地目錄
  • 展開程序:
  • [root@localhost yum.repos.d]# tar xf mariadb-5.5.36-linux-x86_64.tar.gz -C /usr/local
  •  
  • cd到該目錄下
  • [root@localhost mariadb-5.5.36-linux-x86_64]# ll
    total 212
    drwxr-xr-x  2 root root   4096 Aug 12 20:46 bin
    -rw-r--r--  1  500  500  17987 Feb 24 07:50 COPYING
    -rw-r--r--  1  500  500  26545 Feb 24 07:50 COPYING.LESSER
    drwxr-xr-x  3 root root   4096 Aug 12 20:46 data
    drwxr-xr-x  2 root root   4096 Aug 12 20:46 docs
    drwxr-xr-x  3 root root   4096 Aug 12 20:46 include
    -rw-r--r--  1  500  500   8694 Feb 24 07:50 INSTALL-BINARY 安裝程序的方法
    drwxr-xr-x  3 root root   4096 Aug 12 20:46 lib
    drwxr-xr-x  4 root root   4096 Aug 12 20:46 man
    drwxr-xr-x 11 root root   4096 Aug 12 20:47 mysql-test
    -rw-r--r--  1  500  500 108813 Feb 24 07:50 README 安裝程序的方法  
    drwxr-xr-x  2 root root   4096 Aug 12 20:46 scripts
    drwxr-xr-x 27 root root   4096 Aug 12 20:46 share
    drwxr-xr-x  4 root root   4096 Aug 12 20:46 sql-bench
    drwxr-xr-x  4 root root   4096 Aug 12 20:46 support-files
    [root@localhost mariadb-5.5.36-linux-x86_64]# less INSTALL-BINARY
  • image
  • 上面明確的寫着如何安裝的方法。
  • 因爲安裝後數據存放在/usr/local/mariadb-5.5-36…./data目錄下,這些數據通常非常非常重要,所以建議放到邏輯卷中,一來可以當數據量大了以後方便擴展,二來可以通過快照進行恢復。所以分個區:
  • image
  • 然後可以在根目錄下創建個目錄,叫mydata,專門放數據庫的數據。
  • image
  • 然後再創建系統用戶mysql和創建系統組mysql
  • image
  • 直接在根目錄系統下掛載有時候不便,所以在剛纔建好的目錄下再次創建個目錄可以叫/data,如mkdir /mydata/data
  • 因爲mysql服務應該使用普通用戶登錄,所以要改下數據庫的目錄和目錄下文件的屬主屬組,如:
  • image
  • 再次cd回/usr/local目錄下,對已經下載過的mariadb…..那個包的名字進行重命名,因爲名稱要求使用mysql。
  • image
  • 然後我們cd進/usr/local目錄下,先讓我們看看都生成了什麼文件並修改下目錄和文件的權限:
  •  image
  • 其中bin/目錄下的S表示服務器端,C表示客戶端。
  • 下面我們要改/usr/local/mysql/data目錄和文件的權限,因爲它們跟數據庫的數據有關,需要普通用戶開啓的進程。
  • image
  • mysql第一次啓動前要初始化,但先cd到support_files
  • 查看下列5個文件:
  • image
  • 它們分別應用於不同內存的平臺上 ,所以我們要看自己的內存,以便使用: free命令
  • 找到所屬於自己內存大小的配置文件複製到新建在/etc/mysql目錄中去,並重命名爲my.cnf
  • image
  • 編輯my.cnf,然後在空白出填入剛創建的保存數據的mydata處,記得一定要在[mysqld]處
  • datadir=/mydata/data
  • 查看安裝腳本
  • [root@localhost scripts]# ll
    total 16
    -rwxr-xr-x 1 root mysql 16168 Feb 24 11:08 mysql_install_db
  •  
  • [root@localhost scripts]#  scripts/mysql_install_db --help
    Usage: ./mysql_install_db [OPTIONS]
      --basedir=path       The path to the MariaDB installation directory.
      --builddir=path      If using --srcdir with out-of-directory builds, you
                           will need to set this to the location of the build
                           directory where built files reside.
      --cross-bootstrap    For internal use.  Used when building the MariaDB system
                           tables on a different host than the target.
      --datadir=path       The path to the MariaDB data directory.
      --defaults-extra-file=name
                           Read this file after the global files are read.
      --defaults-file=name Only read default options from the given file name.
      --force              Causes mysql_install_db to run even if DNS does not
                           work.  In that case, grant table entries that normally
                           use hostnames will use IP addresses.
      --help               Display this help and exit.                    
      --ldata=path         The path to the MariaDB data directory. Same as
                           --datadir.
      --no-defaults        Don't read default options from any option file.
      --defaults-file=path Read only this configuration file.
      --rpm                For internal use.  This option is used by RPM files
                           during the MariaDB installation process.
      --skip-name-resolve  Use IP addresses rather than hostnames when creating
                           grant table entries.  This option can be useful if
                           your DNS does not work.
      --srcdir=path        The path to the MariaDB source directory.  This option
                           uses the compiled binaries and support files within the
                           source tree, useful for if you don't want to install
                           MariaDB yet and just want to create the system tables.
      --user=user_name     The login username to use for running mysqld.  Files
                           and directories created by mysqld will be owned by this
                           user. 
  • 上面兩個選項很重要,定義了安裝啓動時用哪個用戶登錄並且數據庫數據存放的目錄在哪裏
  • 並且必須回到mysql目錄下進行安裝操作!因爲它依賴bin/目錄下的文件。執行如下:
  • [root@localhost mysql]# scripts/mysql_install_db --user=mysql --datadir=/mydata/data
    Installing MariaDB/MySQL system tables in '/mydata/data' ...
    OK
  • image
  •  
  • 但是後續還有收尾工作需要完成,還需要在/etc/rc.d/init.d下添加服務腳本,以便service mysqld start/stop/status/restart…,所以
  • 複製目錄下support-files裏面的mysql.server的服務腳本,粘貼到/etc/rc.d/init.d/並命名爲mysqld,最後再用ll 查看下是否other有執行權限:
  • image
  • 並且可以給它加載到開機啓動中去,使用chkconfig –add 服務腳本名稱
  • chkconfig –list 查看0-6中那些處於開啓的:
  • image
  • 最後我們使用service mysqld start 開啓服務
  •  image
  • 但是執行會出問題,顯示
  • image
  • 提示我們還要去/etc/profile.d/下編輯一個mysql.sh,裏面導出環境變量。
  • 添加export PATH=/usr/local/mysql/bin:$PATH
  • 最後source一下,然後就可以正常啓動了!
  • image
  • ---------------------------------------------------------------------------------------------------------------------------------------------------------------
  • image SELECT VERSION();選擇版本並返回該函數的狀態
  • image SELECT USER();查看用戶 && SELECT CURRENT_USER();查看當前用戶
  • image 還可以用mysql進行計算!
  • image 對頭文件做軟連接,當開發其他程序的頭文件,
  • image
  • 最後關於導出庫文件,由於mariadb都是18、19頭文件的庫,所以編輯/etc/ld.so.conf.d/mysql.conf
  • 寫入/usr/local/mysql/lib
  • 再次ldconfig –v | grep mysql
  • image
  • jobs done;
  • 發表評論
    所有評論
    還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
    相關文章