在阿里云linux服务器上安装mysql_在阿里云Linux服务器上安装MySQL

http://www.blogjava.net/amigoxie/archive/2013/02/22/395605.html

在阿里云Linux服务器上安装MySQL

文/阿蜜果

日期/2013-2-221、申请阿里云Linux服务器

昨天在阿里云申请了一个免费试用5天的Linux云服务器。

操作系统:Red Hat Enterprise Linux Server 5.4 64位。

CPU:1核

内存:512M

硬盘空间:20G

带宽:1Mbps。

今天在这台云服务器上安装了基本环境(JDK、Tomcat和MySQL)。本文主要在阿里云Linux云服务器安装MySQL全过程,以及对安装时遇到的问题进行记录。2、下载MySQL服务器和客户端

访问MySQL的官网,进入其下载页面(http://dev.mysql.com/downloads/mysql/#downloads),选择MySQL Community Server,在“Select Platform”下拉框中选择“Oracle & Red Hat Linux 4 & 5”。

因为是64位的操作系统,所以选择下载如下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开发依赖包。

将这些rpm包通过FTP上传到Linux服务器的某个目录,例如:/root/software。

也可在Linux服务器上通过wget命令取得这些rpm包,Linux命令如下:3、安装MySQL服务器和客户端3.1安装MySQL服务器

下载完成后使用如下命令开始安装MySQL服务器:thread-1766546-1-1.htmlrpm-ivh MySQL-server-5.6.10-1.rhel5.x86_64.rpm

3.1.1安装依赖包libaio

在运行第一条安装MySQL服务器时会提示依赖包libaio.so.1没有安装,错误提示如下:thread-1766546-1-1.htmlerror: Failed dependencies:

thread-1766546-1-1.htmllibaio.so.1()(64bit) is needed by MySQL-server-5.6.10-1.rhel5.x86_64

thread-1766546-1-1.htmllibaio.so.1(LIBAIO_0.1)(64bit) is needed by MySQL-server-5.6.10-1.rhel5.x86_64

thread-1766546-1-1.htmllibaio.so.1(LIBAIO_0.4)(64bit) is needed by MySQL-server-5.6.10-1.rhel5.x86_64

需要使用yum命令快速安装依赖包libaio,运行如下命令:thread-1766546-1-1.htmlyum install libaio

运行该命令时会发现在这台云服务器上无法通过yum快速安装软件,搜索了一些资料,原来是阿里云安装的是Red Hat5.4的64位系统,但是提供的是CentOS 32位的系统。错误信息参考如下:thread-1766546-1-1.htmlSetting up Install Process

thread-1766546-1-1.htmlNopackagelibaio available.

thread-1766546-1-1.htmlNothing todo

网上找到的一个解决方案是将yum替换成CentOS的版本,我尝试了下是可行的。过程如下:

(1)通过rpm命令查看有哪些yum包,然后进行卸载

笔者在云服务器进行的操作如下:thread-1766546-1-1.html[root@AY130221101729bc93912 software]# rpm -qa|grep yum

thread-1766546-1-1.htmlyum-3.2.22-20.el5

thread-1766546-1-1.htmlyum-metadata-parser-1.1.2-3.el5

thread-1766546-1-1.html[root@AY130221101729bc93912 software]# rpm -e --nodeps yum-3.2.22-20.el5

thread-1766546-1-1.htmlwarning: /etc/yum.conf saved as /etc/yum.conf.rpmsave

thread-1766546-1-1.html[root@AY130221101729bc93912 software]# rpm -e --nodeps yum-metadata-parser-1.1.2-3.el5

(2)通过wget命令在163的镜像上下载CentOS的yum包

参考命令如下:

说明:可能版本会有一些不同,请大家在http://mirrors.163.com/centos/5/os/x86_64/CentOS/下查找yum-3xxx开头、yum-metadata开头和yum-fastestmirror开头的rpm包下载。

(3)安装yum相关的rpm包

使用如下命令安装在(2)中下载的rpm包:thread-1766546-1-1.htmlrpm-ivh yum-*

(4)下载CentOS-Base.repo

找一个CentOS的包资源配置库,名为CentOS-Base.repo,放到/etc/yum.repos.d/路径:thread-1766546-1-1.html[root@AY130221101729bc93912 software]# cd /etc/yum.repos.d/

thread-1766546-1-1.html[root@AY130221101729bc93912 yum.repos.d]# wget http://www.linuxidc.com/files/2011/05/06/CentOS-Base.repo

thread-1766546-1-1.html--2013-02-22 08:58:27-- http://www.linuxidc.com/files/2011/05/06/CentOS-Base.repo

thread-1766546-1-1.htmlResolving www.linuxidc.com

thread-1766546-1-1.html60.191.129.94

thread-1766546-1-1.htmlConnecting to www.linuxidc.com|60.191.129.94|:80

thread-1766546-1-1.htmlconnected.

thread-1766546-1-1.htmlHTTP request sent, awaiting response

thread-1766546-1-1.html200 OK

thread-1766546-1-1.htmlLength: 1426 (1.4K) [application/octet-stream]

thread-1766546-1-1.htmlSaving to: `CentOS-Base.repo'

thread-1766546-1-1.html

thread-1766546-1-1.html100%[==========================================================================================>] 1,426       --.-K/s   in 0s      

thread-1766546-1-1.html

thread-1766546-1-1.html2013-02-22 08:58:28 (124 MB/s) - `CentOS-Base.repo' saved [1426/1426]

(5)生成缓存文件到/var/cache/yum目录thread-1766546-1-1.html[root@AY130221101729bc93912 yum.repos.d]# yum makecache

thread-1766546-1-1.htmlLoaded plugins: fastestmirror

thread-1766546-1-1.htmlDetermining fastest mirrors

thread-1766546-1-1.htmladdons|1.9kB00:00thread-1766546-1-1.htmladdons/filelists_db|568B00:00thread-1766546-1-1.html

thread-1766546-1-1.htmladdons/other_db                                                                                   

thread-1766546-1-1.htmlbase   

thread-1766546-1-1.html……3641/3641thread-1766546-1-1.htmlbase3641/3641thread-1766546-1-1.htmlMetadata Cache Created

(6)安装依赖包libaio

第(5)步做完后,此时可以成功运行yum install libaio命令,参考执行情况如下:thread-1766546-1-1.html[root@AY130221101729bc93912 yum.repos.d]# yum install libaio

thread-1766546-1-1.htmlLoaded plugins: fastestmirror

thread-1766546-1-1.htmlLoading mirror speeds from cached hostfile

thread-1766546-1-1.htmlSetting up Install Process

thread-1766546-1-1.htmlResolving Dependencies

thread-1766546-1-1.html……

thread-1766546-1-1.htmlComplete

3.1.2安装MySQL Server的rpm包

依赖包安装完成后,可以执行rpm -ivh MySQL-server-5.6.10-1.rhel5.x86_64.rpm包安装MySQL的服务器端。参考执行情况如下(省略了部分内容):thread-1766546-1-1.html[root@AY130221101729bc93912 software]# rpm -ivh MySQL-server-5.6.10-1.rhel5.x86_64.rpm

thread-1766546-1-1.htmlPreparing

thread-1766546-1-1.html                ########################################### [100%]

thread-1766546-1-1.html  1:MySQL-server           ########################################### [100%]

thread-1766546-1-1.html2013-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).

