linux mysql 安装



            linux mysql 安装

在Linux操作系统下,安装MYSQL有两种方式:

一种tar安装方式,

另外一种是rpm安装方式。

这两种安装方式有什么区别呢?尽管我们在Linux下常用tar来压缩/解压缩文件,但MYSQL的tar格式的文件其实只是mysql的文件包,并不能直接安装,需要操作configure、make、install等命令才能完成安装,是一种比较繁琐的安装方式。而rpm格式的文件是真正的安装包,相当于windows的exe文件,可以直接安装。

本文以MySQL-5.6.21 64位版本rpm格式的安装方式为例,详述MySQL的安装方式,32位的rpm版本安装方式也是如此。

(一)删除老版本的MySQL

在安装前要先确定系统是否已经安装了其他版本的MySQL,如已安装其他版本的MySQL,需先删除后再安装新版本。经本文亲测,采用如下方式删除老版本的MySQL或MySQL残留文件作为方便。

1. 执行yum命令,删除MySQL的lib库,服务文件

yum remove mysql mysql-server mysql-libs mysql-server;

2. 执行find命令,查找MySQL的残留文件,然后运行“rm -rf 文件名”删除残留的MySQL文件

find / -name mysql

(二)RPM格式安装MySQL

当前,MySQL的最新版本为:5.6.21,从官网下载MySQL的rpm安装包,解压后有如下六个文件:

  1. MySQL-client-5.6.21-1.linux_glibc2.5.x86_64.rpm #MySQL客户端程序
  2. MySQL-devel-5.6.21-1.linux_glibc2.5.x86_64.rpm #MySQL的库和头文件
  3. MySQL-embedded-5.6.21-1.linux_glibc2.5.x86_64.rpm #MySQL的嵌入式程序
  4. MySQL-server-5.6.21-1.linux_glibc2.5.x86_64.rpm #MySQL服务端程序
  5. MySQL-shared-5.6.21-1.linux_glibc2.5.x86_64.rpm #MySQL的共享库
  6. MySQL-test-5.6.21-1.linux_glibc2.5.x86_64.rpm #MySQL的测试组件

一般对于开发而言,我们只需要下面三个文件就可以。

  1. MySQL-devel-5.6.21-1.linux_glibc2.5.x86_64.rpm #MySQL的库和头文件
  2. MySQL-server-5.6.21-1.linux_glibc2.5.x86_64.rpm #MySQL服务端程序 
  3. MySQL-devel-5.6.21-1.linux_glibc2.5.x86_64.rpm #MySQL的库和头文件

1. 在重新进行安装之前,为确保万无一失,我们还是再确认一下系统中是否有MySQL极其相关的RPM安装包。如果有,则先删除。

rpm -qa | grep -i mysql

执行完上述命令后,返回空数据,则可进行第二步。否则,执行下面的命令删除MySQL的相关包文件。

yum -y remove mysql-libs*

2. 将前面提到的三个MySQL安装文件,拷贝到服务器,然后执行下述安装命令

rpm -ivh MySQL-server-5.6.21-1.linux_glibc2.5.x86_64.rpm
rpm -ivh MySQL-devel-5.6.21-1.linux_glibc2.5.x86_64.rpm
rpm -ivh MySQL-client-5.6.21-1.linux_glibc2.5.x86_64.rpm

debug 如下:

[root@VM_32_234_centos tools]# rpm -ivh MySQL-server-5.6.21-1.linux_glibc2.5.x86_64.rpm
Preparing...					 ########################################### [100%]
  1:MySQL-server			  rpm -ivh MySQL-devel-5.6.21-1.linux_glibc2.5.x86_64.rpm
