标签


CentOS6.6 上安装MySQL5.6

2015年02月26日

准备工作

MySQL官网上分别下载mysql服务器端于客户端包。如:

MySQL-client-5.6.23-1.linux_glibc2.5.x86_64.rpm
MySQL-server-5.6.23-1.linux_glibc2.5.x86_64.rpm

检测系统是否安装MySQL

进入系统后,检测是否安装mysql. 如:检测是否安装Mysql输入

#rpm -qa | grep -i mysql
[root@localhost MySQL-5.6.23]# rpm -qa | grep -i mysql
mysql-libs-5.1.73-3.el6_5.x86_64


[root@localhost MySQL-5.6.23]# rpm -ivh MySQL-server-5.6.23-1.linux_glibc2.5.x86_64.rpm 
Preparing...                ########################################### [100%]
	file /usr/share/mysql/charsets/README from install of MySQL-server-5.6.23-1.linux_glibc2.5.x86_64 conflicts with file from package mysql-libs-5.1.73-3.el6_5.x86_64
	file /usr/share/mysql/czech/errmsg.sys from install of MySQL-server-5.6.23-1.linux_glibc2.5.x86_64 conflicts with file from package mysql-libs-5.1.73-3.el6_5.x86_64
	file /usr/share/mysql/danish/errmsg.sys from install of MySQL-server-5.6.23-1.linux_glibc2.5.x86_64 conflicts with file from package mysql-libs-5.1.73-3.el6_5.x86_64
	...

[root@localhost MySQL-5.6.23]# rpm -qa| grep -i mysql
mysql-libs-5.1.73-3.el6_5.x86_64
[root@localhost MySQL-5.6.23]# rpm -ev mysql-libs-5.1.73-3.el6_5.x86_64
error: Failed dependencies:
	libmysqlclient.so.16()(64bit) is needed by (installed) postfix-2:2.6.6-6.el6_5.x86_64
	libmysqlclient.so.16(libmysqlclient_16)(64bit) is needed by (installed) postfix-2:2.6.6-6.el6_5.x86_64
	mysql-libs is needed by (installed) postfix-2:2.6.6-6.el6_5.x86_64
[root@localhost MySQL-5.6.23]# 

原因由包冲突引起的! 解决思路,先移除冲突的libs包,在进行安装

执行以下命令,删除mysql-libs-5.1.73-3.el6.x86_64:-y的意思就是不用询问是否remove

[root@localhost MySQL-5.6.23]# yum -y remove mysql-libs-5.1.73*
Loaded plugins: fastestmirror, refresh-packagekit, security
Setting up Remove Process
Resolving Dependencies
--> Running transaction check
---> Package mysql-libs.x86_64 0:5.1.73-3.el6_5 will be erased
--> Processing Dependency: libmysqlclient.so.16()(64bit) for package: 2:postfix-2.6.6-6.el6_5.x86_64
--> Processing Dependency: libmysqlclient.so.16(libmysqlclient_16)(64bit) for package: 2:postfix-2.6.6-6.el6_5.x86_64
--> Processing Dependency: mysql-libs for package: 2:postfix-2.6.6-6.el6_5.x86_64
--> Running transaction check
...
Removed:
  mysql-libs.x86_64 0:5.1.73-3.el6_5 

Dependency Removed:
  cronie.x86_64 0:1.4.4-12.el6          cronie-anacron.x86_64 0:1.4.4-12.el6          crontabs.noarch 0:1.10-33.el6          postfix.x86_64 2:2.6.6-6.el6_5          sysstat.x86_64 0:9.0.4-27.el6 

Complete!

再次安装MySQL

[root@localhost MySQL-5.6.23]# rpm -ivh MySQL-server-5.6.23-1.linux_glibc2.5.x86_64.rpm 
Preparing...                ########################################### [100%]
   1:MySQL-server           ########################################### [100%]
warning: user mysql does not exist - using root
warning: group mysql does not exist - using root
2015-02-26 01:35:29 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2015-02-26 01:35:29 13049 [Note] InnoDB: Using atomics to ref count buffer pool pages
...
2015-02-26 01:35:34 13073 [Note] InnoDB: Shutdown completed; log sequence number 1625987
...
Also, the account for the anonymous user has been removed.
In addition, you can run:
  /usr/bin/mysql_secure_installation
...

安装客户端

[root@localhost MySQL-5.6.23]# rpm -ivh MySQL-client-5.6.23-1.linux_glibc2.5.x86_64.rpm 
Preparing...                ########################################### [100%]
   1:MySQL-client           ########################################### [100%]

