溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

Mysql 5.6版本二進制安裝

發(fā)布時間:2020-08-05 16:54:06 來源:網絡 閱讀:2690 作者:lajifeiwomoshu 欄目:MySQL數(shù)據(jù)庫

時間:2018.7.30
作者:李強
參考:man,info,magedu講義,萬能的internet
實驗環(huán)境:VMware? Workstation 12 Pro ,Centos 6.9,Centos 7.4,SecureCRT Version 8.1.4
聲明:以下英文純屬個人翻譯,英文B級,歡迎糾正,以下內容純屬個人理解,并沒有對錯,只是參考,盜版不糾,才能有限,希望不誤人子弟為好。
版本:v1-2018.7.30

參考資料

1、https://www.cnblogs.com/BrightMoon/p/4730081.html
2、https://dev.mysql.com/doc/refman/5.6/en/installing.html

官方下載站點:

https://dev.mysql.com/downloads/mysql/

可以下載rpm包,repo倉庫。二進制包等

一些鏡像站點如搜狐,阿里,網易等都不好使了。

mysql安裝為什么大部分使用二進制安裝。而不是源碼手動去編譯?

mysql使用的glibc進行開發(fā)的。glibc庫是一個底層api,所以只要是linux,都會有glibc庫。所以,mysql安裝不需要考慮環(huán)境是否符合要求。移植性很方便。直接將編譯好的二進制代碼復制到另外一個機器上,也是可以用的。

原理性東西:一般在linux下安裝一個軟件,不同軟件所需要的函數(shù)庫不同。于是會遇到一個現(xiàn)象:一個軟件復制到另外一個平臺可能無法運行。安裝軟件需要先偵測環(huán)境就是出于此考慮。因為mysql使用的是通用的glibc函數(shù)庫。沒有對其他東西的依賴性。所以,從一個平臺復制到另外一個平臺能夠通用。并不需要去偵測環(huán)境。直接使用編譯好的二進制即可

手動編譯安裝,顯得步驟麻煩?;趍ysql的特點,二進制安裝完全可以。

注:mysql5.5安裝的時候,需要用到cmake命令,所以需要保證你的機器上安裝了該命令。沒有的話,還要去安裝該cmake。也顯得麻煩。我暫時不想去安裝最新版本的了。

如果使用二進制安裝升級怎么進行?

升級獲取的還是二進制壓縮包。那么,直接將指向目錄切換到新的目錄即可。

不需要涉及到像php一樣,手動編譯可以達到自己定制模塊的好處。而mysql安裝的時候不需要涉及到模塊

mysql官方建議安裝方式:二進制安裝。

以下為安裝二進制版本5.6.41操作步驟

一、安裝前環(huán)境準備:

1、依賴庫檢查

主要是看二進制安裝依賴的庫是否存在,數(shù)據(jù)庫初始化和服務啟動需要此庫

shell> yum search libaio  # search for info
shell> yum install libaio # install library

2、安裝相關規(guī)劃

    軟件安裝目錄      /usr/loca/app/mysql_13306
    數(shù)據(jù)庫存放目錄  /data/mysql_13306
    port                     13306
    pid_file                /data/mysql_13306/mysql_13306.pid
    socket                 /data/mysql_13306/mysql_13306.socket
    log_error             /var/log/mysql_13306.log

二、進制安裝步驟

1、創(chuàng)建用戶

shell> groupadd mysql
shell> useradd -r -g mysql -s /bin/false mysql

2、下載二進制包

shell> cd /usr/local/app
shell> wget https://cdn.mysql.com//Downloads/MySQL-5.6/mysql-5.6.41-linux-glibc2.12-x86_64.tar.gz
shell> tar zxvf mysql-5.6.41-linux-glibc2.12-x86_64.tar.gz
shell> mv mysql-5.6.41-linux-glibc2.12-x86_64 mysql_13306
shell> ln -s  mysql_13306  ../mysql_13306
# 我覺得建立軟鏈接其實作用就是因為默認的路徑就是這里。當我們安裝多實例的時候,這個步驟就沒有意義了。
shell>cd /usr/local/app/mysql_3306
shell> rm -rf data
shell> ln -s data /data/mysql_13306

3、為工作目錄指定用戶權限

