Linux 平台下 MySQL 5.5 安装 说明 与 示例

 

一.下载说明

前期的一些准备说明,参考:

MySQL 发展史

http://blog.csdn.net/tianlesoftware/article/details/6999245

 

Mysql 不同版本 说明

http://blog.csdn.net/tianlesoftware/article/details/6723117

MySQL 分为Community Server 和 Enterprise Edition。 其中Community Server 可以直接从mysql 的官网下载。Enterprice Edition 只能从Oracle edelivery上下载,不过Edelivery 现在已经屏蔽了中国的IP,如果国内的用户一般不能从edelivery上下载,需要FQ出去才能下载。

 

1.1 官方文档上有关MySQL安装文件类型说明:

       http://dev.mysql.com/doc/refman/5.5/en/index.html

 

Linux supports anumber of different solutions for installing MySQL. The recommended method isto use one of the distributions from Oracle. If you choose this method, thereare three options available:

(1)Installingfrom a generic binary package in .tar.gz format. See Section 2.2,“Installing MySQL from Generic Binaries on Unix/Linux” for moreinformation.

(2)Extractingand compiling MySQL from a source distribution. For detailed instructions,see Section 2.9, “InstallingMySQL from Source”.

(3)Installingusing a pre-compiled RPM package. For more information on using the RPMsolution, see Section 2.5.1,“Installing MySQL from RPM Packages on Linux”.

       --这里讲了3种方式来安装MySQL数据库,我这里用最简单的RPM 包来安装。

 

As analternative, you can use the native package manager within your Linuxdistribution to automatically download and install MySQL for you. Nativepackage installations can take of the download and dependencies required to runMySQL, but the MySQL version will often be some way behind the currentlyavailable release. You will also normally be unable to install developmentalreleases, as these are not usually made available in the native repository. Formore information on using the native package installers, see Section 2.5.2,“Installing MySQL on Linux using Native Package Manager”.

 

Note

For many Linux installations,you will want to set up MySQL to be started automatically when your machinestarts. Many of the native package installations perform this operation foryou, but for source, binary and RPM solutions you may need to set this upseparately. The required script, mysql.server,can be found in the support-filesdirectory under the MySQL installationdirectory or in a MySQL source tree. You can install itas/etc/init.d/mysql for automatic MySQL startup and shutdown. See Section 2.10.1.2,“Starting and Stopping MySQL Automatically”.

       --这里要注意一个问题,就是设置MySQL的自启动。 如果使用native package来安装,会自动设置为自启动,如果使用其他的方式,如source,binary和RPM,就需要单独的来设置自启动。

 

1.2 下载安装包

       我这里下载Community Server 版的,Enterprise Edition版的请到Oracle E-Delivery上下载。Enterprise Edition 有30天的试用期。


  Community Server下载地址:http://www.mysql.com/downloads/mysql/

 

 

这里要注意的,MySQL的Tar 包还是比较大,要比RPM包大3倍左右。

 

MySQL 的RPM 包有如下几个:

 


看一下每个rpm 包具体的描述:

(1)MySQL-server-VERSION.glibc23.i386.rpm

The MySQLserver. You need this unless you only want to connect to a MySQL server runningon another machine.

 

(2)MySQL-client-VERSION.glibc23.i386.rpm

The standardMySQL client programs. You probably always want to install this package.

 

(3)MySQL-devel-VERSION.glibc23.i386.rpm

The librariesand include files that are needed if you want to compile other MySQL clients,such as the Perl modules.

 

(4)MySQL-debuginfo-VERSION.glibc23.i386.rpm

This packagecontains debugging information. debuginfo RPMs are never needed touse MySQL software; this is true both for the server and for client programs.However, they contain additional information that might be needed by a debuggerto analyze a crash.

 

(5)MySQL-shared-VERSION.glibc23.i386.rpm

This packagecontains the shared libraries (libmysqlclient.so*) that certain languages andapplications need to dynamically load and use MySQL. It containssingle-threaded and thread-safe libraries. Prior toMySQL 5.5.6, if you install this package, do not installthe MySQL-shared-compat package.

 

(6)MySQL-shared-compat-VERSION.glibc23.i386.rpm

This packageincludes the shared libraries for MySQL 3.23, 4.0, and so on. It containssingle-threaded and thread-safe libraries. Install this package if you have applicationsinstalled that are dynamically linked against older versions of MySQL but youwant to upgrade to the current version without breaking the librarydependencies. Before MySQL 5.5.6, MySQL-shared-compat also includesthe libraries for the current release, so if you install it, you should notalso install MySQL-shared. As of 5.5.6, MySQL-shared-compat doesnot include the current library version, so there is no conflict.

 

