LINUX MYSQL INSTALL

2.9. Installing MySQL from tar.gz Packages on Other Unix-Like Systems

This section covers the installation of MySQL binary distributions that are provided for various platforms in the form of compressed tar files (files with a .tar.gz extension). See Section 2.1.2.4, “MySQL Binaries Compiled by Sun Microsystems, Inc.”, for a detailed list.

To obtain MySQL, see Section 2.1.3, “How to Get MySQL”.

MySQL tar file binary distributions have names of the form mysql-VERSION-OS.tar.gz, where VERSION is a number (for example, 5.1.39), and OS indicates the type of operating system for which the distribution is intended (for example, pc-linux-i686).

In addition to these generic packages, we also offer binaries in platform-specific package formats for selected platforms. See Section 2.2, “Standard MySQL Installation Using a Binary Distribution”, for more information on how to install these.

You need the following tools to install a MySQL tar file binary distribution:

GNU gunzip to uncompress the distribution.

A reasonable tar to unpack the distribution. GNU tar is known to work. Some operating systems come with a preinstalled version of tar that is known to have problems. For example, the tar provided with early versions of Mac OS X, SunOS 4.x, Solaris 8, Solaris 9, Solaris 10 and OpenSolaris, and HP-UX are known to have problems with long file names. On Mac OS X, you can use the preinstalled gnutar program. On Solaris 10 and OpenSolaris you can use the preinstalled gtar. On other systems with a deficient tar, you should install GNU tar first.

If you run into problems and need to file a bug report, please use the instructions in Section 1.6, “How to Report Bugs or Problems”.

The basic commands that you must execute to install and use a MySQL binary distribution are:
shell> groupadd mysql
shell> useradd -g mysql mysql
shell> cd /usr/local
shell> gunzip < /path/to/mysql-VERSION-OS.tar.gz | tar xvf -
shell> ln -s full-path-to-mysql-VERSION-OS mysql
shell> cd mysql
shell> chown -R mysql .
shell> chgrp -R mysql .
shell> scripts/mysql_install_db --user=mysql
shell> chown -R root .
shell> chown -R mysql data
shell> bin/mysqld_safe --user=mysql &
Note

This procedure does not set up any passwords for MySQL accounts. After following the procedure, proceed to Section 2.11, “Post-Installation Setup and Testing”.

A more detailed version of the preceding description for installing a binary distribution follows:

Add a login user and group for mysqld to run as:
shell> groupadd mysql
shell> useradd -g mysql mysql

These commands add the mysql group and the mysql user. The syntax for useradd and groupadd may differ slightly on different versions of Unix, or they may have different names such as adduser and addgroup.

You might want to call the user and group something else instead of mysql. If so, substitute the appropriate name in the following steps.

Pick the directory under which you want to unpack the distribution and change location into it. In the following example, we unpack the distribution under /usr/local. (The instructions, therefore, assume that you have permission to create files and directories in /usr/local. If that directory is protected, you must perform the installation as root.)
shell> cd /usr/local

Obtain a distribution file using the instructions in Section 2.1.3, “How to Get MySQL”. For a given release, binary distributions for all platforms are built from the same MySQL source distribution.

Unpack the distribution, which creates the installation directory. Then create a symbolic link to that directory:
shell> gunzip < /path/to/mysql-VERSION-OS.tar.gz | tar xvf -
shell> ln -s full-path-to-mysql-VERSION-OS mysql

The tar command creates a directory named mysql-VERSION-OS. The ln command makes a symbolic link to that directory. This lets you refer more easily to the installation directory as /usr/local/mysql.

With GNU tar, no separate invocation of gunzip is necessary. You can replace the first line with the following alternative command to uncompress and extract the distribution:
shell> tar zxvf /path/to/mysql-VERSION-OS.tar.gz

Change location into the installation directory:
shell> cd mysql

You will find several files and subdirectories in the mysql directory. The most important for installation purposes are the bin and scripts subdirectories:

The bin directory contains client programs and the server. You should add the full path name of this directory to your PATH environment variable so that your shell finds the MySQL programs properly. See Section 2.14, “Environment Variables”.

The scripts directory contains the mysql_install_db script used to initialize the mysql database containing the grant tables that store the server access permissions.

Ensure that the distribution contents are accessible to mysql. If you unpacked the distribution as mysql, no further action is required. If you unpacked the distribution as root, its contents will be owned by root. Change its ownership to mysql by executing the following commands as root in the installation directory:
shell> chown -R mysql .
shell> chgrp -R mysql .

The first command changes the owner attribute of the files to the mysql user. The second changes the group attribute to the mysql group.

If you have not installed MySQL before, you must create the MySQL data directory and initialize the grant tables:
shell> scripts/mysql_install_db --user=mysql

If you run the command as root, include the --user option as shown. If you run the command while logged in as that user, you can omit the --user option.

The command should create the data directory and its contents with mysql as the owner.

After creating or updating the grant tables, you need to restart the server manually.

Most of the MySQL installation can be owned by root if you like. The exception is that the data directory must be owned by mysql. To accomplish this, run the following commands as root in the installation directory:
shell> chown -R root .
shell> chown -R mysql data