shell> cd mysql_13306
shell> scripts/mysql_install_db --user=mysql   #這里可以指定mysql安裝和安裝數(shù)據(jù)的位置。 
# --basedir=path 使用mysqld程序的路徑 --datadir=path  數(shù)據(jù)庫安裝的路徑
#此腳本,默認執(zhí)行的是
#./bin/mysqld --bootstrap --basedir=. --datadir=/var/lib/mysql --log

shell> chown -R root .
shell> chown -R mysql /data/mysql_13306
# 數(shù)據(jù)庫數(shù)據(jù)位置需要擁有mysql的權限。不能設置為root權限。否則無法啟動。
shell> scripts/mysql_install_db --user=mysql --basedir=/usr/local/app/mysql_13306 --datadir=/usr/local/app/mysql_13306/data
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:

  /home/ewifi/mysql/bin/mysqladmin -u root password 'new-password'
  /home/ewifi/mysql/bin/mysqladmin -u root -h ewifi-yuhang password 'new-password'

Alternatively you can run:

  /home/ewifi/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.

See the manual for more instructions.

You can start the MySQL daemon with:

  cd . ; /home/ewifi/mysql/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/

The latest information about MySQL is available on the web at

  http://www.mysql.com

Support MySQL by buying support/licenses at http://shop.mysql.com

New default config file was created as /home/ewifi/mysql/my.cnf and
will be used by default by the server when you start it.
You may edit this file to change server settings

WARNING: Default config file /etc/my.cnf exists on the system
This file will be read by default by the MySQL server
If you do not want to use this, either remove it, or use the
--defaults-file argument to mysqld_safe when starting the server

/home/ewifi/mysql/bin/mysqld_safe --defaults-file=/home/ewifi/mysql/my.cnf &

4、修改配置文件指定mysql的安裝目錄和數(shù)據(jù)目錄


執(zhí)行完安裝數(shù)據(jù)庫腳本后,會在安裝路徑下自動生成my.cnf配置文件。
主要設置參數(shù),在mysqld下配置。
[mysqld]  

user =mysql                                 //以mysql用戶權限運行mysql服務
baseurl=/usr/loca/app/mysql_13306       //mysql二進制程序路徑,默認為當前程序的./bin/mysqld
dataurl=/data/mysql_13306/        //mysql數(shù)據(jù)庫存放路徑, 默認為/var/lib/mysql

因為我們可能根據(jù)自己的數(shù)據(jù)安全,放在其他位置,可以將二進制里的data目錄刪除,然后建立一個軟鏈接過去。然后設置data的屬性為mysl.mysql

port=13306
socket=/data/mysql_13306/mysql_13306.socket         //socket文件,默認路徑為/var/lib/mysql/mysql.sock
pid-file=/var/run/mysql_13306.pid        //如果沒有指定,那么默認為$datadir/`hostname`.pid
[mysqld_safe]
log-error=/var/log/mysql_13306.log   

5、啟動服務器

shell> bin/mysqld --user=mysql &           # 或使用mysqld_safe
shell> bin/mysqld_safe --user=mysql  --defaults-file=/usr/loca/app/mysql_13306/my.cnf & # 官方建議使用這個

#啟動可以用mysqld也可以使用mysqld_safe,區(qū)別簡單點就是mysqld_safe比mysql更安全,因為mysqld_safe啟動后會監(jiān)控mysql服務狀態(tài)做到自動重啟mysql服務的功能,本質上用到的還是mysqld程序。
#如果安裝目錄和數(shù)據(jù)庫目錄改變,添加相關參數(shù)

6、添加啟動腳本。

# Next command is optional
shell> cp support-files/mysql.server /etc/init.d/mysql_13306.server

如果修改了baseurl和dataurl的位置,這里需要對這2個變量進行賦值
這里調用的就是mysqld_safe 

注意事項

1、不同版本的安裝方式不一樣。需要參考官方安裝指導手冊
2、自定義的路徑,需要修改相關文件的相關變量。官方上是默認路徑。

向AI問一下細節(jié)

免責聲明:本站發(fā)布的內容(圖片、視頻和文字)以原創(chuàng)、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關證據(jù),一經查實,將立刻刪除涉嫌侵權內容。

AI