(7)MySQL-embedded-VERSION.glibc23.i386.rpm

The embeddedMySQL server library.

 

(8)MySQL-test-VERSION.glibc23.i386.rpm

This packageincludes the MySQL test suite.

 

(9)MySQL-VERSION.src.rpm

This containsthe source code for all of the previous packages. It can also be used torebuild the RPMs on other architectures (for example, Alpha or SPARC).

 

二. 安装MySQL

2.1 安装说明

(1)MySQL的安装包有很多个,作用也不同,在大多数情况下,只需要安装MySQL-server 和 MySQL-client,其他的包根据需要来安装。

 

(2)The server RPM places data underthe /var/lib/mysql directory. The RPM also creates a login accountfor a user named mysql (if one does not exist) to use for running theMySQL server, and creates the appropriate entries in /etc/init.d/ tostart the server automatically at boot time. (This means that if you haveperformed a previous installation and have made changes to its startup script,you may want to make a copy of the script so that you do not lose it when youinstall a newer RPM.) 

 

(3)During RPM installation, a usernamed mysql and a group named mysql are created on thesystem. This is done using the useradd, groupadd,and usermod commands. Those commands require appropriateadministrative privileges, which is required for locally managed users andgroups (as listed in the /etc/passwd and /etc/groupfiles) by theRPM installation process being run by root.

       --在MySQL 安装时,会创建mysql 用户和mysql组。

 

(4)MySQL 的相关目录说明

/usr/bin : Client programs and scripts    -- mysqladmin mysqldump等命令

/usr/sbin:  The mysqld server

/var/lib/mysql: Log files, databases  --这个目录就是数据库的目录

/usr/share/info: Manual in Info format

/usr/share/man: Unix manual pages

/usr/include/mysql: Include (header) files

/usr/lib/mysql: Libraries

/usr/share/mysql : Miscellaneous support files,including error messages, character set files, sample configuration files, SQLfor database installation

               --mysql.server命令及配置文件

/usr/share/sql-bench: Benchmarks

/etc/rc.d/init.d/: 启动脚本文件mysql的目录

 

2.2 安装

--安装Server端:

[root@rac2 software]# ls

MySQL-client-5.5.15-1.rhel5.x86_64.rpm

MySQL-devel-5.5.15-1.rhel5.x86_64.rpm

MySQL-embedded-5.5.15-1.rhel5.x86_64.rpm

MySQL-server-5.5.15-1.rhel5.x86_64.rpm

MySQL-shared-5.5.15-1.rhel5.x86_64.rpm

MySQL-shared-compat-5.5.15-1.rhel5.x86_64.rpm

MySQL-test-5.5.15-1.rhel5.x86_64.rpm

 

[root@rac2 software]# rpm -ivh MySQL-server-5.5.15-1.rhel5.x86_64.rpm

Preparing...               ########################################### [100%]

  1:MySQL-server          ########################################### [100%]

 

PLEASE REMEMBER TO SET A PASSWORD FOR THEMySQL root USER !

To do so, start the server, then issue thefollowing commands:

 

/usr/bin/mysqladmin -u root password'new-password'

/usr/bin/mysqladmin -u root -h rac2password 'new-password'

 

Alternatively you can run:

/usr/bin/mysql_secure_installation

 

which will also give you the option ofremoving the test

databases and anonymous user created bydefault.  This is

strongly recommended for productionservers.

 

See the manual for more instructions.

 

Please report any problems with the /usr/bin/mysqlbugscript!

 

[root@rac2 software]#

 

--- 安装客户端

[root@rac2 software]# rpm -ivh MySQL-client-5.5.15-1.rhel5.x86_64.rpm

Preparing...               ########################################### [100%]

  1:MySQL-client           ###########################################[100%]

 

2.3 其他操作

2.3.1 查看在时创建的mysql用户和mysql group:

[root@rac2 bin]# cat /etc/passwd|grep mysql

mysql:x:103:106:MySQLserver:/var/lib/mysql:/bin/bash

[root@rac2 bin]# cat /etc/group | grepmysql

mysql:x:106:

 

2.3.2 修改密码

--连接MySQL 报错:

[root@rac2 software]# mysql

ERROR 2002 (HY000): Can't connect to localMySQL server through socket '/var/lib/mysql/mysql.sock' (2)

 

--启动MySQL 后,在连正常:

[root@rac2 ~]# /etc/init.d/mysql start

Starting MySQL...                                          [  OK  ]

[root@rac2 init.d]# mysql

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 1

