---
title: "ubuntu下安装配置mysql(Version: '5.6.24')"
author: "stephen830"
date: "2015-05-05T15:45:05Z"
tags: []
categories: ["数据库"]
slug: "ubuntu-mysql-version-5-6-24"
draft: false
lastmod: "2015-05-06T12:17:05Z"
id: 2208605
url: "https://stephen830.iteye.com/blog/2208605"
---

**ubuntu下安装配置mysql(Version: '5.6.24')**

 

 

**mysql(Version: '5.6.24')下载地址** http://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.24-linux-glibc2.5-x86\_64.tar.gz

 

官方安装［mysql5.6版本］说明：  http://dev.mysql.com/doc/refman/5.6/en/binary-installation.html

 

**1.下载mysql安装文件**

去mysql官网：  http://dev.mysql.com/downloads/mysql/

 

# Download MySQL Community Server

MySQL open source software is provided under the [GPL License](http://www.gnu.org/licenses/old-licenses/gpl-2.0.html).

OEMs, ISVs and VARs can purchase commercial licenses.

MySQL Community Edition is a freely downloadable version of the world's most popular open source database that is supported by an active community of open source developers and enthusiasts.

[MySQL Cluster Community Edition](http://dev.mysql.com/downloads/cluster/) is available as a separate download. The reason for this change is so that MySQL Cluster can provide more frequent updates and support using the latest sources of MySQL Cluster Carrier Grade Edition.

# MySQL Community Server 这是免费的，因此下载这个类型。

![](http://dl2.iteye.com/upload/attachment/0108/3410/07bf8a09-cd0a-32c7-91fd-640545b989de.png)  
 

在 select platform 中选择 Linux-Generic

![](http://dl2.iteye.com/upload/attachment/0108/3412/2405059c-8644-300e-b589-93e930e412ba.png)  
 选择下载的包:  Linux - Generic (glibc 2.5) (x86, 64-bit), Compressed TAR Archive

我这里选择的是64位的包，请根据自己的实际情况选择。

 

 **2.解压下载得到的安装包(mysql-\*.tar.gz)**

因为mysql默认的安装目录在**/usr/local/**目录中，因此将安装包复制到/usr/local/目录下，然后执行

```
cp mysql-5.6.24-linux-glibc2.5-x86_64.tar.gz /usr/local/
cd /usr/local
tar -zxvf mysql-5.6.24-linux-glibc2.5-x86_64.tar.gz
```

 解压后得到mysql的目录 /usr/local/**mysql-5.6.24-linux-glibc2.5-x86\_64**

 目录名称比较长，因此创建一个软连接

```
cd /usr/local
ln -s mysql-5.6.24-linux-glibc2.5-x86_64 mysql
```

 **/usr/local/mysql** 实际指向的就是 **/usr/local/mysql-5.6.24-linux-glibc2.5-x86\_64**

 

 mysql目录结构如下表：  
![](http://dl2.iteye.com/upload/attachment/0108/3416/6611327c-eb2e-3220-9508-03b84cdbfaab.png)  
 

**3.安装mysql依赖库libaio**

`mysql安装需要libaio` library，因此必须先安装libaio类库。

ubuntu服务器上执行下面命令来安装libaoio：

```
apt-get install libaio1
```

 

**4.配置mysql**

```
shell> groupadd mysql
shell> useradd -r -g mysql mysql
shell> cd /usr/local
shell> cd mysql
shell> chown -R mysql .
shell> chgrp -R mysql .
shell> scripts/mysql_install_db --user=mysql
shell> chown -R root .
shell> chown -R mysql data
shell> bin/mysqld_safe --user=mysql &
```

 执行 ps aux|grep mysql 命令，可以看到mysql的数据库目录为 **/usr/local/mysql/data**  
![](http://dl2.iteye.com/upload/attachment/0108/3454/ec606a15-89e5-381a-a56f-1093ef1c6f9c.png)  
 

 

 

**5.配置mysql启动服务**

```
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql.server
```

停止mysql命令 service mysql.server stop

启动mysql命令 service mysql.server start

 

**6.设置mysql参数（root密码、删除测试test库、）**

```
service mysql.server start
/usr/local/mysql/bin/mysql_secure_installation
```

 根据提示进行mysql参数的设置。

```
Enter current password for root (enter for none):
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.

Set root password? [Y/n] y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
... Success!

By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] y
... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] y
... Success!

By default, MySQL comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] y
- Dropping test database...
... Success!
- Removing privileges on test database...
... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] y
... Success! 
```

 

 

 

也可以使用下面命令来设置root密码

```
/usr/local/mysql/bin/mysqladmin -u root password 'new-password'
```

**7.配置mysql字符编码为utf-8**

在修改前，先查看下当前的字符编码，登入mysql

执行命令

```
show variables like '%char%';
```

 如下图结果，可以看到有lat1的字符编码。  
![](http://dl2.iteye.com/upload/attachment/0108/3456/0a00e98e-ca50-329e-b822-56ca81d5b2eb.png)  
 

修改/usr/local/mysql/my.cnf文件

如下图，在\[mysqld]节点下增加3行配置参数：

skip-character-set-client-handshake  
character\_set\_client=utf8  
character\_set\_server=utf8  
![](http://dl2.iteye.com/upload/attachment/0108/3427/51c81f56-2b0b-3c17-a1fd-9bad5cfd5826.png)  
保存修改，然后重启mysql。

登入mysql，执行命令：**/usr/local/mysql/bin/mysql -uroot -p密码**

查看mysql的字符编码，执行命令：

```
show variables like '%char%';
```

 如果都显示utf8，那么表示字符编码已经全部调整为utf8，如果看到lat1，则表示编码不全是utf8。  
![](http://dl2.iteye.com/upload/attachment/0108/3429/622335c7-e117-3b79-bc4b-09325b80be21.png)  
 

 **8.更改mysql存放数据库的目录/usr/local/mysql/data**

 这里将**/usr/local/mysql/data**目录更改到**/data/mysql/data**

```
service mysql.server stop
mkdir /data/mysql
cd /data
chown -R mysql mysql
chgrp -R mysql mysql
cd /data/mysql
mv /usr/local/mysql/data .
```

 修改/usr/local/mysql/my.cnf文件

如下图，在\[mysqld]节点下增加配置参数：

datadir = /data/mysql/data  
![](http://dl2.iteye.com/upload/attachment/0108/3444/695a3e66-75ef-3e22-a339-8dc2c0edf0f1.png)  
 保存修改，然后重启mysql

 

 

**9. 查看mysql的日志**

查看日志命令 cat /data/mysql/data/xxx.err （注意xxx用自己的日志文件名来替换）

 

**9.1 \[Note] Plugin 'FEDERATED' is disabled.**

解决方法：在my.cnf中的mysqld节点下增加一行参数

```
federated
```

 如下图，然后重启mysql，问题就可以解决。  
![](http://dl2.iteye.com/upload/attachment/0108/3465/74b4416b-aae7-36e9-a674-8e82499838a8.png)  
   
**9.2 \[Warning] Using unique option prefix character\_set\_client instead of character-set-client-handshake is deprecated and will be removed in a future release. Please use the full name instead.** **\[Warning] /usr/local/mysql/bin/mysqld: ignoring option '--character-set-client-handshake' due to invalid value 'utf8'**  
 解决方法：修改my.cnf配置文件

新增节点\[mysql]，然后在其下增加配置参数 default-character-set = utf8

新增节点\[client]，然后在其下增加配置参数 default-character-set = utf8

在节点\[mysqld] 下增肌配置参数 character-set-server = utf8

删除原来\[mysqld]节点下和utf8有关的参数  
![](http://dl2.iteye.com/upload/attachment/0108/3470/a5d7f56f-a472-359b-a307-62804073b08f.png)  
 

**9.3** **\[Warning] IP address 'xxx.xxx.xxx.xxx' could not be resolved: Temporary failure in name resolution**

**\[Warning] IP address '****xxx.xxx.xxx.xxx' could not be resolved: Name or service not known** 

 

问题产生的原因：  
出现错误的原因是MYSQL Server在本地内存中维护了一个非本地的Client TCP cache，这个cache中包含了远程Client的登录信息，比如IP地址，hostname等信息。  
如果Client连接到服务器后，Mysql首先会在本地TCP池中根据IP地址解析客户端的hostname或者反解析，如果解析不到，就会去DNS中进行解析，如果还是解析失败  
就是在error log中写入这样的警告信息。

解决的办法：  
可以通过两个参数来disable这个功能，在MYSQL的配置文件中\[mysqld]中加入下面的参数:  
\[mysqld]  
skip-host-cache  
skip-name-resolve

 

**9.4** **mysql启用skip-name-resolve模式时出现Warning的处理办法**

**\[Warning] 'proxies\_priv' entry '@ root@10-10-5-27' ignored in --skip-name-resolve mode.**

 

 

参考以下解决方法：

skip-name-resolve 参数的目的是不再进行反解析（ip不反解成域名），这样可以加快数据库的反应时间。

修改配置文件添加并需要重启：

\[mysqld] 

skip-name-resolve

添加后发现错误日志有警告信息  
131127 11:09:12 \[Warning] 'user' entry 'root@cvs' ignored in --skip-name-resolve mode.  
131127 11:09:12 \[Warning] 'user' entry '@cvs' ignored in --skip-name-resolve mode.  
131127 11:09:12 \[Warning] 'proxies\_priv' entry '@ root@cvs' ignored in --skip-name-resolve mode

启用后，在mysql的授权表中就不能使用主机名了，只能使用IP ，出现此警告是由于mysql.user表中已经存在有相关的帐号信息。 我们把它删除就好了。  
mysql&gt;use mysql;  
mysql&gt; delete  from user where HOST='cvs';  
Query OK, 2 rows affected (0.00 sec)  

然后删除表mysql.proxies\_priv中和cvs类似与具体域名有关的行,方法同上。

重启MYSQL ，发现警告已经没有啦。 

 

**9.5 \[Note] InnoDB: The InnoDB memory heap is disabled**

表示InnoDB默认使用系统内存，如果需要自定义InnoDB内存则需要在节点\[mysqld]下增加如下参数：

innodb\_use\_sys\_malloc = 0

tmpdir = /data/mysql/tmp

然后重启mysql，查看日志就可以看到**”The InnoDB memory heap is disabled” 已经没有了**

但在日志中会出现1条新的警告：**InnoDB: Warning: Setting innodb\_use\_sys\_malloc to FALSE is DEPRECATED. This option may be removed in future releases, together with the InnoDB's internal memory allocator.**