If you want MySQL to start automatically when you boot your machine, you can copy support-files/mysql.server to the location where your system has its startup files. More information can be found in the support-files/mysql.server script itself and in Section 2.11.2.2, “Starting and Stopping MySQL Automatically”.

You can set up new accounts using the bin/mysql_setpermission script if you install the DBI and DBD::mysql Perl modules. See Section 4.6.14, “mysql_setpermission — Interactively Set Permissions in Grant Tables”. For Perl module installation instructions, see Section 2.15, “Perl Installation Notes”.

If you would like to use mysqlaccess and have the MySQL distribution in some nonstandard location, you must change the location where mysqlaccess expects to find the mysql client. Edit the bin/mysqlaccess script at approximately line 18. Search for a line that looks like this:
$MYSQL     = '/usr/local/bin/mysql';    # path to mysql executable

Change the path to reflect the location where mysql actually is stored on your system. If you do not do this, a Broken pipe error will occur when you run mysqlaccess.

After everything has been unpacked and installed, you should test your distribution. To start the MySQL server, use the following command:
shell> bin/mysqld_safe --user=mysql &

If you run the command as root, you must use the --user option as shown. The value of the option is the name of the login account that you created in the first step to use for running the server. If you run the command while logged in as mysql, you can omit the --user option.

If the command fails immediately and prints mysqld ended, you can find some information in the host_name.err file in the data directory.

More information about mysqld_safe is given in Section 4.3.2, “mysqld_safe — MySQL Server Startup Script”.
Note

The accounts that are listed in the MySQL grant tables initially have no passwords. After starting the server, you should set up passwords for them using the instructions in Section 2.11, “Post-Installation Setup and Testing”.
Previous / Next / Up / Table of Contents

User Comments
================================================================================================
Installing MySQL system tables...
090830  0:33:33 [Warning] option 'thread_stack': unsigned value 126976 adjusted to 131072
OK
Filling help tables...
090830  0:33:33 [Warning] option 'thread_stack': unsigned value 126976 adjusted to 131072
OK

To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:
./bin/mysqladmin -u root password 'new-password'
./bin/mysqladmin -u root -h box password 'new-password'

Alternatively you can run:
./bin/mysql_secure_installation

which will also give you the option of removing the test
databases and anonymous user created by default.  This is
strongly recommended for production servers.

See the manual for more instructions.

You can start the MySQL daemon with:
cd . ; ./bin/mysqld_safe &

You can test the MySQL daemon with mysql-test-run.pl
cd mysql-test ; perl mysql-test-run.pl

Please report any problems with the ./bin/mysqlbug script!

The latest information about MySQL is available on the web at
http://www.mysql.com
Support MySQL by buying support/licenses at http://shop.mysql.com
==============================================================================================
mysql> CREATE USER 'monty'@'localhost' IDENTIFIED BY 'some_pass';
mysql> GRANT ALL PRIVILEGES ON *.* TO 'monty'@'localhost'
    ->     WITH GRANT OPTION;
mysql> CREATE USER 'monty'@'%' IDENTIFIED BY 'some_pass';
mysql> GRANT ALL PRIVILEGES ON *.* TO 'monty'@'%'
    ->     WITH GRANT OPTION;
===============================================================================================
16 Replication
16.1 Replication Configuration
16.1.1 How to Set Up Replication
16.1.1.1. Creating a User for Replication
mysql> GRANT REPLICATION SLAVE ON *.* TO 'repl'@'%.mydomain.com' IDENTIFIED BY 'slavepass';
16.1.1.2. Setting the Replication Master Configuration
    [mysqld]
log-bin=mysql-bin
server-id=1
16.1.1.3. Setting the Replication Slave Configuration
[mysqld]
server-id=2
16.1.1.4. Obtaining the Master Replication Information
mysql > SHOW MASTER STATUS;
16.1.1.5. Creating a Data Snapshot Using mysqldump
mysql> FLUSH TABLES WITH READ LOCK;
shell> mysqldump --all-databases --lock-all-tables >dbdump.db
shell> mysqldump --all-databases --master-data >dbdump.db
mysql> UNLOCK TABLES;
16.1.1.10. Setting the Master Configuration on the Slave
mysql> CHANGE MASTER TO
->     MASTER_HOST='master_host_name',
->     MASTER_USER='replication_user_name',
->     MASTER_PASSWORD='replication_password',
->     MASTER_LOG_FILE='recorded_log_file_name',
->     MASTER_LOG_POS=recorded_log_position;
16.1.4.1. Checking Replication Status
the primary statement for this is SHOW SLAVE STATUS which you must execute on each slave:
mysql> SHOW SLAVE STATUS\G
On the master, you can check the status of slaves by examining the list of running processes. Slaves execute the Binlog Dump command:
mysql> SHOW PROCESSLIST \G
If you have used the --report-host option, then the SHOW SLAVE HOSTS statement will show basic information about connected slaves:
mysql> SHOW SLAVE HOSTS;
16.1.4.2. Pausing Replication on the Slave
mysql> STOP SLAVE;
mysql> STOP SLAVE IO_THREAD;
To start execution again, use the START SLAVE statement:
mysql> START SLAVE;
16 Replication :: 16.2 Replication Solutions :: 16.2.1 Using Replication for Backups :: 16.2.1.1 Backing Up a Slave Using mysqldump
When using mysqldump you should stop the slave before starting the dump process to ensure that the dump contains a consistent set of data:

(1)Stop the slave from processing requests. You can either stop the slave completely using mysqladmin:
shell> mysqladmin stop-slave

Alternatively, you can stop processing the relay log files by stopping the replication SQL thread. Using this method will allow the binary log data to be transferred. Within busy replication environments this may speed up the catch-up process when you start the slave processing again:
shell> mysql -e 'STOP SLAVE SQL_THREAD;'

(2)Run mysqldump to dump your databases. You may either select databases to be dumped, or dump all databases. For more information, see Section 4.5.4, “mysqldump — A Database Backup Program”. For example, to dump all databases:
shell> mysqldump --all-databases >fulldb.dump

(3)Once the dump has completed, start slave operations again:
shell> mysqladmin start-slave
===============================================================================================
设置MySQL数据同步(单向&双向)
设置MySQL数据同步(单向&双向)

  由于公司的业务需求,需要网通和电信的数据同步,就做了个MySQL的双向同步,记下过程,以后用得到再翻出来,也贴出来供大家参考。

  一、准备服务器

  由于MySQL不同版本之间的(二进制日志)binlog格式可能会不一样,因此最好的搭配组合是Master的MySQL版本和Slave的版本相同或者更低,Master的版本肯定不能高于Slave版本。

  more.. | less.. | 本文中,我们假设主服务器(以下简称Master)和从服务器(以下简称Slave)的版本都是5.0.27,操作系统是RedHat Linux 9。

  假设同步Master的主机名为:A(IP:192.168.0.1),Slave主机名为:B(IP:192.168.0.2),2个MySQL的basedir目录都是/usr/local/mysql,datadir都是:/var/lib/mysql。

  二、设置同步服务器

  1、设置同步Master

  修改 my.cnf 文件,在

  # Replication Master Server (default)

  # binary logging is required for replication

  添加如下内容:

  log-bin=/var/log/mysql/updatelog

  server-id = 1

  binlog-do-db=test

  binlog-ignore-db=mysql

  重启MySQL,创建一个MySQL帐号为同步专用

  GRANT REPLICATION SLAVE,RELOAD,SUPER, ON *.* TO back@192.168.0.2 IDENTIFIED BY 'back' ;

  FLUSH PRIVILEGES ;

  2、设置同步Slave

  修改my.cnf文件,添加

  server-id = 2

  master-host = 192.168.0.1

  master-user = back

  master-password = back

  master-port = 3306

  replicate-ignore-db=mysql

  replicate-do-db=test

  重启MySQL

  3、启动同步

  在主服务器A MySQL命令符下:

  show master status;

  显示(当然这个是我机器的情况,你的不可能跟我一样哈,只是个例子):

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

  | File | Position | Binlog_Do_DB | Binlog_Ignore_DB |

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

  | updatelog.000028 | 313361 | test | mysql |

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

  在从服务器A MySQL命令符下:

  slave stop;

  CHANGE MASTER TO MASTER_LOG_FILE='updatelog.000028',MASTER_LOG_POS=313361;

  slave start;

  用show slave status\G;看一下从服务器的同步情况

  Slave_IO_Running: Yes

  Slave_SQL_Running: Yes

  如果都是yes,那代表已经在同步

  往表里面写点数据测试一下看是否同步成功,如果不成功,绝对不是你的RP问题,再检查一下操作步骤!

  4、设置双向同步

  修改B服务器的my.cnf,添加

  log-bin=/var/log/mysql/updatelog

  binlog-do-db=test

  binlog-ignore-db=mysql

  重启MySQL,创建一个MySQL帐号为同步专用

  GRANT REPLICATION SLAVE,RELOAD,SUPER, ON *.* TO back@192.168.0.1 IDENTIFIED BY 'back' ;

  FLUSH PRIVILEGES ;

  修改A服务器的my.cnf,添加

  master-host = 192.168.0.2

  master-user = back

  master-password = back

  master-port = 3306

  replicate-ignore-db=mysql

  replicate-do-db=test

  重启MySQL

  在主服务器B MySQL命令符下:

  show master status;

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

  | File | Position | Binlog_Do_DB | Binlog_Ignore_DB |

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

  | updatelog.000028 | 13753 | test | mysql |

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

  在服务器A MySQL命令符下:

  slave stop;

  CHANGE MASTER TO MASTER_LOG_FILE='updatelog.000028',MASTER_LOG_POS=13753;

  slave start;

  其实也就是A->B单向同步的反向操作!双向同步,就这么简单啦!
mysql> CREATE USER 'admin'@'localhost';
mysql> GRANT RELOAD,PROCESS ON *.* TO 'admin'@'localhost';
mysql> CREATE USER 'dummy'@'localhost';

你可能感兴趣的:(mysql,linux,SQL Server,Solaris,OS)