CentOS 6.8 編譯安裝MySQL5.5.32 (二 多執行個體)

來源:互聯網
上載者:User

標籤:設定檔   mysql多執行個體   

MySQL多執行個體的配置

通過上文 CentOS 6.8 編譯安裝MySQL5.5.32 ,我們完成了編譯安裝,接下配置多執行個體


5,添加多執行個體目錄

[[email protected] application]# mkdir -p /data/{3306,3307}/data[[email protected] application]# tree  /data//data/├── 3306   │   └── data   └── 3307       └── data,

6,上傳多執行個體設定檔

[[email protected] /]# cd /[[email protected] /]# rz -y data.zip [[email protected] /]# unzip data.zip[[email protected] /]# tree datadata├── 3306  ##3306執行個體目錄│   ├── data     │   ├── my.cnf   │   └── mysql    └── 3307    ├── data    ├── my.cnf    └── mysql

##多執行個體 檔案對比 設定檔中 只有字串 3306與3307,與serverID 的不同

7,給Mysql啟動指令碼增加執行許可權

find /data -type f -name "mysql"|xargs chmod +xchown -R mysql.mysql /data

650) this.width=650;" src="https://s5.51cto.com/wyfs02/M02/92/DE/wKiom1kEGjLzMo8JAABdjs04lcw923.png" style="float:none;" title="1_副本.png" alt="wKiom1kEGjLzMo8JAABdjs04lcw923.png" />

8,多執行個體初始化,作用就是載入mysql內建的庫與表##

cd /application/mysql/scripts./mysql_install_db --basedir=/application/mysql --datadir=/data/3306/data --user=mysql./mysql_install_db --basedir=/application/mysql/ --datadir=/data/3307/data --user=mysql##提示:--basedir=/application/mysql/為MySQL的安裝路徑,--datadir為資料檔案目錄。另,注意mysql_install_db和MySQL5.1的路徑不同,MySQL5.1不在MySQL bin路徑下了。

  編譯過程,注意要有2個OK 才算成功

[[email protected] scripts]# ./mysql_install_db --basedir=/application/mysql --datadir=/data/3306/data --user=mysqlWARNING: The host ‘db02‘ could not be looked up with resolveip.This probably means that your libc libraries are not 100 % compatiblewith this binary MySQL version. The MySQL daemon, mysqld, should worknormally with the exception that host name resolving will not work.This means that you should use IP addresses instead of hostnameswhen specifying MySQL privileges !Installing MySQL system tables...OK #<==兩個OK是初始化成功的標誌。Filling help tables...OK  #<==兩個OK是初始化成功的標誌。To start mysqld at boot time you have to copysupport-files/mysql.server to the right place for your systemPLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !To do so, start the server, then issue the following commands:/application/mysql/bin/mysqladmin -u root password ‘new-password‘/application/mysql/bin/mysqladmin -u root -h db02 password ‘new-password‘Alternatively you can run:/application/mysql/bin/mysql_secure_installationwhich will also give you the option of removing the testdatabases and anonymous user created by default.  This isstrongly recommended for production servers.See the manual for more instructions.You can start the MySQL daemon with:cd /application/mysql ; /application/mysql/bin/mysqld_safe &You can test the MySQL daemon with mysql-test-run.plcd /application/mysql/mysql-test ; perl mysql-test-run.plPlease report any problems with the /application/mysql/scripts/mysqlbug script!###請注意如下幾行英文的說明及報錯New default config file was createdas /application/mysql//my.cnf andwill be used by default by theserver when you start it.You may edit this file to changeserver settings#從上文說明中可以指導mysql的預設設定檔已經變到了/application/mysql//my.cnfWARNING: Default config file/etc/my.cnf exists on the systemThis file will be read by defaultby the MySQL serverIf you do not want to use this,either remove it, or use the--defaults-file argument tomysqld_safe when starting the server#從上文說明中可以看到資料庫啟動時會讀取/etc/my.cnf,因此有可能會導致無法啟動,避免的方法就是使用mysqld_safe啟動服務時採用--defaults-file參數指定設定檔,前文已將/etc/my.cnf改名了,所以,就不需要指定參數了,這裡是一個坑,讀者要注意。此步驟必須要初始化成功,否則,後面會出現登入不了資料庫等各種問題。[[email protected] ~]# mysqlERROR1045 (28000): Access denied for user ‘root‘@‘localhost‘ (using password: NO)解決辦法:重新初始化資料庫即可,此問題一般都是資料庫初始化問題,或者資料庫檔案損壞,以及目錄許可權問題

9,MySQL 初始化原理

初始化資料庫的就是載入MySQL內建的庫與表  例如:產生的test及mysql庫表等。

初始化資料庫後,查看資料目錄,產生哪些檔案

