Mysql 安裝(Using Generic Binaries)

來源:互聯網
上載者:User

標籤:blog   http   io   ar   os   使用   sp   for   strong   

本次 Mysql 為Community 5.6.21 版本,安裝方式為通用Linux安裝方式,即大多數Linux平台都可以採用該方式進行安裝。

一、安裝步驟

1、安裝環境

1)Centos 7.0.1406 X86_64

2、下載 Mysql 、解壓縮、建立軟串連,與官方提供解壓縮路徑有些許。

$ wget http://cdn.mysql.com/Downloads/MySQL-5.6/mysql-5.6.21-linux-glibc2.5-x86_64.tar.gz$ sudo tar zxvf mysql-5.6.21-linux-glibc2.5-x86_64.tar.gz -C /usr/local/src/$ sudo ln -s /usr/local/src/mysql-5.6.21-linux-glibc2.5-x86_64/ /usr/local/mysql

3、安裝方式分為兩種。

方式1 參考 Mysql 官方指導建議進行安裝,多用在Mysql學習環境,下列命令來源Mysql官方,原文參見 Installing MySQL on Unix/Linux Using Generic Binaries

shell> groupadd mysqlshell> useradd -r -g mysql mysqlshell> cd /usr/localshell> tar zxvf /path/to/mysql-VERSION-OS.tar.gzshell> ln -s full-path-to-mysql-VERSION-OS mysqlshell> cd mysqlshell> chown -R mysql .shell> chgrp -R mysql .shell> scripts/mysql_install_db --user=mysqlshell> chown -R root .shell> chown -R mysql datashell> bin/mysqld_safe --user=mysql &# Next command is optionalshell> cp support-files/mysql.server /etc/init.d/mysql.server

方式2 自訂 Mysql 資料儲存路徑,多用在部署環境。

1)建立Mysql使用者以及使用者組

$ sudo groupadd mysql$ sudo useradd -r -g mysql mysql$ cd /usr/local/src/$ sudo chown -R mysql:mysql mysql-5.6.21-linux-glibc2.5-x86_64/ #定義mysql使用者以及組$ ll總用量 4drwxr-xr-x. 13 mysql mysql 4096 11月  5 08:10 mysql-5.6.21-linux-glibc2.5-x86_64

2)建立Mysql資料檔案儲存位置,若使用資料盤則自行掛載。

$ sudo mkdir -p /data/mysql #定義mysql資料檔案儲存地址

3)初始化 Mysql,可能會出現的問題參見文章底部問題處理方法

$ sudo /usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/data/mysql/ #初始化 mysql

4)配置 my.cnf

$ sudo vi /usr/local/mysql/my.cnf 

本樣本僅保證可以正常運行,所以配置如下三項即可。

  basedir = /usr/local/mysql  datadir = /data/mysql  port = 3306

建立軟串連 my.cnf 到 /etc/ 目錄

$ sudo ln -s /usr/local/mysql/my.cnf /etc/my.cnf

5)啟動 Mysql 服務

$ sudo /usr/local/mysql/support-files/mysql.server startStarting MySQL. SUCCESS! 

6)登陸 Mysql

$ /usr/local/mysql/bin/mysqlWelcome to the MySQL monitor.  Commands end with ; or \g.Your MySQL connection id is 1Server version: 5.6.21 MySQL Community Server (GPL)Copyright (c) 2000, 2014, 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> 

二、開機啟動

$ sudo chkconfig --add mysqld

三、環境變數

1)編輯 profile 檔案

$ sudo vi /etc/profile

2)添加下列資訊到 profile 底部

export PATH=$PATH:/usr/local/mysql/bin

3)立即生效設定檔

$ source /etc/profile

四、Mysql遠端連線

mysql> select user();+----------------+| user()         |+----------------+| [email protected] |+----------------+1 row in set (0.01 sec)mysql> grant all privileges  on *.* to [email protected]'%' identified by "你的密碼";Query OK, 0 rows affected (0.00 sec)mysql> flush privileges;Query OK, 0 rows affected (0.00 sec)

五、防火牆開啟

Centos 7 預設啟用 firewall 管理連接埠

1)查看連接埠開啟情況,若之前沒有配過會顯示 no 說明 3306 連接埠未開放,反之 yes 說明已開放直接可用 Mysql 用戶端遠端存取!

$ sudo firewall-cmd --query-port=3306/tcpno

2)臨時性開啟 3306 連接埠

$ sudo firewall-cmd --add-port=3306/tcpsuccess

3)永久性開啟 3306 連接埠

$ sudo firewall-cmd --permanent --zone=public --add-port=3306/tcpsuccess$ sudo firewall-cmd --reload #重新載入配置success[[email protected] ~]$ sudo firewall-cmd --zone=public --list-all #查看添加結果public (default, active)  interfaces: eth0  sources:   services: dhcpv6-client ssh  ports: 3306/tcp 22/tcp  masquerade: no  forward-ports:   icmp-blocks:   rich rules: 

六、問題整理

問題1:

$ sudo scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/data/mysql/sudo: unable to execute scripts/mysql_install_db: No such file or directory

解決:解決這個問題純屬巧合,去掉 sudo 提示 Perl 解析器有問題,重新安裝下

$ sudo yum install perl$ sudo yum install perl-Data-Dumper.x86_64

問題2:

$ sudo scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/data/mysql/Installing MySQL system tables.../usr/local/mysql//bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory

解決:

$ sudo yum install libaio.x86_64

問題3:

$ sudo support-files/mysql.server startStarting MySQL. ERROR! The server quit without updating PID file (/data/mysql/localhost.localdomain.pid).
解決:這個問題特別實在初次開機時會提示,簡單說就是找不到 my.cnf 檔案,將配置完畢 my.cnf 複製到 /etc/  或 建立軟串連到 /etc/ 目錄下!

$ sudo cp my.cnf /etc/
這裡我有點疑惑,表面現象 mysql 啟動依賴 /etc/my.cnf 檔案,但實際第一次正常啟動 mysql 後可以刪除 /etc/my.cnf 檔案,第二次啟動可以正常載入 /usr/local/mysql/my.cnf 檔案!


參考文章:

Centos7 安裝Mysql 5.6.19

CentOS 7.0編譯安裝Nginx1.6.0+MySQL5.6.19+PHP5.5.14方法分享

RHEL7中防火牆firewalld的配置(1)

Mysql 安裝(Using Generic Binaries)

聯繫我們

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