linux 6.5下 MySQL 5.6 RPM安装

来源:互联网 发布:t-sql语法基础知识 编辑:程序博客网 时间:2024/04/30 08:21

1.环境

OS: CentOS 6.5 x64


2.准备MySQL RPM安装包

打开网址:http://dev.mysql.com/downloads/mysql/

会看到以下界面:


最新的是5.7,我们要下载的是5.6,所以点击右边的Looking for previous GA versions?,会出现以下界面:


Select Version: 选5.6.31,Select Platform: 选Red Hat Enterprise Linux / Oracle Linux. 

在下面的下载列表里选Red Hat Enterprise Linux 6 / Oracle Linux 6 (x86, 64-bit), RPM Bundle,下载



3.准备安装

将下载的MySQL-5.6.31-1.el6.x86_64.rpm-bundle.tar上传到服务器,解压:

[root@single mysql2]# tar -xvf MySQL-5.6.29-1.el6.x86_64.rpm-bundle.tar 
MySQL-devel-5.6.29-1.el6.x86_64.rpm
MySQL-embedded-5.6.29-1.el6.x86_64.rpm
MySQL-server-5.6.29-1.el6.x86_64.rpm
MySQL-client-5.6.29-1.el6.x86_64.rpm
MySQL-test-5.6.29-1.el6.x86_64.rpm
MySQL-shared-5.6.29-1.el6.x86_64.rpm
[root@single mysql2]# 

解压后会出现7个rpm包,我们只需要其中两个:MySQL-server-5.6.29-1.el6.x86_64.rpm和MySQL-client-5.6.29-1.el6.x86_64.rpm。

安装前要先查询一下系统是否已经安装了MySQL,如果已安装需要先删除,否则会报冲突:

[root@single mysql2]# rpm -ivh MySQL-server-5.6.29-1.el6.x86_64.rpm 
warning: MySQL-server-5.6.29-1.el6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing...                ########################################### [100%]
file /usr/bin/innochecksum from install of MySQL-server-5.6.29-1.el6.x86_64
conflicts with file from package MySQL-server-advanced-5.6.24-1.el6.x86_64
file /usr/bin/my_print_defaults from install of MySQL-server-5.6.29-1.el6.x86_64 conflicts with file from package MySQL-server-advanced-5.6.24-1.el6.x86_64
file /usr/bin/myisam_ftdump from install of MySQL-server-5.6.29-1.el6.x86_64 conflicts with file from package MySQL-server-advanced-5.6.24-1.el6.x86_64

。。。

[root@single mysql2]# rpm -qa | grep -i mysql
MySQL-client-advanced-5.6.24-1.el6.x86_64
MySQL-server-advanced-5.6.24-1.el6.x86_64
MySQL-devel-advanced-5.6.24-1.el6.x86_64

[root@single mysql2]# rpm -e MySQL-server-advanced-5.6.24-1.el6.x86_64     #删除已安装的MySQL

[root@single mysql2]# rpm -e MySQL-client-advanced-5.6.24-1.el6.x86_64     #客户端也要删除

如果删除的由于包依赖删除不了,报 error: Failed dependencies,可以加--nodeps方式删除:

[root@single mysql2]# rpm -e--nodeps MySQL-server-advanced-5.6.24-1.el6.x86_64


4.安装

[root@single mysql2]# rpm -ivh MySQL-server-5.6.29-1.el6.x86_64.rpm 
warning: MySQL-server-5.6.29-1.el6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing...                ########################################### [100%]
   1:MySQL-server           ########################################### [100%]
2016-05-11 09:38:24 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).

。。。

2016-05-11 09:38:38 7496 [Note] InnoDB: Shutdown completed; log sequence number 1625987
A RANDOM PASSWORD HAS BEEN SET FOR THE MySQL root USER !
You will find that password in '/root/.mysql_secret'.

You must change that password on your first connect,
no other statement but 'SET PASSWORD' will be accepted.
See the manual for the semantics of the 'password expired' flag.

Also, the account for the anonymous user has been removed.

In addition, you can run:

  /usr/bin/mysql_secure_installation

which will also give you the option of removing the test database.
This is strongly recommended for production servers.

See the manual for more instructions.

Please report any problems at http://bugs.mysql.com/

The latest information about MySQL is available on the web at

  http://www.mysql.com

Support MySQL by buying support/licenses at http://shop.mysql.com

New default config file was created as /usr/my.cnf and
will be used by default by the server when you start it.
You may edit this file to change server settings

上面的安装提示很重要,比如密码文件的位置,配置文件位置等。默认安装的数据目录位置是/var/lib/mysql,要想改变安装目录,可以使用rpm的--prefix选项指定安装目录。

[root@single mysql2]# cd /var/lib/mysql/
[root@single mysql]# ls
ibdata1  ib_logfile0  ib_logfile1  mysql  performance_schema  RPM_UPGRADE_HISTORY  RPM_UPGRADE_MARKER-LAST  test
[root@single mysql]# 

安装完server还需要安装client,否则server无法使用:
[root@single mysql2]# rpm -ivh MySQL-client-5.6.29-1.el6.x86_64.rpm 
warning: MySQL-client-5.6.29-1.el6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing...                ########################################### [100%]
   1:MySQL-client           ########################################### [100%]
[root@single mysql2]# 


5.配置my.cnf

[root@singleusr]# vi /etc/my.cnf
[mysqld]
datadir = /var/lib/mysql

就这么简单,只配置了一个参数,其实不配置任何参数甚至没有my.cnf文件都可以,只不过全部使用默认值而已。

在生产环境下mysql有许多参数要配,这里只是样例,所以只配置了一个参数。


6.mysql启动、停止、状态

[root@single mysql]# /etc/init.d/mysql start
Starting MySQL.                                            [  OK  ]
[root@single mysql]# /etc/init.d/mysql status
MySQL running (8351)                                       [  OK  ]
[root@single mysql]# /etc/init.d/mysql stop
Shutting down MySQL..                                      [  OK  ]
[root@single mysql]# /etc/init.d/mysql status
MySQL is not running                                       [FAILED]
[root@single mysql]# 

使用RPM包安装,MySQL会自动添加到系统服务并可以开机自动启动。


7.修改root密码

mysql服务启动后第一件事是修改root密码。用RPM方式安装的MySQL5.6不能再用mysqladmin来修改root密码了,要用安装时生成的密码登录后再修改密码,安装时生成的密码在/root/.mysql_secret文件里。

[root@single mysql]# mysqladmin -uroot password
mysqladmin: connect to server at 'localhost' failed
error: 'Access denied for user 'root'@'localhost' (using password: NO)'
[root@single mysql]# cd 

[root@single ~]# ls -a .mysql*
.mysql_history  .mysql_secret
[root@single ~]# cat .mysql_secret 
# The random password set for the root user at Wed May 11 09:38:34 2016 (local time): FloC99GoZUfjkqhg


[root@single ~]# mysql -uroot -pFloC99GoZUfjkqhg
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.6.29
Copyright (c) 2000, 2016, 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> set password=password('root');

mysql> exit
Bye
[root@single mysql]# mysql -uroot -proot #用新密码登录
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.29 MySQL Community Server (GPL)
Copyright (c) 2000, 2016, 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> 


成功。

MySQL RPM方式安装完成。


权限管理可以参考这里:http://blog.csdn.net/john_chang11/article/details/51848254

如何创建表可以参考这里:http://blog.csdn.net/john_chang11/article/details/51673825

MySQL的源码安装可以参考这里:http://blog.csdn.net/john_chang11/article/details/51593220










0 0
原创粉丝点击