1. Trang chủ
  2. » Công Nghệ Thông Tin

Tài liệu MySQL Administrator''''s Bible- P2 docx

50 439 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 50
Dung lượng 1,2 MB

Nội dung

Installing and Upgrading MySQL Server 2 To install the pkg file you will need to run pkgadd -d file.pkg with root privileges. You can list multiple packages separated by spaces and rpm will install them at the same time: shell> pkg -d mysql-VERSION.PLATFORM-PROCESSOR.pkg The following shows an example with the start of the package installation: shell> pkgadd -d mysql-6.0.8-alpha-solaris10-x86_64.pkg The following packages are available: 1 mysql MySQL Community Server (GPL) 6.0.8 Select package(s) you wish to process (or ’all’ to process all packages). (default: all) [?,??,q]: 1 Processing package instance <mysql> from </export/home/user/mysql-6.0.8-alpha-solaris10-x86_64.pkg> MySQL Community Server (GPL) 6.0.8 Copyright (C) 2000-2005 MySQL AB & MySQL Finland AB & TCX DataKonsult AB The selected base directory </opt/mysql> must exist before installation is attempted. Do you want this directory created now [y,n,?,q] y Using </opt/mysql> as the package base directory. ## Processing package information. ## Processing system information. ## Verifying disk space requirements. ## Checking for conflicts with packages already installed. ## Checking for setuid/setgid programs. This package contains scripts which will be executed with super-user permission during the process of installing this package. Do you want to continue with the installation of <mysql> [y,n,?] y Installing MySQL Community Server (GPL) as <mysql> The package places the data files in the data directory, which is /var/lib/mysql by default. This can be somewhat confusing because the base directory defaults to /opt/mysql/mysql.In addition both the pid file and error log are in the data directory. Once installation is complete you will need to perform post-installation configuration, which is covered in the ‘‘Initial Config- uration’’ section later in the chapter. 17 Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. Part I First Steps with MySQL Installing from an archive package on Unix A common installation method is to use the compressed archive distributions provided for various platforms. MySQL archive binary distributions have names of the form mysql-VERSION-OS.tar.gz,whereVERSION is a number (for example, 6.0.8), and OS indicates the type of operating system for which the distribution is intended (for example, pc-linux-i686). The Solaris version of tar does not work with filenames longer than 138 char- acters. If this is a problem, use GNU tar (gtar) to unpack the distribution. You can find a precompiled copy of gtar for Solaris at http://dev.mysql.com/downloads/ os-solaris.html. When installing MySQL Server on Unix using the archive package you should perform the fol- lowing steps: 1. Create a backup of your installation. How to perform backups is covered in Chapter 13, ‘‘Backups and Recovery.’’ 2. Add a mysql user and group mysqld to run the mysqld binary: shell> groupadd mysql shell> useradd -g mysql mysql The exact syntax for useradd and groupadd may vary slightly on different versions of Unix. Some versions of Unix utilize other commands such as adduser and addgroup to accomplish the same task. 3. Download the archive package from http://dev.mysql.com into the directory where you want to install the server files. It is common to use the /usr/local directory and we use this directory for the example. 4. Unpack the archive to create the distribution directory ( /usr/local/mysql- version-OS ). The following command both unzips and extracts the files from the compressed tar archive: shell> tar zxvf mysql-version-OS.tar.gz Take a few minutes to take a look at the layout of the directory that you just extracted. The MySQL Server 6.0.8 archive package contains ten directories. Table 2-2 lists these directories and briefly describes their contents. 5. Create a symbolic link from this new directory to /usr/local/mysql: shell> ln –s /usr/local/mysql-version-OS /usr/local/mysql This means you refer to the installation directory as /usr/local/mysql.Ifyou upgrade to a newer version of the server later, you can change the symbolic link and all directory paths will still be accurate. For example, if your installation directory is /usr/local/mysql-6.0.8-alpha-solaris10-x86_64: 18 Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. Installing and Upgrading MySQL Server 2 shell> ln –s /usr/local/mysql-6.0.8-alpha-solaris10-x86_64 /usr/local/mysql You can refer to the mysql client using the path /usr/local/mysql/bin/mysql. When it is time to upgrade you can unpack a new distribution to /usr/local/mysql- 6.0.9-alpha-solaris10 — x86_64 and change the link as follows: shell> rm /usr/local/mysql shell> ln –s /usr/local/mysql-6.0.9-alpha-solaris10-x86_64 /usr/local/mysql The mysql client binary will still be located at /usr/local/mysql/bin/mysql. TABLE 2-2 MySQL Server Archive Package Directories Directory Name Description bin Binary files for the server binaries and client programs such as the mysql command-line client, mysqldump,andmysqladmin data Databases and database data and index files include Header files lib Compiled libraries man Man pages mysql-test Test suite for testing MySQL Server scripts Contains the script used to initialize a new installation share Language support for messages such as errors sql-bench Benchmarking test program files support-files Example configurations and scripts for log rotation and starting MySQL Server 6. Change to the installation directory: shell> cd /usr/local/mysql 7. Create the data directory and initialize the system tables: shell> scripts/mysql_install_db user=mysql 19 Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. Part I First Steps with MySQL 8. Ensure that the distribution contents are accessible to the mysql user. This was done if you unpacked the distribution as the mysql user. If you unpacked the distribution as any user other than mysql the contents will be owned by that user. You will need to change ownership to the mysql user by executing the fol- lowing commands as root in the installation directory: shell> chown -R mysql:mysql /usr/local/mysql 9. To configure mysqld for automatic startup when the host server is started you must copy the support-files/mysql.server file to the location where your system has its startup files. This is typically /etc/init.d. In addition you will have to create the appropriate links to run levels for automatically starting and stopping the server. This is covered in the section ‘‘Starting and stopping mysqld on System V-based Unix’’ later in the chapter. 10. At this point you are ready to begin the server. You can start mysqld manually using the following command: shell> bin/mysqld_safe user=mysql group=mysql & The user option allows you to begin the MySQL daemon running under a username other than the account you are logged in under. Files created by mysqld will be owned by the user and group specified by the user and group options. In the preceding example the user that the daemon runs under is the mysql user. We recommend starting mysqld_safe as the root operating system user with the user and group options as in the preceding code. The mysqld_safe process will be owned by root, and the mysqld process will be owned by the mysql user. The mysqld process will inherit important limits from the mysqld_safe process such as the limit in the number of open files. The mysqld binary itself should be run as the mysql user, which is why the user option is so important. If the mysqld_safe command fails and prints mysqld ended there will be some information written in the error log host_name.err located in the data directory. This information is useful for troubleshooting. MySQL Server Installation on Windows On Windows, the MySQL server daemon is the mysqld.exe binary. We will refer to mysqld as the server binary throughout this book; if you are on Windows you can run mysqld.exe with- out the .exe extension — just use mysqld. The MySQL server daemon runs on a variety of Microsoft operating systems including Windows Server 2008, Windows Server 2003, and Windows Vista, XP, and 2000. There are 32-bit and 64-bit binaries available. 20 Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. Installing and Upgrading MySQL Server 2 MySQL for Windows is available in several distribution formats: a source code version, which we do not cover, two packages containing a setup program that installs and configures every- thing needed, and a compressed archive that you unpack in the installation location and man- ually configure. The binary packages are listed here: ■ Essentials package: This package contains both the Installation and Configuration Wiz- ards along with the essentials needed to install the mysqld.exe binary. We recommend using this package to install, unless you need a particular component in the Complete package. ■ Complete package: This package contains everything in the Essentials package, and adds optional components like the embedded server and benchmark suite. For most server installations these optional components are not necessary. ■ Noinstall archive: This package must be manually installed and configured. It does not contain the Installation and Configuration Wizards. Otherwise, it contains all the files found in the Complete install package. Only those who have unusual needs should use the Noinstall package. As an example, if you need to install multiple instances of mysqld on asinglehostserveryouwillneedtousetheNoinstall package. Multiple instances config- uration is not covered in either the Essentials or Complete package and must be manually configured. You must install MySQL on Windows using an account that has administrator rights, or there will be problems with the installation. MySQL does not need to be started by a user with admin- istrator privileges. The installer packages make installation easier than the archive package. The installer packages use an Installation Wizard to install the server binary, and a Configuration Wizard to create an option file, create the initial user accounts, and start the server. Installing MySQL from the installation packages on Windows The wizard-driven Essentials and Complete package installations are the most common way to install MySQL on Windows. How you start the wizards depends on which installation package you download. To begin installation, double-click either the extracted setup.exe file (extracted from the Complete package .zip file) or the msi file (Essentials package). When beginning the installation from the Essentials or Complete packages you must first deter- mine what installation type you wish to perform. Three installation types are available: Typical, Complete, and Custom: ■ Typical installation will install the MySQL Server and the various command-line utilities. ■ Complete installation installs all components in the installation package. The full package includes the embedded server library, a benchmark suite, support programs, and docu- mentation. 21 Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. Part I First Steps with MySQL ■ Custom installation will give you complete control over the packages installed and the location of the files installed. If you choose either the Typical or Complete installation types and click the Next button, you will advance to a verification screen and begin the installation after verifying that you want to install. If you choose the Custom installation type and click the Next button you will advance to the Custom Installation screen. On the Custom Installation screen there is a listing of all components displayed on the left. Components not selected for installation have a red X icon beside the component name. Components selected for installation have a gray icon. To change the installation state of a component click that component’s icon and choose a new option from the drop-down list that appears. Figure 2-1 shows what the Custom Installation screen looks like. FIGURE 2-1 To change the installation path of the server, click the Change button on the right side of the screen across from the currently configured install path. Once you are done choosing the components you want installed and selecting the installation path, click the Next button to advance to the Verification screen. On this screen you can review your current selections and click the Install button if everything is correct. To make changes to the settings click the Back button to return to the previous screen. The Cancel button can be used to exit the Installation Wizard without performing any installation activities. 22 Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. Installing and Upgrading MySQL Server 2 The final screen of the Installation Wizard provides a summary of the installation and gives you the option to launch the MySQL Configuration Wizard. This wizard allows you to create a con- figuration file, install the MySQL service, and configure security settings. Initial configuration of MySQL on Windows On the Windows platform the configuration file is named my.ini and by default is placed in the installation directory. The Configuration Wizard creates a custom my.ini file by asking questions in a series of screens and creating the configuration file based on the answers you provide. When you start the MySQL Configuration Wizard for a new MySQL installation the Configura- tion Type screen is shown. Two configuration types are available: Detailed Configuration and Standard Configuration. The Standard Configuration option is for new users to get started quickly. The Detailed Configura- tion option is for more control over the configuration. For more information on the Detailed Configuration option, see the ‘‘Detailed Configuration’’ section later in this chapter. If this is your first time installing MySQL, choose the Standard Configuration option. The MySQL Configuration Wizard will automatically configure all options except for the Service Options and Security Options. Service Options screen The MySQL Configuration Wizard installs mysqld as a service named MySQL by default. This service is configured to launch when the machine boots up. If you do not wish to install the service, uncheck the box next to Install As Windows Service. The service name can be changed by selecting a new one from the drop-down box or by typing a new service name into the drop-down box. If you wish to install the service but do not want it to launch when the machine boots up, uncheck the box next to ‘‘Launch the MySQL Server Automatically’’. Security Options screen By default, the MySQL Configuration Wizard requires you to set a password for the root user- name. You can bypass this requirement by unchecking the box next to Modify Security Settings. It is not a good idea from a security perspective to bypass this requirement. To set the root pass- word, type the password in the New Root Password and Confirm text boxes. To limit root logins to the local host only, check the box next to Root May Only Connect From localhost. To create an anonymous user account, check the box next to Create An Anonymous Account. We do not recommend allowing root connections from hosts other than the local host, nor do we recommend creating an anonymous user. Both decrease security. If you are using the Configuration Wizard to reconfigure an existing machine that already has the root password set, you need to enter in the existing root password into the Current root password box. 23 Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. Part I First Steps with MySQL Confirmation screen In the Confirmation screen you can: ■ Click the Execute button to save the options to a my.ini file. If applicable, the Configu- ration Wizard will create and start a service for MySQL, and apply the root password, root host settings, and anonymous user settings. ■ Go back to a previous screen by clicking the Back button. ■ Cancel configuration without making changes by clicking the Cancel button. After the MySQL Configuration Wizard has completed everything it will display a summary. Click the Finish button to exit the MySQL Configuration Wizard. Installing MySQL from a Noinstall Zip Archive The Noinstall Zip Archive installation is designed to be installed manually. To install the archive you will need to do the following: 1. Make sure that you are logged in as a user with administrator privileges. 2. Extract the Zip archive to an installation location, traditionally C:\mysql. 3. Create a configuration file, if needed. When mysqld.exe starts on Windows, it looks for configuration files in %WINDIR%\my.ini and C:\my.cnf. %WINDIR% is the Windows environment variable for the Windows directory. You can figure out the Windows direc- tory by opening a command shell with Start  Run, typing cmd in the box that appears, clicking Run, and typing the following at the command-line prompt: C:\> echo %WINDIR% To set options in a configuration file, you can create a new file or use one of the sample configuration files that have been extracted to the installation directory — these sam- ple configuration files are named my-small.ini, my-medium.ini, my-large.ini, my-huge.ini,andmy-template.ini. Any text editor (Notepad, Wordpad, and so on) can be used to create and change a configuration file. If you did not install MySQL at C:\mysql in step 2, you will need to set two variables in a my.ini configuration file under the [mysqld] section. Note that directories on Windows can be specified with either forward slashes or backslashes. If you use backslashes they must be escaped with a second backslash. For example, the directory C:\mysql could be written as C:/mysql or it could be written as C:\\mysql. If you installed MySQL at C:\customdir\mysql,yourmy.ini file would contain something similar to this: [mysqld] # basedir should point to the installation directory basedir=C:/customdir/mysql # datadir should point to the data directory. 24 Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. Installing and Upgrading MySQL Server 2 # By default the datadir is in the "Application Data\MySQL" # subdirectory of the home directory of the user running MySQL. # Thus, if the user is CorpUser1, the data directory will be in # C:\Documents and Settings\CorpUser1\Application Data\MySQL datadir= C:\\Documents and Settings\\CorpUser1\\Application Data\MySQL\\data 4. Choose a MySQL server type. For production installations it is recommended to use the mysqld binary. It is compiled with everything necessary to run MySQL server. For devel- opment or test installations, you may want to use the mysqld-debug server type. This binary is complied with extra debugging information. 5. Start mysqld manually, to confirm a successful installation. See the next section, ‘‘Starting and Stopping MySQL from the Windows Command Line,’’ for more information. The accounts that are automatically created have blank passwords. To make your server more secure, set up passwords using the instructions in the section ‘‘Setting Initial Passwords’’ later in this chapter. Starting and stopping MySQL from the Windows command line Once you have installed the server from the archive it is time to start up the server for the first time. If during installation you chose the mysqld server type, you will start the server using the mysqld.exe binary. If you chose the mysqld-debug server type, you will start the server using the mysqld-debug.exe binary. Our examples use the mysqld.exe binary, and an installation directory of C :\Program Files\MySQL\MySQL Server 6.0. If you have MySQL installed in a different location adjust the pathname accordingly. Start the server using the following command at the command-line prompt: C:\> "C:\Program Files\MySQL\MySQL Server 6.0\bin\mysqld" console The console option forces mysqld to display status messages in the window instead of writing them to the error log. This option is just for testing purposes. If you are not testing the mysqld server, it is recommended to start it as a service, not manually from the command line. See the section ‘‘Starting and Stopping MySQL as a Windows Service’’ for information on how to do that. For a server that uses InnoDB, you should see messages similar to these the first time mysqld starts (the pathnames and file sizes may differ): InnoDB: The first specified data file .\ibdata1 did not exist: InnoDB: a new database to be created! 25 Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. Part I First Steps with MySQL 090423 16:55:46 InnoDB: Setting file .\ibdata1 size to 10 MB InnoDB: Database physically writes the file full: wait 090423 16:55:47 InnoDB: Log file .\ib_logfile0 did not exist: new to be created InnoDB: Setting log file .\ib_logfile0 size to 10 MB InnoDB: Database physically writes the file full: wait 090423 16:55:48 InnoDB: Log file .\ib_logfile1 did not exist: new to be created InnoDB: Setting log file .\ib_logfile1 size to 10 MB InnoDB: Database physically writes the file full: wait InnoDB: Doublewrite buffer not found: creating new InnoDB: Doublewrite buffer created InnoDB: Creating foreign key constraint system tables InnoDB: Foreign key constraint system tables created 090423 16:55:50 InnoDB: Started; log sequence number 0 0 090423 16:55:55 [Note] Event Scheduler: Loaded 0 events 090423 16:55:55 [Note] C:\Program Files\MySQL\MySQL Server 6.0\bin\ mysqld: ready for connections. Version: ’6.0.8-alpha-community’ socket: ’’ port: 3306 MySQL Community Server (GPL) If this is not the first time the server has been started, a successful startup will display messages similar to the last four lines. The last two lines indicate that the server is ready for client connections. If mysqld does not start, check the error log to see if there are any messages that indicate the cause of the problem. The error log is located in the data directory ( datadir) by default, and has a filename of hostname.err,wherehostname is the hostname of the machine. The error log path and filename and can be changed by setting the log-error variable in the configuration file. Once the mysqld daemon is started you can stop the server by running the following command: C:\> "C:\Program Files\MySQL\MySQL Server 6.0\bin\mysqladmin" –u root shutdown –p Type the root password followed by pressing the Enter key when prompted. If you have not yet set a root password you can just press the Enter key. If you have not yet set a root password and disabled the anonymous user it would be a good time to do so. The section ‘‘Setting Initial Passwords’’ later in this chapter describes how to do this. Starting and stopping MySQL as a Windows service The recommended method of running mysqld on Windows is to install it as a Windows service. As a Windows service, mysqld can be controlled manually from the command line or 26 Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. [...]... Files \MySQL\ MySQL Server 6.0\bin\mysqld" install This command installs the service so that it starts and stops automatically when Windows starts or stops By default, the service name is MySQL If you want to use a different service name, specify the service name after the install option To give mysqld a service name of mysql6 0, run: C:\> "C:\Program Files \MySQL\ MySQL Server 6.0\bin\mysqld" -install mysql6 0... and Unix-based systems The MySQL configuration file is used for many MySQL programs, including mysqld This centralized configuration file allows control of the behavior and characteristics of MySQL Different MySQL programs use options from different directives in the configuration file For example, mysqld uses options under the [mysqld] directive Client programs such as mysql and mysqladmin use options under... starting mysqld The simplest way is to run mysqld directly from the command line This method works on any operating system Similar to executing the mysqld binary directly is running the mysqld_safe script This script is a wrapper script that is used to call the mysqld binary It will automatically attempt to restart mysqld if mysqld dies The third method of starting a MySQL server is by running the mysql. server... to S94mysqld and K06mysqld This will ensure that the dependency is met — Apache is started after mysqld and killed before mysqld After copying the mysql. server script to /etc/init.d /mysql the following two commands (run as the root operating system user) create the links from /etc/init.d /mysql to the rc3.d and rc0.d directories on Debian or Solaris: # # ln –s /etc/init.d /mysql /etc/rc3.d/S9 9mysql ln... upset customers It is a good idea to back up your old mysqld before installing a newer one For example, if you are using version 6.0.6 and want to upgrade to 6.0.8, rename your current binary from mysqld to mysqld-6.0.6 If your new mysqld does not function properly, shut it down, move the new binary from mysqld to mysqld-6.0.8, move mysqld-6.0.6 to mysqld, and restart Though every effort is made to protect... MySQL service if one was created To remove the MySQL service, use the following command: C:\> mysqld remove 46 Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark Installing and Upgrading MySQL Server If you do not remove an existing MySQL service the Installation Wizard may fail to install the new MySQL service 6 When upgrading from a version older than mysqld 5.1.23 to mysqld... /etc/init.d /mysql stop shell> /etc/init.d /mysql start And if you want to immediately restart the server upon stopping: shell> /etc/init.d /mysql restart You should always run the startup script as the root user, and run mysqld as a non-root user To run mysqld as a specified user you should add an appropriate user option to the [mysqld] directive of an option file: [mysqld] user =mysql 44 Please purchase PDF Split-Merge... clear the buffer mysql> exit Bye shell> mysql -u testuser -ptestuser_password Welcome to the MySQL monitor Commands end with ; or \g Your MySQL connection id is 9 Server version: 6.0.8-alpha MySQL Community Server (GPL) Type ’help;’ or ’\h’ for help Type ’\c’ to clear the buffer mysql> exit Bye shell> 50 Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark Accessing MySQL You can... additional location of a configuration file It is used as an argument when starting the mysqld binary For example: C:\> "C:\Program Files \MySQL\ MySQL Server 6.0\bin\mysqld defaultsextra-file=c: \mysql\ defaults.cnf" 30 Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark Installing and Upgrading MySQL Server Keep your installations as uniform as possible Even if your servers are... /etc/init.d /mysql /etc/rc0.d/K0 1mysql Even if your installation is configured to start and stop automatically it is necessary sometimes to start or stop the server manually This can be done by using the mysql. server script, invoking it with a start or stop argument If you have already copied the mysql. server script to /etc/init.d /mysql as shown previously it can be done like this: shell> /etc/init.d/mysql . and Recovery.’’ 2. Add a mysql user and group mysqld to run the mysqld binary: shell> groupadd mysql shell> useradd -g mysql mysql The exact syntax. –s /usr/local /mysql- 6.0.8-alpha-solaris10-x86_64 /usr/local /mysql You can refer to the mysql client using the path /usr/local /mysql/ bin /mysql. When it

Ngày đăng: 21/01/2014, 13:20

TỪ KHÓA LIÊN QUAN