關於Linux系統的軟件安裝方法有不少種,目前經常使用是二進制安裝,rpm安裝,yum安裝,源代碼安裝,對這幾種安裝方法都有優勢和缺點,如今將這些安裝方法總結以下:node
二進制包:安裝簡單,能夠任意選擇購軟件版本,不須要編譯,直接初始化就好了mysql
rpm安裝:此安裝方法須要解決依賴包,能夠安裝指定軟件版本linux
yum安裝:只能安裝當前系統的軟件包,若是用網絡源必需要鏈接外網sql
源代碼:安裝比較複雜,也須要解決依賴問題,不過能夠指定須要的模塊和啓動某個功能數據庫
一.用rpm安裝指定的mysql數據庫vim
系統:Centos 6.5 64位網絡
軟件:MySQL-5.6.21 64位dom
[root@node1 ~]# wget http://mirrors.sohu.com/mysql/MySQL-5.6/MySQL-client-5.6.21-1.el6.x86_64.rpm --下載軟件包ide
[root@node1 ~]# wget http://mirrors.sohu.com/mysql/MySQL-5.6/MySQL-devel-5.6.21-1.el6.x86_64.rpmspa
[root@node1 ~]# wget http://mirrors.sohu.com/mysql/MySQL-5.6/MySQL-embedded-5.6.21-1.el6.x86_64.rpm
[root@node1 ~]# wget http://mirrors.sohu.com/mysql/MySQL-5.6/MySQL-server-5.6.21-1.el6.x86_64.rpm
[root@node1 ~]# wget http://mirrors.sohu.com/mysql/MySQL-5.6/MySQL-shared-5.6.21-1.el6.x86_64.rpm
[root@node1 ~]# wget http://mirrors.sohu.com/mysql/MySQL-5.6/MySQL-shared-compat-5.6.21-1.el6.x86_64.rpm
[root@node1 ~]# wget http://mirrors.sohu.com/mysql/MySQL-5.6/MySQL-test-5.6.21-1.el6.x86_64.rpm
[root@node1 ~]# yum localinstall MySQL-* -y --安裝mysql並解決包依賴問題
[root@node1 ~]# vim /root/.mysql_secret --查看mysql初始化密碼
# The random password set for the root user at Wed Nov 12 10:25:55 2014 (local time): _x4DfGXT2B8eBUW_ --紅色的是密碼,此密碼是動態的
[root@node1 ~]# /etc/init.d/mysql restart --啓動服務
Shutting down MySQL.. SUCCESS!
Starting MySQL.. SUCCESS!
[root@node1 ~]# mysql -u root -p --登錄並輸入初始密碼
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server 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 its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> select version(); --查看版本
+-----------+
| version() |
+-----------+
| 5.6.21 |
+-----------+
1 row in set (0.00 sec)
mysql>
二.二進制包安裝
1.下載和解壓mysql數據庫
[root@node1 ~]# wget http://mirrors.sohu.com/mysql/MySQL-5.7/mysql-5.7.4-m14-linux-glibc2.5-x86_64.tar.gz
[root@node1 ~]# tar -xvf mysql-5.7.4-m14-linux-glibc2.5-x86_64.tar.gz -C /usr/local/mysql-5.7.4
2.建立mysql用戶和修改軟件的權限
[root@node1 ~]# useradd -r -M -s /sbin/nologin mysql
[root@node1 ~]# chown -R mysql /usr/local/mysql-5.7.4
[root@node1 ~]# chgrp -R mysql /usr/local/mysql-5.7.4
3.安裝和初始化數據庫
[root@node1 ~]# cd /usr/local/mysql-5.7.4/
[root@node1 mysql-5.7.4]# scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql-5.7.4/ --datadir=/usr/local/mysql-5.7.4/data/ --必須在mysql根目錄安裝mysql,不然出錯
[root@node1 mysql-5.7.4]# cp -a ../support-files/my-default.cnf /etc/my.cnf
[root@node1 mysql-5.7.4]# cp -a ../support-files/mysql.server /etc/init.d/mysqld
[root@node1 mysql-5.7.4]# cd bin/
[root@node1 bin]# ./mysqld_safe --user=mysql &
[root@node1 bin]# chkconfig --add mysql
[root@node1 bin]# /etc/init.d/mysqld restart
Shutting down MySQL.. [ OK ]
Starting MySQL... [ OK ]
[root@node1 bin]#
三.用yum源安裝
[root@node2 ~]# mkdir /mnt/cdrom/
[root@node2 ~]# mount /dev/cdrom /mnt/cdrom/ --掛載光盤鏡像
[root@node2 ~]# yum repolist --更新yum倉庫
[root@node2 ~]# yum install mysql mysql-server mysql-devel mysql-utils -y --只能安裝系統自帶的軟件