mysql dba session 3 installing configuring, starting and stopping

29
Session 3. Installing, Configuring, Starting and Stopping RAM N SANGWAN WWW.HOMETUTOR.NET.IN HTTP://YOUTUBE.COM/USER/THESKILLPEDIA 12-Dec-16 R.N. SANGWAN (WWW.RNSANGWAN.COM) 1

Upload: ram-n-sangwan

Post on 12-Apr-2017

78 views

Category:

Education


3 download

TRANSCRIPT

Page 1: MySQL DBA Session 3 installing configuring, starting and stopping

Session 3. Installing, Configuring, Starting and StoppingRAM N SANGWAN

WWW.HOMETUTOR.NET. IN

HT TP://YOUTUBE.COM/USER/THESKILLPEDIA

12-Dec-16 R.N. SANGWAN (WWW.RNSANGWAN.COM) 1

Page 2: MySQL DBA Session 3 installing configuring, starting and stopping

Agenda

• MySQL Distributions• MySQL Binary Distributions

• MySQL Source Distributions

• MySQL Server

• Startup Prerequisites on Unix

• Installation and Server Startup Method on Unix

• Runtime MySQL Configuration

• Log and Status Files

• Logging strategy

12-Dec-16 R.N. SANGWAN (WWW.RNSANGWAN.COM) 2

Page 3: MySQL DBA Session 3 installing configuring, starting and stopping

Agenda Contd..

• The General Query Log

• The Binary Log

• The Slow Query Log

• The Error Log

• Status Files

• Default SQL Mode

• Loading Time Zone Tables

• Security-Related Configuration

• Upgrading MySQL

• Start the new server.

12-Dec-16 R.N. SANGWAN (WWW.RNSANGWAN.COM) 3

Page 4: MySQL DBA Session 3 installing configuring, starting and stopping

MySQL Distributions

• MySQL is available for many operating systems.

• MySQL may be installed from a binary distribution that contains precompiledprograms ready to run.

• MySQL may be compiled from a source distribution to fit into yourrequirement

12-Dec-16 R.N. SANGWAN (WWW.RNSANGWAN.COM) 4

Page 5: MySQL DBA Session 3 installing configuring, starting and stopping

MySQL Binary Distributions

