MySQL admin cookbook : 99 great recipes for mastering MySQL ...

6 downloads 105 Views 197KB Size Report
99 great recipes for mastering MySQL configuration and administration. Daniel Schneller. Udo Schwedt. [packtI. L. PUBLISHING. -J. BIRMINGHAM - MUMBAI ...
MySQL

Admin

Cookbook

99 great recipes for mastering MySQL configuration and administration

Daniel Schneller Udo Schwedt

[packtI L

PUBLISHING

BIRMINGHAM

-

-J

MUMBAI

Table of Contents Preface

1

Chapter 1: Replication

7

Introduction

7

slaves of

Setting

based

up automatically updated SQL dump Setting up automatically updated slaves of a selection of tables based on a SQL dump Setting up automatically updated slaves using data file copy Sharing read load across multiple machines Using replication to provide full-text indexing for InnoDB tables

10

Estimating network and slave I/O load

25

Limiting

network and slave

blackhole

I/O

load in

a server

heavy

on a

write scenarios

using

14 15 19 22

the

storage engine

28

Setting up slaves via network streaming Skipping problematic queries

41

if servers are In sync

48

Checking

Avoiding duplicate

Setting

server

IDs

44

50

up slaves to report custom information about themselves to

the master

Chapter 2: Indexing

52

57

Introduction

57

Adding indexes to tables

63

Adding a fulltext index Creating a normalized text search column Removing indexes from tables Estimating InnoDB index space requirements Using prefix primary keys

66

Choosing InnoDB primary key columns

80

up searches for

Speeding (sub)domains Finding duplicate indexes

69

72 73 77

83

86

Table of Contents

9JL

Chapter 3: Tools

91

Introduction

Transferring

connection settings between different machines

using

a

94

network share

Sorting MySQL GUI Tools' stored connections Automatically creating stored connections

101

98

Adding custom graphs to MySQL Administrator

106

Displaying query results page by page and with scrolling using

the

Information from verbose output

Extracting MySQL command-line

the

using 114

client

default pager

Specifying Using a custom prompt to distinguish connections Encrypting a MySQL server connection with SSH Creating an encrypted MySQL console via SSH Using a PuTTY template connection for SSH secured connections a

Chapter 4: Backing Up and Restoring MySQL Data MySQL Administrator GUI Tool

frontend for backups

Using Copying all data files to a backup location Creating a SQL dump of all databases Creating a SQL dump of specific databases Creating

116 118 121 127 130

135 136

Introduction

a

MySQL 111

command-line client

SQL dump

of

specific

as a

137

141 144 148 150

tables

Compressing SQL dumps on-the-fiy

151

Rotating and purging binary logs Using replication to perform backups without hurting a production system's performance Restoring data from a dump to a previously backed-up state Performing a point-in-time recovery using the binary logs

153

Chapter 5: Managing Data

156 159 163

167

Introduction

167

Exporting data to a simple CSV file Exporting data to a custom file format Using stored procedures to export repeatedly

168

Importing

data from a

simple

172

174

CSV file

178

importing data from custom file formats data and

data if it

180 exists

Inserting updating already Inserting data based on existing database content Deleting all data from large tables new

-DO

183 185 188

Table of Contents

Deleting

all but

a

fragment of

a

large table's

data

192

Deleting all data incrementally from large tables

Chapter 6: Monitoring

and

Analyzing

a

197

MySQL Installation

201

Introduction

201

Checking free InnoDB tablespace Establishing alerting mechanisms for

202 low

remaining tablespace

by using triggers Estimating tablespace requirements Identifying and changing MySQL variables Assessing the overall table count

205

Finding the biggest tables

218

Finding all columns with a certain name and/or type Finding all tables referencing each other

220

209 213 217

223

Chapter 7: Configuring MySQL

225

Introduction

226 fixed InnoDB

Setting tablespace Setting up an auto-extending InnoDB tablespace Storing InnoDB data in one file per table Decreasing InnoDB tablespace up a

Enabling

and

226 230 234 236

configuring binary logging

Configuring the

238

InnoDB redo

log and Understanding configuring important MySQL and InnoDB timeout options Adjusting table and database name letter case handling for

240

better platform independence

247

Installing MySQL

as a

Windows service with custom

Running multiple MySQL

server

instances in

Preventing invalid date values from being or

parallel

243

options on a

248

Linux server

DATETIME columns

256

Chapter 8: MySQL User Management

259

Introduction

259

Configuring MySQL Administrator to display global privileges Defining

an

alternative

user

for administrative tasks

Disabling the default accounts Creating a basic user Creating

an

Creating

a

Defining

a

251

stored In DATE

installation

user

read-only account

specific specific

Defining a Allowing access

for

backup user for replication from specific hosts only user

and hosts

261 263 266 268 272 277

281 285 290

on-

Table of Contents

Regaining access to your database in case of lost account information Avoiding plain text passwords in administrative scripts

Chapter

9:

Managing Schemas

297 300

303

Introduction

303

Adding new columns at specific positions Defining a primary key for a table containing (non-unique) Allowing individual INSERT statements with "0" values in auto-incrementlng columns

305 data

308 312

Globally allowing INSERT statements with "0" values in

auto-incrementing columns Choosing a suitable storage engine Improving the performance of ALTER Using

a

stored

procedure

to

313 315

318

TABLE for InnoDB

conditionally

add columns

or

indexes

321

Improving query performance for InnoDB tables with BLOB columns

324

Identifying differences between two schemas Comparing schema revisions using hash values

327 331

Appendix: Good to Know

335

Introduction

335

Avoiding silent replication disruption on full master disk Maximizing usable memory on 32-bit Windows Using separate temporary directories for multiple MySQL on a single machine, preventing conflicts Preventing mysqldump from failing with Error 2013 Non-availability of InnoDB may escape monitoring

336

Troubleshooting "Can't start or

directory"

Understanding

-03

Bind

on

341 342 343

TCP/IP port: No such file 344

error

Choosing character

Index

server:

337 servers

sets

auto-increment values

346 350 353