[[email protected] scripts]# ls -l /data/3306/data/total 143372-rw-rw---- 1 mysql mysql 134217728 Apr 29 03:32 ibdata1-rw-rw---- 1 mysql mysql   4194304 Apr 29 03:32 ib_logfile0-rw-rw---- 1 mysql mysql   4194304 Apr 29 03:32 ib_logfile1-rw-rw---- 1 mysql mysql   4194304 Apr 29 03:32 ib_logfile2drwx------ 2 mysql root       4096 Apr 29 03:31 mysql      ##用於存放管理mysql資料drwx------ 2 mysql mysql      4096 Apr 29 03:31 performance_schema #內部效能庫drwx------ 2 mysql root       4096 Apr 29 03:31 test       ##測試庫

10,啟動MySQL 命令 多執行個體(3306/3307)

[[email protected] scripts]# /data/3306/mysql start ##啟動指令碼見百度雲串連Starting MySQL...    [[email protected] scripts]# /data/3307/mysql startStarting MySQL...[[email protected] scripts]# ps -ef|grep 330root      13426      1  0 11:32 pts/1    00:00:00 /bin/sh /application/mysql/bin/mysqld_safe --defaults-file=/data/3306/my.cnfmysql     14150  13426  0 11:32 pts/1    00:00:05 /application/mysql-5.5.32/bin/mysqld --defaults-file=/data/3306/my.cnf --basedir=/application/mysql --datadir=/data/3306/data --plugin-dir=/application/mysql/lib/plugin --user=mysql --log-error=/data/3306/mysql_oldboy3306.err --open-files-limit=1024 --pid-file=/data/3306/mysqld.pid --socket=/data/3306/mysql.sock --port=3306root      17840      1  0 12:57 pts/1    00:00:00 /bin/sh /application/mysql/bin/mysqld_safe --defaults-file=/data/3307/my.cnfmysql     18540  17840 15 12:57 pts/1    00:00:01 /application/mysql-5.5.32/bin/mysqld --defaults-file=/data/3307/my.cnf --basedir=/application/mysql --datadir=/data/3307/data --plugin-dir=/application/mysql/lib/plugin --user=mysql --log-error=/data/3307/mysql_oldboy3307.err --open-files-limit=1024 --pid-file=/data/3307/mysqld.pid --socket=/data/3307/mysql.sock --port=3307root      18558   1286  0 12:57 pts/1    00:00:00 grep --color=auto 330##如果啟動失敗,請檢查日誌,路徑是在 每個執行個體下都有個err檔案,例如下面的3306[[email protected] scripts]# vi /data/3306/mysql_oldboy3306.err

11,串連MySQL資料庫( 以socket區分,多執行個體)

[[email protected] scripts]# mysql -uroot -p -S /data/3306/mysql.sock  #-S指定要啟動執行個體的socket-bash: mysql: command not found  #報錯是因為沒有設定環境變數解決方案的兩種思路: (建議使用第二種)1)將mysql 路徑添加到環境變數echo "PATH=$PATH:/application/mysql/bin/">>/etc/profilesource /etc/profilep2)將mysql 需要執行的檔案或指令碼,拷貝到第一個已經有環境變數許可權的目錄下,去執行。cp /application/mysql/bin/* /usr/local/sbin/再次串連,登入3306[[email protected] ~]# mysql -uroot -p -S /data/3306/mysql.sock [[email protected] ~]# mysql -uroot -p -S /data/3307/mysql.sockEnter password: Welcome to the MySQL monitor.  Commands end with ; or \g.Your MySQL connection id is 2Server version: 5.5.32-log Source distributionCopyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.mysql>

12,添加開機自啟動 (多執行個體 multi instances)

[[email protected] ~]# echo "# mysql multi instances" >>/etc/rc.local #添加註釋,及執行個體啟動項[[email protected] ~]# echo "/data/3306/mysql start " >>/etc/rc.local[[email protected] ~]# echo "/data/3307/mysql start " >>/etc/rc.loca

l

13,排錯總結

Mysql多執行個體啟動故障排錯說明

  1. 如果MySQL多執行個體有服務沒有被啟動,排除方法如下:

     如果發現沒有顯示MySQL對應的執行個體連接埠,請稍微等待幾秒在檢查,MySQL服務的啟動稍慢

     如果還是不行,請查看MySQL執行個體對應的錯誤記錄檔,路徑在my.cnf設定檔中最下面定義:

    例如:3306執行個體的錯誤記錄檔為:/data/3306/*.err

  2. 細看所有執行命令返回的螢幕輸出,不要忽略關鍵的輸出內容。

  3. 輔助查看系統日誌/var/log/messages

  4. 如果是MySQL關聯了其他服務,同時查看相關服務日誌

  5. 仔細閱讀,重新查看操作的步驟是否正確,書寫命令及字串是否正確。

  6. 多看日誌,多多總結,終究會稱為高手的。




本文出自 “逗哥筆記” 部落格,請務必保留此出處http://qiuyt.blog.51cto.com/1229789/1920687

CentOS 6.8 編譯安裝MySQL5.5.32 (二 多執行個體)

相關文章

聯繫我們

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