• RPM (Redhat Package Manager) files are available for Linux based systems.(Run #rpm -qpl rpm_file for location of installed files.)

• Packaged tar files are also available for Unix and Unix-like systems.

• To install from a tar file, simply unpack it in the installation directory of yourchoice.

12-Dec-16 R.N. SANGWAN (WWW.RNSANGWAN.COM) 5

Page 6: MySQL DBA Session 3 installing configuring, starting and stopping

MySQL Source Distributions

Why compile MySQL:

• There might be no binary distribution for target platform.

• Requirement of a feature that might not be available in a precompileddistribution.

• Disable a feature that is not required.

• Binary distributions are available only for released versions. If you want torun a server built from the current source, you must compile it yourself.

• You can configure a source distribution to be installed at a location of yourchoice.

12-Dec-16 R.N. SANGWAN (WWW.RNSANGWAN.COM) 6

Page 7: MySQL DBA Session 3 installing configuring, starting and stopping

MySQL on Unix

• On Unix, you should use a dedicated login user and group for administering andrunning MySQL Server so that you can run it with permissions other than thoseof the root login.

12-Dec-16 R.N. SANGWAN (WWW.RNSANGWAN.COM) 7

Page 8: MySQL DBA Session 3 installing configuring, starting and stopping

Installing MySQL

• To install using RPM simple run :rpm –ivh mysql* oryum install mysql*• Sets up a login account with user and group names of mysql.• Also registers a startup script named mysqld in the /etc/init.d directory.• Starts the server.• Setup a data Directory

• With tar file distributions,• Login account is not automatically created.• Data directory is not set up.• You must create the login account and initialize the data directory yourself.

12-Dec-16 R.N. SANGWAN (WWW.RNSANGWAN.COM) 8

Page 9: MySQL DBA Session 3 installing configuring, starting and stopping

Data Directory Initialization

• Run mysql_install_db script:# mysql_install_db

• You can run it as root with the --user=mysql option:# mysql_install_db --user=mysql

• If you do not run this script, the server will complain when you runit later that it cannot find files in the mysql database.

• With a tar file distribution, you'll also need to install a startupscript.

• In any case, the initial MySQL accounts have no passwords.

12-Dec-16 R.N. SANGWAN (WWW.RNSANGWAN.COM) 9

Page 10: MySQL DBA Session 3 installing configuring, starting and stopping

Server Startup Methods on Unix

# service mysqld start.# mysqld_safe: It invokes mysqld and set up the error log, and thenlaunches mysqld and monitors it. If mysqld terminates abnormally, mysqld_saferestarts it.• mysqld_multi is a Perl script intended to make it easier to manage multiple

servers on a single host.• To start mysql server automatically at system startup, install a startup script

under run-level directories (/etc/init.d):# /etc/init.d/mysqld start# /etc/init.d/mysqld stop

• To stop the server manually, use mysqladmin with shutdown command. Itconnects to the server as a client and can shut down local or remote servers.

12-Dec-16 R.N. SANGWAN (WWW.RNSANGWAN.COM) 10

Page 11: MySQL DBA Session 3 installing configuring, starting and stopping

Runtime MySQL Configuration

• Used to tell the server to use different values:

• use a data directory other than the directory named data underthe installation directory, use a --datadir.

• Options to control which log files the server writes.

• Options to override the server's built-in values for performance- relatedvariables.

• To enable or disable storage.

• Several options configure the InnoDB tablespace. If InnoDB is enabled, itcreates a default tablespace in the absence of explicit configuration.

12-Dec-16 R.N. SANGWAN (WWW.RNSANGWAN.COM) 11

Page 12: MySQL DBA Session 3 installing configuring, starting and stopping

Runtime MySQL Configuration

• To list all options the server supports, use:# mysql --verbose --help

• Any of the server options shown in the help message may be specified on thecommand line.

• However, it's more typical to list them in an option file, for several reasons:• You need not specify them on the command line each time you start the

server.

• If you invoke the server using the mysqld startup script, you cannot specifyserver options on the command line.

• If you list all server options in a single option file, you can look at this file tosee immediately how you've configured the server to run.

12-Dec-16 R.N. SANGWAN (WWW.RNSANGWAN.COM) 12

Page 13: MySQL DBA Session 3 installing configuring, starting and stopping

Runtime MySQL Configuration

• When starting a server it look for /etc/my.cnf and $MYSQL_HOME/my.cnf Thesecond file is used only if the MYSQL_HOME environment variable is set.

• If you use the data directory under /var/lib/mysql as the data directory, youcan specify the same as:[mysqld]

datadir=/var/lib/mysql

• To enable logging:[mysqld]

log log-bin log-slow-queries

12-Dec-16 R.N. SANGWAN (WWW.RNSANGWAN.COM) 13

Page 14: MySQL DBA Session 3 installing configuring, starting and stopping

Runtime MySQL Configuration

• To specify a default storage engine:[mysqld]

default-storage-engine=InnoDB

• Option files also can be used to set many server system variable values:[mysqld]

max_connections=200

key_buffer_size=128M

12-Dec-16 R.N. SANGWAN (WWW.RNSANGWAN.COM) 14

Page 15: MySQL DBA Session 3 installing configuring, starting and stopping

Runtime MySQL Configuration

• MySQL distributions contain several sample option files.

• They have names like my-small.cnf and my-large.cnf.

• Likely locations are in /usr/share/mysql for RPM installations orthe share directory under the MySQL installation directory for tar fileinstallations.

12-Dec-16 R.N. SANGWAN (WWW.RNSANGWAN.COM) 15

Page 16: MySQL DBA Session 3 installing configuring, starting and stopping

Log and Status Files

• The logs record various types of information about the SQL statementsprocessed by the server:• The general query log records all statements that the server receives from

clients.

• The binary log records statements that modify data.

• The slow query log contains a record of queries that take a long time toexecute.

• These logs can be used to assess the operational state of the server, for datarecovery after a crash, for replication purposes, and to help you determinewhich queries are running slowly.

12-Dec-16 R.N. SANGWAN (WWW.RNSANGWAN.COM) 16

Page 17: MySQL DBA Session 3 installing configuring, starting and stopping

Recommended Logging Strategy

• Enable the general query log, the binary log, and the slow query log whenyou set up a server initially.

• After the server has been configured and you have verified that it is runningsmoothly, disable the general query log to save disk space.

• All logs are written in text format except for the binary log which is a binary file.

• When the server logs statements to the binary log and slow query log, it writesextra information.

• To suppress the extra information, start the server with the --log-short-format option.

12-Dec-16 R.N. SANGWAN (WWW.RNSANGWAN.COM) 17

Page 18: MySQL DBA Session 3 installing configuring, starting and stopping

The General Query Log

• Contains a record of when clients connect and disconnect, and the text ofevery SQL statement received by the server.

• To enable the general query log, use the --log or --log= file_name option.

• If no filename is given, the default name is host_name.log.

• By default, the server creates the general query log file under the datadirectory unless you specify an absolute pathname.

12-Dec-16 R.N. SANGWAN (WWW.RNSANGWAN.COM) 18

Page 19: MySQL DBA Session 3 installing configuring, starting and stopping

The Binary Log

• The binary log contains a record of statements that modify data.

• This log is stored in binary format, but its contents can be viewed usingthe mysqlbinlog utility.

• To enable the binary log, use the --log-bin or --log-bin=file_name option.

• By default, the server creates the binary log files under the datadirectory unless you specify an absolute pathname.

• By default, the name of the index file is the same as the binary log basename,with a suffix of .index

• To specify the name explicitly, use a --log-bin-index=file_name option.

12-Dec-16 R.N. SANGWAN (WWW.RNSANGWAN.COM) 19

Page 20: MySQL DBA Session 3 installing configuring, starting and stopping

The Slow Query Log

• The slow query log contains the text of queries that take a long time toexecute.

• By default, "a long time" is more than 10 seconds.

• To enable the slow query log, use the --log-slow-queries or --log-slow-queries=file_name option.

• If no filename is given, the default name is host_name-slow.log.

• By default, the server creates the slow query log file under the datadirectory unless you specify an absolute pathname.

• To log queries that are not processed with the benefit of indexes, use the --log-queries-not-using-indexes option.

12-Dec-16 R.N. SANGWAN (WWW.RNSANGWAN.COM) 20

Page 21: MySQL DBA Session 3 installing configuring, starting and stopping

The Error Log

• The server produces diagnostic messages about normal startupsand shutdowns, as well as about abnormal conditions:

• If you invoke mysqld directly, it sends diagnostics to its standard error output,which normally is your terminal.

• You can start the server with a --log-error=file_name option.

• The default error log name is host_name.err in the server's data directory.

12-Dec-16 R.N. SANGWAN (WWW.RNSANGWAN.COM) 21

Page 22: MySQL DBA Session 3 installing configuring, starting and stopping

Status Files

• The server creates several status files. Some of these are located in the datadirectory by default.

• The server records its process ID in a PID file, for use by other programs thatneed to send the server a signal.

• The default PID filename is host_name.pid in the data directory. The name andlocation may be changed with the --pid-file=file_name option.

• Unix servers create a Unix socket file so that local clients can establish socketconnections. By default, this file is /tmp/mysql.sock.

12-Dec-16 R.N. SANGWAN (WWW.RNSANGWAN.COM) 22

Page 23: MySQL DBA Session 3 installing configuring, starting and stopping

SQL Mode

• MySQL Server has a configurable SQL mode that provides control over aspectsof query processing such as how strict or forgiving the server is aboutaccepting input data.

• By no special restrictions or conformance behaviors are enabled.Individual clients can configure the SQL mode for their own requirements, butit's also possible to set the default SQL mode at server startup with the --sql-mode option.

• If you enable TRADITIONAL mode, the server enforces restrictions on inputdata values that are like other database servers, rather than MySQL's moreforgiving behavior.

12-Dec-16 R.N. SANGWAN (WWW.RNSANGWAN.COM) 23

Page 24: MySQL DBA Session 3 installing configuring, starting and stopping

SQL Mode Contd..

• It will also not allow new user accounts to be created with

the GRANT statement unless a password is specified. You can enable

TRADITIONAL SQL mode by placing the following lines in an option file:

[mysqld]

sql-mode=TRADITIONAL

12-Dec-16 R.N. SANGWAN (WWW.RNSANGWAN.COM) 24

Page 25: MySQL DBA Session 3 installing configuring, starting and stopping

Time Zone Tables

The MySQL installation procedure creates a set of time zone tables in the mysql database:

• Created when mysql_install_db is executed.

• The server uses the time zone tables to implement support for named time zones such as'Europe/Warsaw'.

• On operating systems that have their own time zone files, it is best to use them for loadingthe MySQL time zone tables. Many Unix systems have these files, often locatedunder/usr/share/zoneinfo.

• For such systems, use the mysql_tzinfo_to_sql program to convert the file contents into SQLstatements that can be loaded into MySQL by the mysql program. If the files are locatedat /usr/share/zoneinfo:

# mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root mysql

12-Dec-16 R.N. SANGWAN (WWW.RNSANGWAN.COM) 25

Page 26: MySQL DBA Session 3 installing configuring, starting and stopping

Security-Related Configuration

• Two procedures:◦ to set passwords for the initial MySQL accounts that are stored in the grant

tables of the mysql database, and

◦ to make sure that filesystem permissions for the components ofyour installation do not allow access to anyone but the MySQL administrativelogin account.

• If all clients are local clients, you can disable connections fromremote clients by starting the server with the --skip-networking.

12-Dec-16 R.N. SANGWAN (WWW.RNSANGWAN.COM) 26

Page 27: MySQL DBA Session 3 installing configuring, starting and stopping

Upgrading MySQL

• Check the MySQL Reference Manual before performing any upgrade:

• Always consult the section on upgrading to see whether there are any notespertaining to the type of upgrade you're performing.

• Check the change note sections for versions more recent than your currentversion to make sure that you're aware of what has changed since your originalinstall.

• Generally upgrading MySQL usually is straight forward procedure:

◦ Back up your databases.

◦ Stop the server.

◦ Install the new version of MySQL on top of the existing version.

12-Dec-16 R.N. SANGWAN (WWW.RNSANGWAN.COM) 27

Page 28: MySQL DBA Session 3 installing configuring, starting and stopping

Upgrading MySQL

• If you install a new version of MySQL on top of an existing one, you might notneed to do much reconfiguring.

• If you upgrade MySQL using a tar file, the new distribution likely will createa new version-specific base installation directory that differs from your existinginstallation directory. In this case, some reconfiguration might be necessary.

• If you have a symbolic link set up that points to the old installation directory,you can delete the link and re-create it to point to the new installationdirectory.

12-Dec-16 R.N. SANGWAN (WWW.RNSANGWAN.COM) 28

Page 29: MySQL DBA Session 3 installing configuring, starting and stopping

Thank YouFor corporate training needs visit www.rnsangwan.com

Subscribe my channel https://youtube.com/user/TheSkil lPedia

12-Dec-16 R.N. SANGWAN (WWW.RNSANGWAN.COM) 29