rpm -ivh MySQL-client-5.6.21-1.linux_glibc2.5.x86_64.rpm#################		 ########################################### [100%]
2014-09-29 15:01:50 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2014-09-29 15:01:50 30994 [Note] InnoDB: Using atomics to ref count buffer pool pages
2014-09-29 15:01:50 30994 [Note] InnoDB: The InnoDB memory heap is disabled
2014-09-29 15:01:50 30994 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2014-09-29 15:01:50 30994 [Note] InnoDB: Memory barrier is not used
2014-09-29 15:01:50 30994 [Note] InnoDB: Compressed tables use zlib 1.2.3
2014-09-29 15:01:50 30994 [Note] InnoDB: Using Linux native AIO
2014-09-29 15:01:50 30994 [Note] InnoDB: Using CPU crc32 instructions
2014-09-29 15:01:50 30994 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2014-09-29 15:01:50 30994 [Note] InnoDB: Completed initialization of buffer pool
2014-09-29 15:01:50 30994 [Note] InnoDB: The first specified data file ./ibdata1 did not exist: a new database to be created!
2014-09-29 15:01:50 30994 [Note] InnoDB: Setting file ./ibdata1 size to 12 MB
2014-09-29 15:01:50 30994 [Note] InnoDB: Database physically writes the file full: wait...
2014-09-29 15:01:51 30994 [Note] InnoDB: Setting log file ./ib_logfile101 size to 48 MB
2014-09-29 15:01:52 30994 [Note] InnoDB: Setting log file ./ib_logfile1 size to 48 MB
2014-09-29 15:01:52 30994 [Note] InnoDB: Renaming log file ./ib_logfile101 to ./ib_logfile0
2014-09-29 15:01:52 30994 [Warning] InnoDB: New log files created, LSN=45781
2014-09-29 15:01:52 30994 [Note] InnoDB: Doublewrite buffer not found: creating new
2014-09-29 15:01:52 30994 [Note] InnoDB: Doublewrite buffer created
2014-09-29 15:01:52 30994 [Note] InnoDB: 128 rollback segment(s) are active.
2014-09-29 15:01:52 30994 [Warning] InnoDB: Creating foreign key constraint system tables.
2014-09-29 15:01:52 30994 [Note] InnoDB: Foreign key constraint system tables created
2014-09-29 15:01:52 30994 [Note] InnoDB: Creating tablespace and datafile system tables.
2014-09-29 15:01:52 30994 [Note] InnoDB: Tablespace and datafile system tables created.
2014-09-29 15:01:52 30994 [Note] InnoDB: Waiting for purge to start
2014-09-29 15:01:52 30994 [Note] InnoDB: 5.6.21 started; log sequence number 0
A random root password has been set. You will find it in '/root/.mysql_secret'.
2014-09-29 15:01:53 30994 [Note] Binlog end
2014-09-29 15:01:53 30994 [Note] InnoDB: FTS optimize thread exiting.
2014-09-29 15:01:53 30994 [Note] InnoDB: Starting shutdown...
2014-09-29 15:01:54 30994 [Note] InnoDB: Shutdown completed; log sequence number 1625977


2014-09-29 15:01:54 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2014-09-29 15:01:54 31016 [Note] InnoDB: Using atomics to ref count buffer pool pages
2014-09-29 15:01:54 31016 [Note] InnoDB: The InnoDB memory heap is disabled
2014-09-29 15:01:54 31016 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2014-09-29 15:01:54 31016 [Note] InnoDB: Memory barrier is not used
2014-09-29 15:01:54 31016 [Note] InnoDB: Compressed tables use zlib 1.2.3
2014-09-29 15:01:54 31016 [Note] InnoDB: Using Linux native AIO
2014-09-29 15:01:54 31016 [Note] InnoDB: Using CPU crc32 instructions
2014-09-29 15:01:54 31016 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2014-09-29 15:01:54 31016 [Note] InnoDB: Completed initialization of buffer pool
2014-09-29 15:01:54 31016 [Note] InnoDB: Highest supported file format is Barracuda.
2014-09-29 15:01:54 31016 [Note] InnoDB: 128 rollback segment(s) are active.
2014-09-29 15:01:54 31016 [Note] InnoDB: Waiting for purge to start
2014-09-29 15:01:54 31016 [Note] InnoDB: 5.6.21 started; log sequence number 1625977
2014-09-29 15:01:54 31016 [Note] Binlog end
2014-09-29 15:01:54 31016 [Note] InnoDB: FTS optimize thread exiting.
2014-09-29 15:01:54 31016 [Note] InnoDB: Starting shutdown...
2014-09-29 15:01:56 31016 [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

[root@VM_32_234_centos tools]# rpm -ivh MySQL-devel-5.6.21-1.linux_glibc2.5.x86_64.rpm
Preparing...					 ########################################### [100%]
  1:MySQL-devel				########################################### [100%]
[root@VM_32_234_centos tools]# rpm -ivh MySQL-client-5.6.21-1.linux_glibc2.5.x86_64.rpm
Preparing...					 ########################################### [100%]
  1:MySQL-client			  ########################################### [100%]
[root@VM_32_234_centos tools]# 

上述三个命令在执行时,只有第一个命令执行的时间稍微长些,后面两个命令运行速度很快。

3.执行下述命令,将MySQL的配置文件拷贝到/etc目录下。

cp /usr/share/mysql/my-default.cnf /etc/my.cnf

4.分别运行下述命令,初始化MySQL及设置密码。

/usr/bin/mysql_install_db    #初始化MySQL 
service mysql start        #启动MySQL 
cat /root/.mysql_secret        #查看root账号的初始密码,会出现下述所示信息

如:

[root@VM_32_234_centos storage]# service mysql start
Starting MySQL. SUCCESS! 
[root@VM_32_234_centos storage]# cat /root/.mysql_secret
# The random password set for the root user at Mon Sep 29 15:01:52 2014 (local time): PENFgcgkI8UnIKaE

安装成功.

[root@VM_32_234_centos storage]# mysql -u root -pPENFgcgkI8UnIKaE
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 4
Server version: 5.6.21

Copyright (c) 2000, 2014, 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('MySecurePassword');

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值