在阿里云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服务器:

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

Setting up Install Process

Nopackagelibaio available.

Nothing todo
某家网站提供了一个解决方案建议将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包
参考命令如下:
提示:可能会有不同的版本,请大家访问指定链接以获取以yum-3xxx开头、yum-metadata开头以及yum-fastestmirror开头的rpm包下载信息。
(3)安装yum相关的rpm包
使用如下命令安装在(2)中下载的rpm包:

rpm-ivh yum-*
(4)下载CentOS-Base.repo
请获取一个名为CentOS-Base.repo的 CentOS 包配置文件,并将其放置在/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.9kB00:00

addons/filelists_db|568B00:00


addons/other_db

base

……3641/3641

base3641/3641

Metadata Cache Created
(6)安装依赖包libaio
完成第(5)项步骤后, 此时将能够正确地执行yum install libaio命令; 具体操作步骤可参考以下内容.

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

[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] 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).

…….

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开发依赖包
接着安装MySQL-devel-5.5.28-1.rhel5.i386.rpm,命令如下:

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"命令进行查询,并参考执行结果。

[root@AY130221101729bc93912 mysql]# whereis mysql

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命令会提示如下错误:

[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服务器的过程中(或时),将提示您需要配置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,0rows affected (0.00sec)

mysql>show databases;

+--------------------+

|Database|

+--------------------+

|information_schema|

|mysql|

|performance_schema|

|test|

+--------------------+
3.7设置开机自启动
多种方法可实现开机自动启动配置。其中一种方法是使用 chkconfig 命令;此外还可以在 /etc/rc.local 文件中添加 MySQL 启动命令。

/etc/init.d/mysql start
设置完成后重启系统,使用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、参考文档阿蜜果
