Advertisement

在阿里云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数据库进行了全面的部署操作,并详细记录了整个过程中的常见问题及其解决方案。第二步:获取并下载MySQL数据库服务及其客户端软件。

访问MySQL官方网站(http://dev.mysql.com/downloads/mysql/#downloads),下载MySQL Community Server版本,并从提供的平台选项中选择适用于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服务器上指定的某个特定目录中,并如图所示,在软件根目录下。

同样可以在Linux服务器上使用apt update -y命令更新所有依赖项后,在终端输入apt install mysql:mysql-client完成整个过程

下载完成后使用如下命令开始安装MySQL服务器:

thread-1766546-1-1.html

rpm-ivh MySQL-server-5.6.10-1.rhel5.x86_64.rpm

3.1.1安装依赖包libaio

当尝试执行第一条安装MySQL服务器的命令时,系统会报错,并显示缺少指定的动态链接库libaio.so.1。

thread-1766546-1-1.html

error: Failed dependencies:

thread-1766546-1-1.html

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

thread-1766546-1-1.html

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

thread-1766546-1-1.html

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

需要使用yum命令快速安装依赖包libaio,运行如下命令:

thread-1766546-1-1.html

yum install libaio

在执行该命令时发现,在这台云服务器上无法迅速通过yum安装软件。经过查阅资料后了解到:原来阿里云配置的是Red Hat Enterprise Linux 5.4 64-bit操作系统,并非预期中的CentOS 32-bit操作系统。错误信息如下所示:

thread-1766546-1-1.html

Setting up Install Process

thread-1766546-1-1.html

Nopackagelibaio available.

thread-1766546-1-1.html

Nothing todo

某家网站提供了一个解决方案建议将yum替换成 CentOS 官方版本 具体操作步骤如下 首先下载对应的官方镜像文件并解压至指定目录 经过测试发现该方法非常有效

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

笔者在云服务器进行的操作如下:

thread-1766546-1-1.html

[root@AY130221101729bc93912 software]# rpm -qa|grep yum

thread-1766546-1-1.html

yum-3.2.22-20.el5

thread-1766546-1-1.html

yum-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.html

warning: /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包

参考命令如下:

提示:可能会有不同的版本,请大家访问指定链接以获取以yum-3xxx开头、yum-metadata开头以及yum-fastestmirror开头的rpm包下载信息。

(3)安装yum相关的rpm包

使用如下命令安装在(2)中下载的rpm包:

thread-1766546-1-1.html

rpm-ivh yum-*

(4)下载CentOS-Base.repo

请获取一个名为CentOS-Base.repo的 CentOS 包配置文件,并将其放置在/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.html

Resolving www.linuxidc.com

thread-1766546-1-1.html

60.191.129.94

thread-1766546-1-1.html

Connecting to www.linuxidc.com|60.191.129.94|:80

thread-1766546-1-1.html

connected.

thread-1766546-1-1.html

HTTP request sent, awaiting response

thread-1766546-1-1.html

200 OK

thread-1766546-1-1.html

Length: 1426 (1.4K) [application/octet-stream]

thread-1766546-1-1.html

Saving to: `CentOS-Base.repo'

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

100%[==========================================================================================>] 1,426 --.-K/s in 0s

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

2013-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.html

Loaded plugins: fastestmirror

thread-1766546-1-1.html

Determining fastest mirrors

thread-1766546-1-1.html

addons|1.9kB00:00

thread-1766546-1-1.html

addons/filelists_db|568B00:00

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

addons/other_db

thread-1766546-1-1.html

base

thread-1766546-1-1.html

……3641/3641

thread-1766546-1-1.html

base3641/3641

thread-1766546-1-1.html

Metadata 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.html

Loaded plugins: fastestmirror

thread-1766546-1-1.html

Loading mirror speeds from cached hostfile

thread-1766546-1-1.html

Setting up Install Process

thread-1766546-1-1.html

Resolving Dependencies

thread-1766546-1-1.html

……

thread-1766546-1-1.html

Complete

3.1.2安装MySQL Server的rpm包

在完成所有依赖包的安装后,可以通过运行rpm命令rpm -ivh MySQL-server-5.6.10-1.rhel5.x86_64.rpm来为MySQL服务安装一个rpm包。查看安装过程中的具体情况。

thread-1766546-1-1.html

[root@AY130221101729bc93912 software]# rpm -ivh MySQL-server-5.6.10-1.rhel5.x86_64.rpm

thread-1766546-1-1.html

Preparing

thread-1766546-1-1.html

########################################### [100%]

thread-1766546-1-1.html

1:MySQL-server ########################################### [100%]

thread-1766546-1-1.html

2013-02-22 09:03:18 0 [Warning] Using a TIMESTAMP with an implicit DEFAULT value is no longer recommended. It is suggested that you employ the --explicit_defaults_for_timestamp server option (for further information, consult the documentation).

thread-1766546-1-1.html

…….

thread-1766546-1-1.html

A random root password has been set. You will find it in '/root/.mysql_secret'.

thread-1766546-1-1.html

2013-02-22 09:03:25 4132 [Note] Binlog end

thread-1766546-1-1.html

2013-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.html

rpm -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.html

rpm -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安装的具体位置,请使用"mysql whereis"命令进行查询,并参考执行结果。

thread-1766546-1-1.html

[root@AY130221101729bc93912 mysql]# whereis mysql

thread-1766546-1-1.html

MySQL: Binary version of MySQL, including header files, in the MySQL shared library directory, and the man page of MySQL version 1 in gzipped format.

3.5启动MySQL

安装完成后mysql是没有启动的,运行mysql命令会提示如下错误:

thread-1766546-1-1.html

[root@AY130221101729bc93912 software]# mysql

thread-1766546-1-1.html

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)

可使用如下命令启动MySQL:

thread-1766546-1-1.html

service mysql start

或者使用如下命令:

thread-1766546-1-1.html

/etc/init.d/mysql start

3.6登录MySQL

通过mysql命令执行操作,在登录到MySQL服务器的过程中(或时),将提示您需要配置root用户的密码。

thread-1766546-1-1.html

[root@AY130221101729bc93912 mysql]# mysql -u root -p

thread-1766546-1-1.html

Enter password:

thread-1766546-1-1.html

Welcome to the MySQL monitor. Commands end with ; or \g.

thread-1766546-1-1.html

Your MySQL connection id is 5

thread-1766546-1-1.html

Server version: 5.6.10

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

Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.

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

Oracle is a registered trademark of Oracle Corporation and/or its

thread-1766546-1-1.html

affiliates. Other names may be trademarks of their respective

thread-1766546-1-1.html

owners.

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

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

thread-1766546-1-1.html

mysql> show databases;

thread-1766546-1-1.html

ERROR 1820 (HY000): You must SET PASSWORD before executing this statement

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

thread-1766546-1-1.html

mysql>SET PASSWORD=PASSWORD('root123456');

thread-1766546-1-1.html

Query OK,0rows affected (0.00sec)

thread-1766546-1-1.html

mysql>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.html

netstat -nat

thread-1766546-1-1.html

Active Internet connections (servers and established)

thread-1766546-1-1.html

Proto Recv-Q Send-Q Local Address Foreign Address State

thread-1766546-1-1.html

tcp 0 0 127.0.0.1:8005 0.0.0.0:* LISTEN

thread-1766546-1-1.html

tcp 0 0 0.0.0.0:8009 0.0.0.0:* LISTEN

thread-1766546-1-1.html

tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN

thread-1766546-1-1.html

……

5、参考文档阿蜜果

全部评论 (0)

还没有任何评论哟~