thread-1766546-1-1.html…….

thread-1766546-1-1.htmlA random root password has been set. You will find it in '/root/.mysql_secret'.

thread-1766546-1-1.html2013-02-22 09:03:25 4132 [Note] Binlog end

thread-1766546-1-1.html2013-02-22 09:03:25 4132 [Note] InnoDB: FTS optimize thread exiting.

thread-1766546-1-1.html……

安装完成后会生成root用户的随机密码,请使用“cat /root/.mysql_secret”或类似命令进行查看。3.2安装MySQL客户端

服务端安装完成后,使用如下命令安装MySQL客户端,命令如下:thread-1766546-1-1.htmlrpm -ivh MySQL-client-5.5.28-1.rhel5.i386.rpm

3.3安装MySQL开发依赖包

接着安装MySQL-devel-5.5.28-1.rhel5.i386.rpm,命令如下:thread-1766546-1-1.htmlrpm -ivh MySQL-devel-5.5.28-1.rhel5.i386.rpm

3.4 MySQL的几个重要目录

(1)数据库目录

/var/lib/mysql/

(2)配置文件

/usr/share/mysql(mysql.server命令及配置文件)

(3)相关命令

/usr/bin(mysqladmin mysqldump等命令) (4)启动脚本

/etc/rc.d/init.d/(启动脚本文件mysql的目录)

