- 論壇徽章:
- 0
|
http://www.blogjava.net/amigoxie/archive/2013/02/22/395605.html
文/阿蜜果
日期/2013-2-22
1、申請阿里云Linux服務器
昨天在阿里云申請了一個免費試用5天的Linux云服務器。
操作系統(tǒng):Red Hat Enterprise Linux Server 5.4 64位。
CPU:1核
內(nèi)存:512M
硬盤空間:20G
帶寬:1Mbps。
今天在這臺云服務器上安裝了基本環(huán)境(JDK、Tomcat和MySQL)。本文主要在阿里云Linux云服務器安裝MySQL全過程,以及對安裝時遇到的問題進行記錄。
2、下載MySQL服務器和客戶端
訪問MySQL的官網(wǎng),進入其下載頁面(http://dev.mysql.com/downloads/mysql/#downloads),選擇MySQL Community Server,在“Select Platform”下拉框中選擇“Oracle & Red Hat Linux 4 & 5”。
因為是64位的操作系統(tǒng),所以選擇下載如下rpm包:
(1)MySQL-server-5.6.10-1.rhel5.x86_64.rpm:MySQL服務器;
(2)MySQL-client-5.6.10-1.rhel5.x86_64.rpm:MySQL客戶端;
(3)MySQL-devel-5.6.10-1.rhel5.x86_64.rpm:Mysql開發(fā)依賴包。
將這些rpm包通過FTP上傳到Linux服務器的某個目錄,例如:/root/software。
也可在Linux服務器上通過wget命令取得這些rpm包,Linux命令如下:
wget –c http://dev.mysql.com/get/Downloa ... ttp://cdn.mysql.com
wget –c http://dev.mysql.com/get/Downloa ... ttp://cdn.mysql.com
wget –c http://dev.mysql.com/get/Downloa ... http://cdn.mysql.co
3、安裝MySQL服務器和客戶端
3.1 安裝MySQL服務器
下載完成后使用如下命令開始安裝MySQL服務器:
rpm -ivh MySQL-server-5.6.10-1.rhel5.x86_64.rpm
3.1.1 安裝依賴包libaio在運行第一條安裝MySQL服務器時會提示依賴包libaio.so.1沒有安裝,錯誤提示如下:
error: Failed dependencies:
libaio.so.1()(64bit) is needed by MySQL-server-5.6.10-1.rhel5.x86_64
libaio.so.1(LIBAIO_0.1)(64bit) is needed by MySQL-server-5.6.10-1.rhel5.x86_64
libaio.so.1(LIBAIO_0.4)(64bit) is needed by MySQL-server-5.6.10-1.rhel5.x86_64
需要使用yum命令快速安裝依賴包libaio,運行如下命令:
yum install libaio
運行該命令時會發(fā)現(xiàn)在這臺云服務器上無法通過yum快速安裝軟件,搜索了一些資料,原來是阿里云安裝的是Red Hat5.4的64位系統(tǒng),但是提供的是CentOS 32位的系統(tǒng)。錯誤信息參考如下:
Setting up Install Process
No package libaio available.
Nothing to do
網(wǎng)上找到的一個解決方案是將yum替換成CentOS的版本,我嘗試了下是可行的。過程如下:
(1)通過rpm命令查看有哪些yum包,然后進行卸載
筆者在云服務器進行的操作如下:
[root@AY130221101729bc93912 software]# rpm -qa|grep yum
yum-3.2.22-20.el5
yum-metadata-parser-1.1.2-3.el5
[root@AY130221101729bc93912 software]# rpm -e --nodeps yum-3.2.22-20.el5
warning: /etc/yum.conf saved as /etc/yum.conf.rpmsave
[root@AY130221101729bc93912 software]# rpm -e --nodeps yum-metadata-parser-1.1.2-3.el5
(2)通過wget命令在163的鏡像上下載CentOS的yum包
參考命令如下:
wget http://mirrors.163.com/centos/5/ ... 5.centos.noarch.rpm
wget http://mirrors.163.com/centos/5/ ... .2-4.el5.x86_64.rpm
wget http://mirrors.163.com/centos/5/ ... 5.centos.noarch.rpm
說明:可能版本會有一些不同,請大家在http://mirrors.163.com/centos/5/os/x86_64/CentOS/下查找yum-3xxx開頭、yum-metadata開頭和yum-fastestmirror開頭的rpm包下載。
(3)安裝yum相關的rpm包
使用如下命令安裝在(2)中下載的rpm包:
rpm -ivh yum-*
(4)下載CentOS-Base.repo
找一個CentOS的包資源配置庫,名為CentOS-Base.repo,放到/etc/yum.repos.d/路徑:
[root@AY130221101729bc93912 software]# cd /etc/yum.repos.d/
[root@AY130221101729bc93912 yum.repos.d]# wget http://www.linuxidc.com/files/2011/05/06/CentOS-Base.repo
--2013-02-22 08:58:27-- http://www.linuxidc.com/files/2011/05/06/CentOS-Base.repo
Resolving www.linuxidc.com 60.191.129.94
Connecting to www.linuxidc.com|60.191.129.94|:80 connected.
HTTP request sent, awaiting response 200 OK
Length: 1426 (1.4K) [application/octet-stream]
Saving to: `CentOS-Base.repo'
100%[==========================================================================================>] 1,426 --.-K/s in 0s
2013-02-22 08:58:28 (124 MB/s) - `CentOS-Base.repo' saved [1426/1426]
(5)生成緩存文件到/var/cache/yum目錄
[root@AY130221101729bc93912 yum.repos.d]# yum makecache
Loaded plugins: fastestmirror
Determining fastest mirrors
addons | 1.9 kB 00:00
addons/filelists_db | 568 B 00:00
addons/other_db
base
…… 3641/3641
base 3641/3641
Metadata Cache Created<p align="justify"></p>
(6)安裝依賴包libaio
第(5)步做完后,此時可以成功運行yum install libaio命令,參考執(zhí)行情況如下:
[root@AY130221101729bc93912 yum.repos.d]# yum install libaio
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Setting up Install Process
Resolving Dependencies
……
Complete
3.1.2 安裝MySQL Server的rpm包 依賴包安裝完成后,可以執(zhí)行rpm -ivh MySQL-server-5.6.10-1.rhel5.x86_64.rpm包安裝MySQL的服務器端。參考執(zhí)行情況如下(省略了部分內(nèi)容):
[root@AY130221101729bc93912 software]# rpm -ivh MySQL-server-5.6.10-1.rhel5.x86_64.rpm
Preparing ########################################### [100%]
1:MySQL-server ########################################### [100%]
2013-02-22 09:03:18 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
…….
A random root password has been set. You will find it in '/root/.mysql_secret'.
2013-02-22 09:03:25 4132 [Note] Binlog end
2013-02-22 09:03:25 4132 [Note] InnoDB: FTS optimize thread exiting.
……
安裝完成后會生成root用戶的隨機密碼,請使用“cat /root/.mysql_secret”或類似命令進行查看。
3.2 安裝MySQL客戶端
服務端安裝完成后,使用如下命令安裝MySQL客戶端,命令如下:
rpm -ivh MySQL-client-5.5.28-1.rhel5.i386.rpm
3.3 安裝MySQL開發(fā)依賴包
接著安裝MySQL-devel-5.5.28-1.rhel5.i386.rpm,命令如下:
rpm -ivh MySQL-devel-5.5.28-1.rhel5.i386.rpm
3.4 MySQL的幾個重要目錄
(1)數(shù)據(jù)庫目錄
/var/lib/mysql/
(2)配置文件
/usr/share/mysql(mysql.server命令及配置文件)
(3)相關命令
/usr/bin(mysqladmin mysqldump等命令)
(4)啟動腳本
/etc/rc.d/init.d/(啟動腳本文件mysql的目錄)
若想查看MySQL安裝到哪個目錄,可使用“whereis mysql”命令查看,參考執(zhí)行結果如下所示:
[root@AY130221101729bc93912 mysql]# whereis mysql
mysql: /usr/bin/mysql /usr/include/mysql /usr/share/mysql /usr/share/man/man1/mysql.1.gz
3.5 啟動MySQL
安裝完成后mysql是沒有啟動的,運行mysql命令會提示如下錯誤:
[root@AY130221101729bc93912 software]# mysql
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
可使用如下命令啟動MySQL:
service mysql start
或者使用如下命令:
/etc/init.d/mysql start
3.6 登錄MySQL
使用mysql命令登錄MySQL服務器,運行MySQL的命令時,會提示需要設置root用戶密碼,提示信息如下:
[root@AY130221101729bc93912 mysql]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.6.10
Copyright (c) 2000, 2013, 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> show databases;
ERROR 1820 (HY000): You must SET PASSWORD before executing this statement
可使用SET PASSWORD命令修改root用戶的密碼,參考如下:
mysql> SET PASSWORD = PASSWORD('root123456');
Query OK, 0 rows affected (0.00 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
3.7 設置開機自啟動
設置開機自啟動的方法有很多,例如使用chkconfig命令,另外也可以在/etc/rc.local文件中加上如下MySQL的啟動命令,例如:
/etc/init.d/mysql start
設置完成后重啟系統(tǒng),使用natstat –nat命令可看到MySQL的3306端口:
netstat -nat
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 127.0.0.1:8005 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:8009 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN
……
5、參考文檔
(1)《在Linux下安裝和使用MySQL》:http://www.yesky.com/187/1754687.shtml
(2)《CentOS下以RPM方式安裝MySQL5.5》:http://blog.seweal.com/post/centos-mysql-install-rpm
(3)《Redhat Linux無法使用yum快速安裝軟件解決方案》:
http://www.2cto.com/os/201112/113105.html
(4)CentOS的一些rpm包的鏡像下載路徑:http://mirrors.163.com/centos/5/os/x86_64/CentOS/
(5)MySQL的Server和Client端的下載路徑:http://dev.mysql.com/downloads/mysql/#downloads
posted on 2013-02-22 18:23 阿蜜果 |
|