Server version: 5.5.15 MySQL CommunityServer (GPL)

 

Copyright (c) 2000, 2010, Oracle and/or itsaffiliates. All rights reserved.

 

Oracle is a registered trademark of OracleCorporation and/or its

affiliates. Other names may be trademarksof their respective

owners.

 

Type 'help;' or '\h' for help. Type '\c' toclear the current input statement.

 

mysql>

--注意这里,因为MySQL默认没有密码,所以这里我们没有输入密码就直接连上了。

 

--修改密码,这个是安装Server 中提示的:

[root@rac2 ~]# /usr/bin/mysqladmin -u root password root

[root@rac2 ~]# mysql

ERROR 1045 (28000): Access denied for user'root'@'localhost' (using password: NO)

--修改密码之后,就提示要使用密码了。

 

[root@rac2 ~]# mysql -u root -p

Enter password:

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 5

Server version: 5.5.15 MySQL CommunityServer (GPL)

 

Copyright (c) 2000, 2010, Oracle and/or itsaffiliates. All rights reserved.

 

Oracle is a registered trademark of OracleCorporation and/or its affiliates. Other names may be trademarks of theirrespective owners.

 

Type 'help;' or '\h' for help. Type '\c' toclear the current input statement.

 

mysql>

--输入密码后成功连接。

 

 

2.3.3 查看MySQL端口 3306, 这个是默认端口:

[root@rac2 ~]# netstat -nat|grep 3306

tcp       0      0 192.168.3.100:32842         192.168.3.100:3306          TIME_WAIT  

tcp       0      0 :::3306                     :::*                        LISTEN     

 

2.3.4 设置开机自启动

--查看MySQL 开机自启动设置:

[root@rac2 ~]# chkconfig --list |grep mysql

mysql           0:off   1:off  2:on    3:on    4:on   5:on    6:off

这里的数字分别代表Linux启动的不同模式,3是命令行,5是窗口。

 

--关闭开机自启动

[root@rac2 ~]# chkconfig mysql off

[root@rac2 ~]# chkconfig --list |grep mysql

mysql          0:off   1:off  2:off   3:off   4:off  5:off   6:off

 

--启用开机自启动:

[root@rac2 ~]# chkconfig mysql on

[root@rac2 ~]# chkconfig --list |grep mysql

mysql           0:off   1:off  2:on    3:on    4:on   5:on    6:off

[root@rac2 ~]#

 

--将Mysql 从chkconfig服务里删除:

[root@rac2 ~]# chkconfig --del mysql

[root@rac2 ~]# chkconfig --list |grep mysql

 

--将Mysql 添加到chkconfig里:

[root@rac2 ~]# chkconfig --add mysql      

[root@rac2 ~]# chkconfig --list |grep mysql

mysql           0:off   1:off  2:on    3:on    4:on   5:on    6:off

 

2.4 数据库操作

[root@rac2 ~]# mysql -u root -p

Enter password:

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 6

Server version: 5.5.15 MySQL CommunityServer (GPL)

 

Copyright (c) 2000, 2010, Oracle and/or itsaffiliates. All rights reserved.

 

Oracle is a registered trademark of OracleCorporation and/or its

affiliates. Other names may be trademarksof their respective

owners.

 

Type 'help;' or '\h' for help. Type '\c' toclear the current input statement.

 

--查看已经存在的数据库,这几个是安装时自动创建的

mysql> show databases;

+--------------------+

| Database           |

+--------------------+

| information_schema |

| mysql              |

| performance_schema |

| test               |

+--------------------+

4 rows in set (0.00 sec)

 

--使用mysql 数据库

mysql> use mysql

Reading table information for completion oftable and column names

You can turn off this feature to get aquicker startup with -A

 

Database changed

 

--查看mysql 数据库下面的表

mysql> show tables;

+---------------------------+

| Tables_in_mysql           |

+---------------------------+

| columns_priv              |

| db                        |

| event                     |

| func                      |

| general_log               |

| help_category             |

| help_keyword              |

| help_relation             |

| help_topic                |

| host                      |

| ndb_binlog_index          |

| plugin                    |

| proc                      |

| procs_priv                |

| proxies_priv              |

| servers                   |

| slow_log                  |

| tables_priv               |

| time_zone                 |

| time_zone_leap_second     |

| time_zone_name            |

| time_zone_transition      |

| time_zone_transition_type |

| user                      |

+---------------------------+

24 rows in set (0.01 sec)

 

--创建数据库Dave

mysql> create database dave;

Query OK, 1 row affected (0.01 sec)

 

--在dave 数据库下面创建dave表:

mysql> use dave;

Database changed

mysql> create table dave(id int,namechar(20));

Query OK, 0 rows affected (0.01 sec)

 

--查看dave 表结构:

mysql> desc dave;

+-------+----------+------+-----+---------+-------+

| Field | Type     | Null | Key | Default | Extra |

+-------+----------+------+-----+---------+-------+

| id   | int(11)  | YES  |     | NULL   |       |

| name | char(20) | YES  |     | NULL   |       |

+-------+----------+------+-----+---------+-------+

2 rows in set (0.00 sec)

 

--向dave 表里插入2条记录:

mysql> insert into davevalues(1,'dave');

Query OK, 1 row affected (0.00 sec)

 

mysql> insert into davevalues(2,'anqing');

Query OK, 1 row affected (0.01 sec)

 

mysql> select * from dave;

+------+--------+

| id  | name   |

+------+--------+

|   1 | dave   |

|   2 | anqing |

+------+--------+

2 rows in set (0.00 sec)

 

--update 表:

mysql> update dave set name='david dai'where id=1;

Query OK, 1 row affected (0.01 sec)

Rows matched: 1  Changed: 1 Warnings: 0

 

mysql> select * from dave;

+------+-----------+

| id  | name      |

+------+-----------+

|   1 | david dai |

|   2 | anqing    |

+------+-----------+

2 rows in set (0.00 sec)

 

--drop 表:

mysql> drop table dave;

Query OK, 0 rows affected (0.01 sec)

 

--drop 数据库:

mysql> drop database dave;

Query OK, 0 rows affected (0.00 sec)

 

mysql> show databases;

+--------------------+

| Database           |

+--------------------+

| information_schema |

| mysql              |

| performance_schema |

| test               |

+--------------------+

4 rows in set (0.01 sec)



至此,操作结束。 


 

 

 

 

-------------------------------------------------------------------------------------------------------

版权所有,文章允许转载,但必须以链接方式注明源地址,否则追究法律责任!

Blog:     http://blog.csdn.net/tianlesoftware

Weibo: http://weibo.com/tianlesoftware

Email:   tianlesoftware@gmail.com

Skype: tianlesoftware

 

-------加群需要在备注说明Oracle表空间和数据文件的关系,否则拒绝申请----

DBA1 群:62697716(满);   DBA2 群:62697977(满)  DBA3 群:62697850(满)  

DBA 超级群:63306533(满);  DBA4 群:83829929(满) DBA5群: 142216823(满) 

DBA6 群:158654907(满)   DBA7 群:69087192(满)  DBA8 群:172855474

DBA 超级群2:151508914  DBA9群:102954821     聊天 群:40132017(满)

转载于:https://www.cnblogs.com/springside-example/archive/2011/11/22/2529609.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/377970.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

开始python之旅

接触python缘于工作所需,曾经接触过C、C等语言,对于编程语言在学习上大体是一个套路,当然套路因人而异,适合就好。接下来,我将不断分享python的知识和学习技巧,共同学习。 起源 初识一门语言善于先了解语言…

LeetCode 112. 路径总和 、113. 路径总和 II 思考分析

目录112. 路径总和题目递归解递归解,其他人的解法迭代解,其他人的解法113. 路径总和 II题目递归解递归解,参考别人的思路112. 路径总和 题目 给定一个二叉树和一个目标和,判断该树中是否存在根节点到叶子节点的路径,…

kotlin 查找id_Kotlin程序查找矩阵的转置

kotlin 查找idA transpose of a matrix is simply a flipped version of the original matrix. We can transpose a matrix by switching its rows with its columns 矩阵的转置只是原始矩阵的翻转形式。 我们可以通过切换矩阵的行和列来转置矩阵 Given a matrix, we have to…

[mongodb翻译]分片和故障转移

一个配置恰当的mongodb 分片集群不会有单点失效。 本章节描述了集群服务器中可能出现的故障,及相应的对策。 1. 某个mongos路由进程故障 每一个mongos会运行每一台应用服务器上面,该应用服务器只能通过这个mongos进程和集群进行通信。mongos进程不是…

看张子阳的书真是收获很多,也醒悟了很多(一)

摘录: 这是有一次开会时,我的老总跟我们说了这样一个事例:通常来说,医生是很高尚的职业(暂不考虑国内医生的负面新闻),尤其是牙科医生, 他们有着体面的工作并且收入不菲。但是&#…

【C++ grammar】抽象、封装与this指针

目录1、Abstraction and Encapsulation(抽象与封装)1. Data Field Encapsulation (数据域封装)2. Accessor and Mutator (访问器与更改器)2.1. To read/write private data, we need get/set function (为读写私有数据,需要get/set函数)2.2. …