若想查看MySQL安装到哪个目录,可使用“whereis mysql”命令查看,参考执行结果如下所示:

thread-1766546-1-1.html[root@AY130221101729bc93912 mysql]# whereis mysql

thread-1766546-1-1.htmlmysql: /usr/bin/mysql /usr/include/mysql /usr/share/mysql /usr/share/man/man1/mysql.1.gz

3.5启动MySQL

安装完成后mysql是没有启动的,运行mysql命令会提示如下错误:thread-1766546-1-1.html[root@AY130221101729bc93912 software]# mysql

thread-1766546-1-1.htmlERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)

可使用如下命令启动MySQL:thread-1766546-1-1.htmlservice mysql start

或者使用如下命令:thread-1766546-1-1.html/etc/init.d/mysql start

3.6登录MySQL

使用mysql命令登录MySQL服务器,运行MySQL的命令时,会提示需要设置root用户密码,提示信息如下:thread-1766546-1-1.html[root@AY130221101729bc93912 mysql]# mysql -u root -p

thread-1766546-1-1.htmlEnter password:

thread-1766546-1-1.htmlWelcome to the MySQL monitor. Commands end with ; or \g.

thread-1766546-1-1.htmlYour MySQL connection id is 5

thread-1766546-1-1.htmlServer version: 5.6.10

thread-1766546-1-1.html

thread-1766546-1-1.htmlCopyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.

thread-1766546-1-1.html

thread-1766546-1-1.htmlOracle is a registered trademark of Oracle Corporation and/or its

thread-1766546-1-1.htmlaffiliates. Other names may be trademarks of their respective

thread-1766546-1-1.htmlowners.

thread-1766546-1-1.html

thread-1766546-1-1.htmlType 'help;' or '\h' for help. Type '\c' to clear the current input statement.

thread-1766546-1-1.htmlmysql> show databases;

thread-1766546-1-1.htmlERROR 1820 (HY000): You must SET PASSWORD before executing this statement

可使用SET PASSWORD命令修改root用户的密码,参考如下:

thread-1766546-1-1.htmlmysql>SET PASSWORD=PASSWORD('root123456');

thread-1766546-1-1.htmlQuery OK,0rows affected (0.00sec)

thread-1766546-1-1.htmlmysql>show databases;

thread-1766546-1-1.html+--------------------+thread-1766546-1-1.html|Database|thread-1766546-1-1.html+--------------------+thread-1766546-1-1.html|information_schema|thread-1766546-1-1.html|mysql|thread-1766546-1-1.html|performance_schema|thread-1766546-1-1.html|test|thread-1766546-1-1.html+--------------------+

3.7设置开机自启动

设置开机自启动的方法有很多,例如使用chkconfig命令,另外也可以在/etc/rc.local文件中加上如下MySQL的启动命令,例如:thread-1766546-1-1.html/etc/init.d/mysql start

设置完成后重启系统,使用natstat –nat命令可看到MySQL的3306端口:

thread-1766546-1-1.htmlnetstat -nat

thread-1766546-1-1.htmlActive Internet connections (servers and established)

thread-1766546-1-1.htmlProto Recv-Q Send-Q Local Address               Foreign Address             State      

thread-1766546-1-1.htmltcp        0      0 127.0.0.1:8005              0.0.0.0:*                   LISTEN      

thread-1766546-1-1.htmltcp        0      0 0.0.0.0:8009                0.0.0.0:*                   LISTEN      

thread-1766546-1-1.htmltcp        0      0 0.0.0.0:3306                0.0.0.0:*                   LISTEN   

thread-1766546-1-1.html……

5、参考文档阿蜜果


版权声明:本文为weixin_42295528原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。