[root@localhost MySQL-5.6.23]# netstat -nat
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address               Foreign Address             State      
tcp        0      0 0.0.0.0:22                  0.0.0.0:*                   LISTEN      
tcp        0      0 127.0.0.1:631               0.0.0.0:*                   LISTEN      
tcp        0      0 10.64.40.17:22              10.64.40.4:57248            ESTABLISHED 
tcp        0      0 :::22                       :::*                        LISTEN      
tcp        0      0 ::1:631                     :::*                        LISTEN   
[root@localhost MySQL-5.6.23]# service mysql start
Starting MySQL......... SUCCESS! 
[root@localhost MySQL-5.6.23]# netstat -nat
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address               Foreign Address             State      
tcp        0      0 0.0.0.0:22                  0.0.0.0:*                   LISTEN      
tcp        0      0 127.0.0.1:631               0.0.0.0:*                   LISTEN      
tcp        0      0 10.64.40.17:22              10.64.40.4:57248            ESTABLISHED 
tcp        0      0 :::22                       :::*                        LISTEN      
tcp        0      0 ::1:631                     :::*                        LISTEN      
tcp        0      0 :::3306                     :::*                        LISTEN      

设置新密码

[root@localhost MySQL-5.6.23]# cat /root/.mysql_secret
# The random password set for the root user at Thu Feb 26 01:35:30 2015 (local time): ix4o33R687RUX77C

[root@localhost MySQL-5.6.23]# /usr/bin/mysql_secure_installation
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!
...
All done!  If you've completed all of the above steps, your MySQL
installation should now be secure.
Thanks for using MySQL!
Cleaning up...

密码: dream123

[root@localhost mysql]# whereis mysql
mysql: /usr/bin/mysql /usr/lib64/mysql /usr/share/mysql /usr/share/man/man1/mysql.1.gz

自动启动

1)察看mysql是否在自动启动列表中

[root@localhost mysql]# /sbin/chkconfig --list| grep mysql
mysql          	0:off	1:off	2:on	3:on	4:on	5:on	6:off

2)把MySQL添加到你系统的启动服务组里面去

/sbin/chkconfig – add mysql

3)把MySQL从启动服务组里面删除。

/sbin/chkconfig – del mysql

安装MySQL5.6 my.cnf的默认位置在/usr/my.cnf,拷贝它到/etc/my.cnf。 注:我人为的为所有用户添加写权限,mysql为安全起见,将/etc/my.cnf忽略了,最后将my.cnf设置为用户可读写,其他用户不可写,才可通过.

[root@localhost mysql]# service mysql stop
Warning: World-writable config file '/etc/my.cnf' is ignored
Shutting down MySQL.... SUCCESS! 
[root@localhost mysql]# chmod 644 /etc/my.cnf

查看字符集

mysql> show variables like '%char%';
+--------------------------+----------------------------+
| Variable_name            | Value                      |
+--------------------------+----------------------------+
| character_set_client     | utf8                       |
| character_set_connection | utf8                       |
| character_set_database   | latin1                     |
| character_set_filesystem | binary                     |
| character_set_results    | utf8                       |
| character_set_server     | latin1                     |
| character_set_system     | utf8                       |
| character_sets_dir       | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.00 sec)

mysql> show variables like '%colla%';
+----------------------+-------------------+
| Variable_name        | Value             |
+----------------------+-------------------+
| collation_connection | utf8_general_ci   |
| collation_database   | latin1_swedish_ci |
| collation_server     | latin1_swedish_ci |
+----------------------+-------------------+
3 rows in set (0.00 sec)

修改/etc/my.cnf,分别在mysqld选项和mysql选项中添加以下内容。

[mysqld]
character_set_server=utf8
collation-server=utf8_general_ci
character_set_client=utf8

[mysql]
default-character-set = utf8

重新查看

mysql> show variables like '%char%';
+--------------------------+----------------------------+
| Variable_name            | Value                      |
+--------------------------+----------------------------+
| character_set_client     | utf8                       |
| character_set_connection | utf8                       |
| character_set_database   | utf8                       |
| character_set_filesystem | binary                     |
| character_set_results    | utf8                       |
| character_set_server     | utf8                       |
| character_set_system     | utf8                       |
| character_sets_dir       | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.00 sec)

mysql> show variables like '%colla%';
+----------------------+-----------------+
| Variable_name        | Value           |
+----------------------+-----------------+
| collation_connection | utf8_general_ci |
| collation_database   | utf8_general_ci |
| collation_server     | utf8_general_ci |
+----------------------+-----------------+
3 rows in set (0.01 sec)