java创建临时文件_用Java创建一个临时文件

java创建临时文件The task is to create a temporary file in Java. 任务是用Java创建一个临时文件。 Creating a temporary file 创建一个临时文件 To create a temporary file in java – we use createTempFile() method of "File" class. The createTempFile()…

十九、图像的形态学操作

一、图像形态学 图像形态学是图像处理学科的一个单独分支学科 主要针对的是灰度图和二值图像 是由数学的集合论以及数学中的拓扑几何原理发展而来 二、膨胀操作(dilate) 33的卷积核 以33为卷积核从左往右(从上往下)开始运行,若这卷积核…

X名称空间(WPF)

笔记简述 闲话x名称空间简要x名称空间的Attributex名称空间的标签扩展x名称空间的XAML指令元素闲话 本笔记参考与《深入浅出WPF》、MSDN、Some Blog… MSDN的飞机票点这里。 x名称空间简要 在VS中新建个WpfApplication都会自动生成xmlns:x"http://schemas.microsoft.com/w…

基于Bresenham和DDA算法画线段

直线:ykxb 为了将他在显示屏上显示出来,我们需要为相应的点赋值,那么考虑到计算机的乘法执行效率,我们肯定不会选择用Ykxb这个表达式求值,然后进行画线段。 我们应当是将它转化为加法运算。 下面提供两种常见的算法&am…

leetcode 106. 从中序与后序遍历序列构造二叉树 105. 从前序与中序遍历序列构造二叉树思考分析

目录1、106题目2、参考思路:递归切割数组3、105题目4、同样思路的代码1、106题目 2、参考思路:递归切割数组 代码参考:公众号:代码随想录 后序数组中序数组 以 后序数组(左右中)的最后一个元素作为切割点,先切中序数组…

按频率对元素进行排序

Prerequisite: 先决条件: Hashing data structure 散列数据结构 How to write user-defined comparator for priority queue STL in C? 如何在C 中为优先级队列STL编写用户定义的比较器? How to sort a map based on values instead of value? 如何根…

二十、分水岭算法

一、基本原理 分水岭算法主要是基于距离变换(distance transform),找到mark一些种子点,从这些种子点出发根据像素梯度变化进行寻找边缘并标记 分水岭:可以简单的理解成一座山,然后来洪水了,水开…

细数WOW里暴雪的“亲儿子”们

. 不知何时,魔兽世界的词汇中忽然出现了一个新玩意:亲儿子。虽说这个称呼现在大多是拿来调侃法爷的,但江山代有儿子出,各领风骚一两天,今天风光无限的法爷们也经历过被其他职业压得抬不起头的小媳妇生涯。那么今天…

Linux下串口ttyS2,ttyS3不能用的问题解决办法

PC104,Xlinux下,突然发现串口3,4不能用。。。 以为是硬件的问题,换成wince后,3,4工作正常,排除电路问题 在linux下查看dmesg: serial8250: ttyS0 at I/O 0x3f8 (irq 4) is a 16550Aserial8250: ttyS1 at I/O 0x2f8 (i…

安卓log.e函数打印示例_log1p()函数以及C ++中的示例

安卓log.e函数打印示例C log1p()函数 (C log1p() function) log1p() function is a library function of cmath header, it is used to get the natural logarithm (the base-e logarithm) of the one plus given value. It accepts a value (float, double, or long double) …

【C++grammar】C++类数据成员的初始化

目录1、类成员的就地初始化example2、构造函数初始化3、默认构造函数:Default Constructor4、举例5、成员的初始化方法的优先级1、类成员的就地初始化example class S { int m 7; // ok, copy-initializes m int n(7); // 错误:不允许用小括号初始化…

二十一、人脸检测

一、识别图像中的人脸 haarcascade_frontalface_alt_tree.xml lbpcascade_frontalcatface.xml GitHub上有Haar级联检测器源代码可自行下载,lbp级联检测器也一样有源码可自行下载 也一样 import cv2 as cv import numpy as npdef face_detect(image):gray cv.cvtC…

aspx特殊符号说明

http://www.cnblogs.com/GnagWang/archive/2010/07/14/1777130.html转载于:https://www.cnblogs.com/mingyongcheng/archive/2011/11/24/2261253.html

javascript运算符_JavaScript中的按位运算符

javascript运算符JavaScript按位运算符 (JavaScript Bitwise Operators) A lot of times you come across some strange operators where youre knocking your head to understand what is going on in the code. Almost all the programming languages have bitwise operators…