1. 程式人生 > >Linux 平臺下 MySQL 5.5 安裝 說明 與 示例

Linux 平臺下 MySQL 5.5 安裝 說明 與 示例

一.下載說明

前期的一些準備說明,參考:

MySQL 分為Community Server 和 Enterprise Edition。 其中Community Server 可以直接從mysql 的官網下載。Enterprice Edition 只能從Oracle edelivery上下載,不過Edelivery 現在已經遮蔽了中國的IP,如果國內的使用者一般不能從edelivery上下載,需要出去才能下載。

1.1 官方文件上有關MySQL安裝檔案型別說明:

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:

(2)Extractingand compiling MySQL from a source distribution. For detailed instructions,seeSection2.9, “InstallingMySQL from Source”.

(3)Installingusing a pre-compiled RPM package. For more information on using the RPMsolution, seeSection2.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

Section2.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 thesupport-filesdirectory under the MySQL installationdirectory or in a MySQL source tree. You can install itas/etc/init.d/mysqlfor automatic MySQL startup and shutdown. SeeSection2.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天的試用期。

這裡要注意的,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.debuginfoRPMs 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 installtheMySQL-shared-compatpackage.

(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-compatalso includesthe libraries for the current release, so if you install it, you should notalso installMySQL-shared. As of 5.5.6,MySQL-shared-compatdoesnot 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/mysqldirectory. The RPM also creates a login accountfor a user namedmysql(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 usernamedmysqland a group namedmysqlare created on thesystem. This is done using theuseradd,groupadd,andusermodcommands. Those commands require appropriateadministrative privileges, which is required for locally managed users andgroups (as listed in the/etc/passwdand/etc/groupfiles) by theRPM installation process being run byroot.

--在MySQL 安裝時,會建立mysql 使用者和mysql組。

(4)MySQL 的相關目錄說明

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

/usr/sbin: Themysqldserver

/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端:

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

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

[[email protected] software]#

--- 安裝客戶端

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

[[email protected] bin]# cat /etc/passwd|grep mysql

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

[[email protected] bin]# cat /etc/group | grepmysql

mysql:x:106:

2.3.2 修改密碼

--連線MySQL 報錯:

[[email protected] software]# mysql

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

--啟動MySQL 後,在連正常:

[[email protected] ~]# /etc/init.d/mysql start

Starting MySQL... [ OK ]

[[email protected] 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 中提示的:

[[email protected] ~]# /usr/bin/mysqladmin -u root password root

[[email protected] ~]# mysql

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

--修改密碼之後,就提示要使用密碼了。

[[email protected] ~]# 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, 這個是預設埠:

[[email protected] ~]# netstat -nat|grep 3306

tcp0 0 192.168.3.100:32842 192.168.3.100:3306 TIME_WAIT

tcp0 0 :::3306 :::* LISTEN

2.3.4 設定開機自啟動

--檢視MySQL 開機自啟動設定:

[[email protected] ~]# chkconfig --list |grep mysql

mysql 0:off 1:off2:on 3:on 4:on5:on 6:off

這裡的數字分別代表Linux啟動的不同模式,3是命令列,5是視窗。

--關閉開機自啟動

[[email protected] ~]# chkconfig mysql off

[[email protected] ~]# chkconfig --list |grep mysql

mysql0:off 1:off2:off 3:off 4:off5:off 6:off

--啟用開機自啟動:

[[email protected] ~]# chkconfig mysql on

[[email protected] ~]# chkconfig --list |grep mysql

mysql 0:off 1:off2:on 3:on 4:on5:on 6:off

[[email protected] ~]#

--將Mysql 從chkconfig服務裡刪除:

[[email protected] ~]# chkconfig --del mysql

[[email protected] ~]# chkconfig --list |grep mysql

--將Mysql 新增到chkconfig裡:

[[email protected] ~]# chkconfig --add mysql

[[email protected] ~]# chkconfig --list |grep mysql

mysql 0:off 1:off2:on 3:on 4:on5:on 6:off

2.4 資料庫操作

[[email protected] ~]# 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: 1Warnings: 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

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(滿)

相關推薦

Linux 臺下 MySQL 5.5 安裝 說明 示例

一.下載說明 前期的一些準備說明,參考: MySQL 分為Community Server 和 Enterprise Edition。 其中Community Server 可以直接從mysql 的官網下載。Enterprice Edition 只能從Oracl

linux臺下(Ubuntu16.04)安裝配置mysql5.7.24)以及圖形管理工具Workbench

1.在ubuntu系統下,開啟終端 方法(1):在左上角的選單上點一下,出來一列,在裡面選擇[附件] 中的[終端],點一下就OK。 方法(2):快捷鍵Ctrl+Alt+T   2.安裝MySQL5.7需要的依賴,使用命令: sudo apt-get install

windows臺下mysql 8.0 免安裝版配置步驟

免安裝版 utf director my.ini 服務 新建 執行 pro name mysql 8.0 免安裝版配置步驟 新建配置文件 my.ini,內容如下 [mysqld] # set basedir to your installation path basedi

windows臺下MySQl安裝、破解和使用

#1、下載:MySQL Community Server 5.7.16   http://dev.mysql.com/downloads/mysql/ #2、解壓   如果想要讓MySQL安裝在指定目錄,那麼就將解壓後的資料夾移動到指定目錄,如:C:\mysql-5.7.16-winx64 #3、新增環境

Linux臺下MongoDB安裝和環境搭建

下載安裝包 上傳伺服器解壓縮 新增db儲存和日誌儲存資料夾 通過ssh登入遠端伺服器 新開一個shell視窗,使用scp將mongodb-linux-x86_64-ubuntu1404-3.4.4.tgz傳送到伺服器的根目錄 使用scp將本地安裝包傳送到伺

Windows臺下MySQL安裝說明

1 安裝前準備 1.1 從MYSQL官網下載MYSQL Server包: 下載MySQL安裝包檔案:http://dev.mysql.com/downloads/mysql/ 比如我需要選擇32位系統的MYSQL安裝包: 推薦選擇ZIP Arch

教程:Linux臺下的Firefox安裝FlashPlugins的通用方法.

去Adobe官方網站下載FlashPlayer的包。 解壓Adobe Flash Player壓縮包:進入到儲存Adobe Flash Player壓縮包的路徑,將壓縮包解壓,使用如下命令: tar -zxvf install_flash_player_11_linux

一個指令碼搞定各linux臺下docker安裝

#!/bin/sh set -e#面試會問這裡為什麼這樣寫? # This script is meant for quick & easy install via: # $ curl -fsSL get.docker.com -o get-d

Linux臺下的core file分析

from obi iic dialog 獲取 命令 server acc head 轉載自CSDN博客:http://blog.csdn.net/gobitan/article/details/5644151 第一步:找到core file是由哪個程序產生的 [[ema

Nginx配置CI框架問題(Linux臺下Centos系統)

項目 末尾 規則 -c 官方文檔 nbsp fas src 路由 CI框架:官方文檔 http://codeigniter.org.cn/user_guide/index.html CI框架的數據流程圖如下: 其中:index.php作為入口文件,在安裝好CI框架後,i

Linux臺下HighgoDB 備份恢復指導手冊

目錄 文件用途 詳細資訊 文件用途 在Linux平臺下,若HGDB資料庫故障,需要恢復。那麼本文件可以幫您完成資料恢復的目的。   詳細資訊 1.備份概述 1.1備份簡介 防止資料丟失的第一道防線就是備份。一個嚴謹的資料庫備份策略,可以在資料庫發生故障或

Linux】【MySQL】CentOS7安裝最新版MySQL8.0.13(最新版MySQL安裝到執行)

  1、前言   框框部落格線上報時:2018-11-07 19:31:06   當前MySQL最新版本:8.0.13 (聽說比5.7快2倍)   官方之前表示:MySQL 8.0 正式版 8.0.11 已釋出,MySQL 8 要比 MySQL 5.7 快 2 倍,還帶來了大量的改

linux臺下C語言按程序名查詢程序號pid

首先建立一個while迴圈可執行檔案 #include <stdio.h> #include <stdlib.h> int main(int argc, char *argv

Linux臺下reSIProcate專案使用

2、執行:" ./configure --prefix=/usr/local/resip " --prefix=/usr/local/resip:的作用是控制生成的Makefile檔案,在後續執行" make install " 時將專案標頭檔案和庫檔案安裝在/usr/

Windows 臺下 Go 語言的安裝和環境變數設定

1. Go 語言 SDK 安裝包下載和安裝 最新穩定版 1.5.3 安裝包 go1.5.3.windows-amd64.msi下載地址 https://golang.org/dl/,大小約 69 MB(作者上傳了一份該版本安裝包到 CSDN 資源,嫌國外網速慢可以去下載:h

Linux臺下Python 指令碼程式設計入門(一)

眾所周知,系統管理員需要精通一門指令碼語言,而且招聘機構列出的職位需求上也會這麼寫。大多數人會認為 Bash (或者其他的 shell 語言)用起來很方便,但一些強大的語言(比如 Python)會給你帶來一些其它的好處。 在 Linux 中學習 Python 指令碼程式設計 首先,我們會使用 Py

Linux 臺下 Python 指令碼程式設計入門(二)

在“Linux 平臺下 Python 指令碼程式設計入門”系列之前的文章裡,我們向你介紹了 Python 的簡介,它的命令列 shell 和 IDLE(LCTT 譯註:python 自帶的一個 IDE)。我們也演示瞭如何進行算術運算、如何在變數中儲存值、還有如何列印那些值到螢幕上。最後,我們通過一

arm Linux臺下SDL及擴充套件庫的移植

  SDL(Simple DirectMedia Layer)是一個自由的跨平臺的多媒體開發包,適用於 遊戲、遊戲SDK、演示軟體、模擬器、MPEG播放器和其他應用軟體。   基於SDL庫目前已提供豐富的函式庫,非常方便開發者使用。常用的如下:     

windows和linux臺下java簡訊貓的配置

Windows配置: 1;插入usb線扣,開啟電腦的裝置管理器,檢視埠下裝置的com(串列埠)是多少,接下來就是配置簡訊貓的必須引數; 2;把需要的包放到專案裡    Jdk下需在jdk(jdk下的jre,非jre下的)/jre/bin/下放這兩個檔案      在jdk(

Linux臺下C++實現的新聞網站

前段時間跟同學一起做了一個簡單的新聞網站,用的C++語言開發的,基於linux作業系統。該新聞網站的搭建包括兩部分內容:前端+後端,前端就是簡單的HTML網頁,後端搭建了多執行緒伺服器,採用的B/S模型。涉及的內容有html頁面,http協議,多執行緒伺服器模型,資料庫,資訊