在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.-.linux_glibc2..x86_64.rpm
rpm -ivh MySQL-devel-5.6.-.linux_glibc2..x86_64.rpm
rpm -ivh MySQL-client-5.6.-.linux_glibc2..x86_64.rpm

debug 如下:

[root@VM_32_234_centos tools]# rpm -ivh MySQL-server-5.6.-.linux_glibc2..x86_64.rpm
Preparing... ########################################### [%]
:MySQL-server rpm -ivh MySQL-devel-5.6.-.linux_glibc2..x86_64.rpm
rpm -ivh MySQL-client-5.6.-.linux_glibc2..x86_64.rpm################# ########################################### [%]
-- :: [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
-- :: [Note] InnoDB: Using atomics to ref count buffer pool pages
-- :: [Note] InnoDB: The InnoDB memory heap is disabled
-- :: [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
-- :: [Note] InnoDB: Memory barrier is not used
-- :: [Note] InnoDB: Compressed tables use zlib 1.2.
-- :: [Note] InnoDB: Using Linux native AIO
-- :: [Note] InnoDB: Using CPU crc32 instructions
-- :: [Note] InnoDB: Initializing buffer pool, size = 128.0M
-- :: [Note] InnoDB: Completed initialization of buffer pool
-- :: [Note] InnoDB: The first specified data file ./ibdata1 did not exist: a new database to be created!
-- :: [Note] InnoDB: Setting file ./ibdata1 size to MB
-- :: [Note] InnoDB: Database physically writes the file full: wait...
-- :: [Note] InnoDB: Setting log file ./ib_logfile101 size to MB
-- :: [Note] InnoDB: Setting log file ./ib_logfile1 size to MB
-- :: [Note] InnoDB: Renaming log file ./ib_logfile101 to ./ib_logfile0
-- :: [Warning] InnoDB: New log files created, LSN=
-- :: [Note] InnoDB: Doublewrite buffer not found: creating new
-- :: [Note] InnoDB: Doublewrite buffer created
-- :: [Note] InnoDB: rollback segment(s) are active.
-- :: [Warning] InnoDB: Creating foreign key constraint system tables.
-- :: [Note] InnoDB: Foreign key constraint system tables created
-- :: [Note] InnoDB: Creating tablespace and datafile system tables.
-- :: [Note] InnoDB: Tablespace and datafile system tables created.
-- :: [Note] InnoDB: Waiting for purge to start
-- :: [Note] InnoDB: 5.6. started; log sequence number
A random root password has been set. You will find it in '/root/.mysql_secret'.
-- :: [Note] Binlog end
-- :: [Note] InnoDB: FTS optimize thread exiting.
-- :: [Note] InnoDB: Starting shutdown...
-- :: [Note] InnoDB: Shutdown completed; log sequence number -- :: [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
-- :: [Note] InnoDB: Using atomics to ref count buffer pool pages
-- :: [Note] InnoDB: The InnoDB memory heap is disabled
-- :: [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
-- :: [Note] InnoDB: Memory barrier is not used
-- :: [Note] InnoDB: Compressed tables use zlib 1.2.
-- :: [Note] InnoDB: Using Linux native AIO
-- :: [Note] InnoDB: Using CPU crc32 instructions
-- :: [Note] InnoDB: Initializing buffer pool, size = 128.0M
-- :: [Note] InnoDB: Completed initialization of buffer pool
-- :: [Note] InnoDB: Highest supported file format is Barracuda.
-- :: [Note] InnoDB: rollback segment(s) are active.
-- :: [Note] InnoDB: Waiting for purge to start
-- :: [Note] InnoDB: 5.6. started; log sequence number
-- :: [Note] Binlog end
-- :: [Note] InnoDB: FTS optimize thread exiting.
-- :: [Note] InnoDB: Starting shutdown...
-- :: [Note] InnoDB: Shutdown completed; log sequence number 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.-.linux_glibc2..x86_64.rpm
Preparing... ########################################### [%]
:MySQL-devel ########################################### [%]
[root@VM_32_234_centos tools]# rpm -ivh MySQL-client-5.6.-.linux_glibc2..x86_64.rpm
Preparing... ########################################### [%]
:MySQL-client ########################################### [%]
[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 :: (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
Server version: 5.6. Copyright (c) , , 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('123456'); #更改MySQL密码,

mysql> set password=password('');
Query OK, rows affected (0.00 sec)

5.设置开机启动

chkconfig mysql on
[root@VM_32_234_centos storage]# chkconfig mysql on
[root@VM_32_234_centos storage]# chkconfig --list | grep mysql
mysql :off :off :on :on :on :on :off

上面打印出来的内容中,2~5为on就是开机启动了。

6.修改/etc/my.cnf

  设置MySQL的字符集,配置MySQL表明不区分大小写(默认情况下,MySQL对表名区分大小写,列名不区分大小写)。在[mysqld]下面加入如下内容:

character_set_server=utf8 character_set_client=utf8 collation-server=utf8_general_ci lower_case_table_names= max_connections=

7.MySQL的默认文件路径

  1. /var/lib/mysql/ #数据库目录
  2. /usr/share/mysql #配置文件目录
  3. /usr/bin #相关命令目录 #启动脚本

8.修改数据文件路径

  1.修改 /etc/my.cnf 文件

  vi /etc/my.cnf

# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html
# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the
# *** default location during install, and will be replaced if you
# *** upgrade to a newer version of MySQL. [mysqld] # Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at % of total RAM for dedicated server, else %.
# innodb_buffer_pool_size = 128M # Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin # These are commonly set, remove the # and set as required.
#basedir = /storage/server/mysql-5.6.-/
datadir = /storage/server/mysql-5.6.-/data
port =
server_id =
socket = /storage/server/mysql-5.6.-/data/mysql.sock
pid-file =/storage/server/mysql-5.6.-/data/VM_32_234_centos.pid # Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

复制文件 /var/lib/mysql/  到 /storage/server/mysql-5.6.21-1/data/

cp -R /var/lib/mysql/* /storage/server/mysql-5.6.21-1/data/

9.重启MySQL

# service mysql restart
Shutting down MySQL.. SUCCESS!
Starting MySQL. SUCCESS!

linux 下 安装 rpm 格式 的 mysql的更多相关文章

  1. linux下安装rpm格式的mysql

    1.下载安装包官网下载.rpm格式安装包,需要下面两个文件: MySQL-server-5.0.26-0.i386.rpm MySQL-client-5.0.26-0.i386.rpm 注:官网下载时 ...

  2. Linux下安装配置与使用MySQL数据库

    Linux下安装配置与使用MySQL数据库 在Linux下安装做开发时往往少不了要使用到MySQL数据库,下面就Linux系统为例讲解一下,如何安装MySQL数据库,如何启用/停.止MySQL服务,如 ...

  3. Linux下安装rpm出现error: Failed dependencies

    在Linux下安装rpm包时经常会遇到下面这个问题: error: Failed dependencies: xxxxxxxxxxxxxxxxxxxxxx 遇到此问题时可以在安装rpm包命令的后面加两 ...

  4. linux下安装jdk+tomcat+eclipse+mysql

    我的环境:主机是win7的,虚拟机是VWare  Workstation 6.0   ,linux系统为Red Hat Enterprise  Linux 5 64位 各软件版本:jdk是jdk-6u ...

  5. Linux下安装启动多个Mysql

    网上找了N多资料,没有一个可以顺利成功的,郁闷,可能是水平有限吧...!本人经过不断的研究.测试,完整实现Linux下启动两台MySQL,而且对mysql有了更深入的了解...废话不多说,走着! 步骤 ...

  6. Linux下安装LAMP(Apache+PHP+MySql)和禅道

    1.更新yum源: yum update -y 2.安装Apache+PHP+MySql yum install httpd mysql-devel mysql-server mysql-php ph ...

  7. 安装Linux的步骤 包含linux下安装jdk,及mysql

    https://mirrors.tuna.tsinghua.edu.cn/centos/7.9.2009/isos/x86_64/ 镜像下载网址,4G 左右. 安装VMware 15版本 一路下一步, ...

  8. linux下安装mysql(rpm文件安装)

    数据库包下载: https://www.mysql.com/downloads/ 在GPL开原协议的社区开源版里边下载 我们用mysql community server里边的 其中workbench ...

  9. 在Linux下安装和使用MySQL

    [简 介] 想使用Linux已经很长时间了,由于没有硬性任务一直也没有系统学习,近日由于工作需要必须使用Linux下的MySQL.本以为有Windows下使用SQL Server的经验,觉得在Linu ...

随机推荐

  1. C# 操作 Excel 常见问题收集和整理(定期更新,欢迎交流)

    经常会有项目需要把表格导出为 Excel 文件,或者是导入一份 Excel 来操作,那么如何在 C# 中操作 Excel 文件成了一个最基本的问题. 做开发这几年来,陆陆续续也接触过这样的需求,但因为 ...

  2. NAT

      WRITE BY YANGWJ 一.            配置静态Nat 实验图如下: 1.         将网络基本条件配置好,包括路由要可达,即pc1可以ping到server1 2.   ...

  3. Java关键字介绍之this与super

    1.什么是super?什么是this? super关键字表示超(父)类的意思.this变量代表对象本身. 2.使用super&this调用成员变量和方法 可以使用super访问父类被子类隐藏的 ...

  4. MVC项目页面获取控制器的信息

    页面获取控制器的名字: @{ if (ViewContext.RouteData.Values["controller"].ToString()=="Home" ...

  5. 7款超具个性的HTML5播放器

    这篇文章我们要分享一些很有个性的HTML5音乐播放器和视频播放器,它们都具有播放器的大部分功能,并以HTML5和JavaScript实现.这些HTML5播放器有着非常漂亮的外观,很多你都无需自己重新定 ...

  6. 洛谷 1865 A%B问题

    题目背景 题目名称是吸引你点进来的 实际上该题还是很水的 题目描述 区间质数个数 输入输出格式 输入格式: 一行两个整数 询问次数n,范围m 接下来n行,每行两个整数 l,r 表示区间 输出格式: 对 ...

  7. Data truncated for column 错误

    今天插入mysql数据数据时,报错Data truncated for column.研究了一下原理是我数据的长途超出了该字段的最大长度,所以解决办法很简单,就是修改数据库中字段属性,使其长度增加即可 ...

  8. FPGA使用技巧

    1 IOB       为了保证FPGA输入输出接口的时序,一般会要求将输入管脚首先打一拍再使用,输出接口也要打一拍再输出FPGA.将信号打一拍的方法是将信号通过一次寄存器,而且必须在IOB里面的寄存 ...

  9. Java应用短信猫

    首先确定短信猫正常连接到主机,并安装SIM卡.先用超级终端测试短息猫能不能用.安装minicom:#sudo apt-get install minicom安装完成后,执行#sudo minicom ...

  10. 汇编语言-求X的阶乘

    1. 题目:求X的阶乘值 2. 要求:输入一个整型数(不超过10),求出其阶乘值后输出,求阶乘的算法用子程序来实现. 3. 提示:可以用递归来实现,也可以用简单的循环来实现. 这里使用循环来实现: 对 ...