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.
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 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 这是免费的,因此下载这个类型。
在 select platform 中选择 Linux-Generic
选择下载的包: 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
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
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%';
修改/usr/local/mysql/my.cnf文件
如下图,在[mysqld]节点下增加3行配置参数:
skip-character-set-client-handshake
character_set_client=utf8
character_set_server=utf8
保存修改,然后重启mysql。
登入mysql,执行命令:/usr/local/mysql/bin/mysql -uroot -p密码
查看mysql的字符编码,执行命令:
show variables like '%char%';
如果都显示utf8,那么表示字符编码已经全部调整为utf8,如果看到lat1,则表示编码不全是utf8。
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
保存修改,然后重启mysql
9. 查看mysql的日志
查看日志命令 cat /data/mysql/data/xxx.err (注意xxx用自己的日志文件名来替换)
9.1 [Note] Plugin 'FEDERATED' is disabled.
解决方法:在my.cnf中的mysqld节点下增加一行参数
federated
如下图,然后重启mysql,问题就可以解决。
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
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>use mysql;
mysql> 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.