Mysql 安裝(Using Generic Binaries),genericbinaries

來源:互聯網
上載者:User

Mysql 安裝(Using Generic Binaries),genericbinaries

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

一、安裝步驟

1、安裝環境

1)Centos 7.0.1406 X86_64 或 Centos 6.5 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()         |+----------------+| root@localhost |+----------------+1 row in set (0.01 sec)mysql> grant all privileges  on *.* to root@'%' identified by "你的密碼";Query OK, 0 rows affected (0.00 sec)mysql> flush privileges;Query OK, 0 rows affected (0.00 sec)

五、防火牆開啟

Centos 6.5 預設啟用 iptables 管理連接埠

編輯 iptables 檔案

$ sudo vim /etc/sysconfig/iptables
添加 3306 連接埠規則,注意第11行 3306 連接埠規則
# Firewall configuration written by system-config-firewall# Manual customization of this file is not recommended.*filter:INPUT ACCEPT [0:0]:FORWARD ACCEPT [0:0]:OUTPUT ACCEPT [0:0]-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT-A INPUT -p icmp -j ACCEPT-A INPUT -i lo -j ACCEPT-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT-A INPUT -j REJECT --reject-with icmp-host-prohibited-A FORWARD -j REJECT --reject-with icmp-host-prohibitedCOMMIT
重啟 iptables 服務就可以遠端連線了。
$ sudo service iptables restartiptables:將鏈設定為政策 ACCEPT:filter                    [確定]iptables:清除防火牆規則:                                 [確定]iptables:正在卸載模組:                                   [確定]iptables:應用防火牆規則:                                 [確定]

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[john@localhost ~]$ 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 檔案!


轉載請註明出處:http://blog.csdn.net/johnnycode/article/details/40783553


參考文章:

Centos7 安裝Mysql 5.6.19

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

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

相關文章

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.