Linux操作系统下MySQL的安装 --转

转自:http://www.cnblogs.com/mjorcen/p/4000371.html

注:另外的网址参考:http://www.linuxidc.com/Linux/2015-01/112583.htm

在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 如下:

[[email protected]_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

[[email protected]_32_234_centos tools]# rpm -ivh MySQL-devel-5.6.21-1.linux_glibc2.5.x86_64.rpm
Preparing...                ########################################### [100%]
   1:MySQL-devel            ########################################### [100%]
[[email protected]_32_234_centos tools]# rpm -ivh MySQL-client-5.6.21-1.linux_glibc2.5.x86_64.rpm
Preparing...                ########################################### [100%]
   1:MySQL-client           ########################################### [100%]
[[email protected]_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账号的初始密码,会出现下述所示信息

如:

[[email protected]_32_234_centos storage]# service mysql start
Starting MySQL. SUCCESS!
[[email protected]_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

[[email protected]_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(‘123456‘); #更改MySQL密码,

mysql> set password=password(‘123456‘);
Query OK, 0 rows affected (0.00 sec)

5.设置开机启动

chkconfig mysql on
[[email protected]_32_234_centos storage]# chkconfig mysql on
[[email protected]_32_234_centos storage]# chkconfig --list | grep mysql
mysql           0:off   1:off   2:on    3:on    4:on    5:on    6: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=1 max_connections=1000

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 70% of total RAM for dedicated server, else 10%.
# 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.21-1/
datadir = /storage/server/mysql-5.6.21-1/data
port = 3306
server_id = 2
socket = /storage/server/mysql-5.6.21-1/data/mysql.sock
pid-file =/storage/server/mysql-5.6.21-1/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!
时间: 2024-10-21 07:03:50

Linux操作系统下MySQL的安装 --转的相关文章

Linux(Ubuntu)下MySQL的安装与配置[转载+亲测]

在Linux下MySQL的安装,我一直觉得挺麻烦的,因为之前安装时就是由于复杂的配置导致有点晕.今天,需要在Linux下用Qt连接MySQL.遂安装配置了一把. 1)首先检查系统中是否已经安装了MySQL 在终端里面输入 sudo netstat -tap | grep mysql 若没有反映,没有显示已安装结果,则没有安装.若如下显示,则表示已经安装 2)如果没有安装,则安装MySQL. 在终端输入 sudo apt-get install mysql-server mysql-client

Linux(centos)下mysql编译安装教程

Linux下mysql编译安装教程 #查看linux发行版本号 cat /etc/issue #查看linux内核版本 uname -r 本文测试环境centOS6.6 一.Linux下编译安装MySQL前的准备工作 在线安装编译源码所需的工具和库(无法联网的话要事先准备软件,或者系统盘) yum install gcc gcc-c++ ncurses-devel perl 从mysql5.5起源代码编译需要借助cmake这款编译工具.从http://www.cmake.org下载cmake源码

Linux(Ubuntu)下MySQL的安装与配置

转自:http://www.2cto.com/database/201401/273423.html 在Linux下MySQL的安装,我一直觉得挺麻烦的,因为之前安装时就是由于复杂的配置导致有点晕.今天,需要在Linux下用Qt连接MySQL.遂安装配置了一把. 1)首先检查系统中是否已经安装了MySQL 在终端里面输入 sudo netstat -tap | grep mysql 若没有反映,没有显示已安装结果,则没有安装.若如下显示,则表示已经安装 2)如果没有安装,则安装MySQL. 在终

【Linux】LINUX操作系统下VIM的安装和配置

vim是从VI发展而来的一个文本编辑器,功能更强大.而vim.tiny是vim的精简版,所以,安装vim势在必行.同时Windows下程序员很多都很喜欢Source Insight这个工具来看代码,各种语法高亮看着很舒服.vim作为为程序员打造的编辑器,没有道理不可以通过配置让程序员舒服地编辑代码,但是新手通常很难将其配置成顺手顺眼的环境.下面的方法可以通过极其简单的方式把vim配置得跟Source Insight一样炫. 一.安装环境: LINUX操作系统(ubuntu/Centos) 二.v

Linux系统下mysql的安装

1.下载解压Mysql[[email protected] ~]# wget http://cdn.mysql.com//Downloads/MySQL-5.6/mysql-5.6.28.tar.gz--13:12:16--  http://cdn.mysql.com//Downloads/MySQL-5.6/mysql-5.6.28.tar.gz[[email protected] ~]# tar -zxvf mysql-5.6.28.tar.gz 2.安装cmake[[email prote

Linux(DeepInOS) 下 mysql 的安装与基本配置

参看代码 GitHub: DeepIn(GNU/Linux) MySQL 一.安装 二.控制台登陆  三.基本编码配置 四.服务操作  五.运行状态基本查看 六.开机自启及服务 蒙 2018-05-05 23:30 周六 原文地址:https://www.cnblogs.com/Meng-NET/p/8996788.html

[Linux]Centos7下mysql小白安装教程

一.工具下载 mysql下载传送门 SecureCRTSecureFX下载传送门 二.上传安装文件 三.查看上传的mysql安装文件 [[email protected] ~]# ls anaconda-ks.cfg MySQL-client-advanced-5.6.22-1.el7.x86_64.rpm MySQL-server-advanced-5.6.22-1.el7.x86_64.rpm 公共 模板 视频 图片 文档 下载 音乐 桌面 四.安装perl [[email protecte

Linux 操作系统下,安装软件 apt-get、yum 的区别

Linux 操作系统主要分为两大类: RedHat系列:Redhat.Centos.Fedora等: Debian系列:Debian.Ubuntu等. yum(Yellow dog Updater, Modified)是 RedHat 系列 Linux 操作系统下的软件安装方式. apt-get(apt:Advanced Packaging Tool)是 Ubuntu 下的一个软件安装方式,它是基于 Debian 的. 原文地址:https://www.cnblogs.com/cag2050/p

(0.2.3)Linux平台下二进制方式安装mysql

本章节:二进制安装mysql 目录: 1.基于Linux平台的Mysql项目场景介绍 2.mysql数据库运行环境准备-最优配置 3.如何下载mysql数据库 4.linux平台下二进制文件方式安装mysql 4.1.环境检查(libaio包) 4.2.安装过程 (1)下载文件.上传安装程序 (2)创建用户,组,创建目录 (3)解压安装程序包 (4)修改权限(授权用户对解压目录的权限) (5)配置环境变量(以便可以直接运行mysql命令) (6)准备参数配置文件 (7)开始初始化Mysql (8