mysql 5.5二进制文件安装

联系:手机/微信(+86 17813235971) QQ(107644445)

标题:mysql 5.5二进制文件安装

作者:惜分飞©版权所有[未经本人同意,不得以任何形式转载,否则有进一步追究法律责任的权利.]

1、创建相关目录用户
su – root
groupadd mysql
useradd -g mysql -p xifenfei -s /bin/bash -m mysql -d /opt/mysql
MYSQL_BASE=/opt/mysql
mkdir -p $MYSQL_BASE/product/5.5
mkdir -p $MYSQL_BASE/mysqldata
mkdir -p $MYSQL_BASE/mysqllog
mkdir -p /var/run/mysqld/
chmod -R 777 $MYSQL_BASE
chown -R mysql:mysql $MYSQL_BASE
chown -R mysql:mysql /var/run/mysqld
3、环境变量配置
export MYSQL_BASE=/opt/mysql
export basedir=$MYSQL_BASE/product/5.5
export datadir=$MYSQL_BASE/mysqldata
export LD_LIBRARY_PATH=$basedir/lib:/lib:/usr/lib:/usr/local/lib
export TMPDIR=/tmp
export PATH=${PATH}:/usr/bin:/bin:/usr/bin/X11:/usr/local/bin
export PATH=$basedir:$basedir/bin:${PATH}:$LD_LIBRARY_PATH
4、调整mysql 用户系统限制(可选)
编辑文件:/etc/security/limits.conf 加入以下语句:
mysql soft nproc 2047
mysql hard nproc 16384
mysql soft nofile 1024
mysql hard nofile 65536
确认如下语句是否存在于/etc/pam.d/login,如果不存在请增加:
session required pam_limits.so
如果用户SHELL 用的是Bourne, Bash, 或者Korn shell 修改/etc/profile,并增加如
下内容。(在SuSe 操作系统上,则需要修改/etc/profile.local):
if [ $USER = “mysql” ]; then
if [ $SHELL = “/bin/ksh” ]; then
ulimit -p 16384
ulimit -n 65536
else
ulimit -u 16384 -n 65536
fi
fi
5、安装数据库
5.1)解压数据库至/opt/mysql/product/5.5中
5.2)安装数据
[mysql@localhost ~]$ cd product/5.5/scripts/
[mysql@localhost scripts]$ ./mysql_install_db –basedir=$basedir –datadir=$datadir –user=mysql
5.3)设置my.cnf参数
vi /etc/my.cnf

[mysqladmin]
socket =/var/run/mysqld/mysqld.sock
[client]
port = 3306
socket =/var/run/mysqld/mysqld.sock
[mysqld]
port = 3306
socket = /var/run/mysqld/mysqld.sock
user = mysql
pid-file = /var/run/mysqld/mysqld.pid
basedir = /opt/mysql/product/5.5
datadir = /opt/mysql/mysqldata
skip-external-locking = 1
interactive_timeout = 1200
wait_timeout = 1200
character-set-server = utf8
back_log = 500
default_time_zone = '+08:00'
max_connections = 1000
max_connect_errors = 1000
connect_timeout = 300
table_open_cache = 100
max_allowed_packet = 16M
binlog_cache_size = 8M
max_heap_table_size = 64M
sort_buffer_size = 8M
join_buffer_size = 8M
thread_cache_size = 32
thread_concurrency = 16
query_cache_size = 0M
default-storage-engine = INNODB
thread_stack = 192K
transaction_isolation = READ-COMMITTED
tmp_table_size = 64M
log-bin =/opt/mysql/mysqllog/mysqlbin
log-error=/opt/mysql/mysqllog/mysqld.err
expire_logs_days = 7
binlog_format = ROW
max_binlog_size = 300M
slow_query_log = 1
slow_query_log_file =/opt/mysql/mysqllog/mysqld-slow
long_query_time = 10
tmpdir = /tmp
server-id = 1
key_buffer_size = 8M
read_buffer_size = 1M
read_rnd_buffer_size = 1M
bulk_insert_buffer_size = 1M
myisam_sort_buffer_size = 128K
innodb_additional_mem_pool_size = 16M
innodb_buffer_pool_size = 2G
innodb_data_file_path = ibdata1:1024M:autoextend
innodb_autoextend_increment = 64
innodb_file_per_table = 1
innodb_data_home_dir = /opt/mysql/mysqldata
innodb_file_io_threads = 4
innodb_thread_concurrency = 16
innodb_flush_log_at_trx_commit = 2
innodb_log_buffer_size = 8M
innodb_log_file_size = 512M
innodb_log_files_in_group = 3
innodb_max_dirty_pages_pct = 40
innodb_lock_wait_timeout = 120
innodb_locks_unsafe_for_binlog = 1
innodb_autoinc_lock_mode = 2
skip-name-resolve
lower_case_table_names=1
[mysqldump]
quick
max_allowed_packet = 16M
[mysql]
auto-rehash
[myisamchk]
key_buffer_size = 512M
sort_buffer_size = 512M
read_buffer = 8M
write_buffer = 8M
[mysqlhotcopy]
interactive-timeout
[mysqld_safe]
open-files-limit = 8192

5.4)异常处理
5.4.1)直接通过mysqld_safe不能正常启动数据库
ln -s /opt/mysql/product/5.5 /usr/local/mysql
或者
ln -s /opt/mysql/product/5.5/bin/mysqld /usr/local/mysql/bin/mysqld
5.4.2)mysql_secure_installation不能正常执行
1)
执行:/opt/mysql/product/5.5/bin/mysql_secure_installation出现以下错误,解决方法(ln -s /var/run/mysqld/mysqld.sock /tmp/mysql.sock)
Enter current password for root (enter for none):
ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/tmp/mysql.sock’ (2)
2)
修改mysql_secure_installation 脚本的do_query 函数(推荐处理方法)
do_query() {
echo “$1″ >$command
#sed ‘s,^,> ,’ < $command # Debugging # mysql --defaults-file=$config <$command ----此行修改如下: mysql --defaults-extra-file=$config <$command return $? } 6、添加开机启动服务
修改mysql.server文件
basedir=/opt/mysql/product/5.5
datadir=/opt/mysql/mysqldata
[root@localhost ~]# cp /opt/mysql/product/5.5/support-files/mysql.server /etc/init.d/mysqld
[root@localhost ~]# chkconfig –add mysqld
[root@localhost ~]# chkconfig mysqld on
[root@localhost ~]# chkconfig –list mysqld
mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off

mysql-cluster 7.x安装(linux)

联系:手机/微信(+86 17813235971) QQ(107644445)

标题:mysql-cluster 7.x安装(linux)

作者:惜分飞©版权所有[未经本人同意,不得以任何形式转载,否则有进一步追究法律责任的权利.]

一、整体规划
192.168.11.10(ndb)
192.168.11.11(ndb)
192.168.11.12(mgm)
192.168.11.13(sql)
192.168.11.14(sql)
二、安装mysql-cluster软件(root)
所有节点相同操作,如果没有mysql用户请创建mysql用户和组
groupadd mysql
useradd -g mysql mysql
上传至/tmp目录,开始解压安装
cd/tmp
tarxzvftarxzvfmysql-cluster-gpl-7.1.15-linux-x86_64-glibc23.tar.gz
mvmysql-cluster-gpl-7.1.15-linux-x86_64-glibc23/opt/mysql_cluster
chownmysql.mysql-R/opt/mysql_cluster
三、管理节点(mgm)配置(mysql)
配置mgm节点的config.ini文件
[NDBDDEFAULT]
NoOfReplicas=2
[NDB_MGMD]
NodeId=1
hostname=192.168.11.12
[NDBD]
NodeId=11
hostname=192.168.11.11
datadir=/opt/mysql_cluster/ndbdata
[NDBD]
NodeId=12
hostname=192.168.11.10
datadir=/opt/mysql_cluster/ndbdata
[MYSQLD]
NodeId=21
hostname=192.168.11.13
[MYSQLD]
NodeId=22
hostname=192.168.11.14
启动mgm节点
/opt/mysql_cluster/bin/ndb_mgmd -f /opt/mysql_cluster/config.ini –configdir=/opt/mysql_cluster
四、数据节点配置(mysql)
配置ndb节点参数(/opt/mysql_cluster/my.cnf)
[mysqld]
ndbcluster
ndb-connectstring=192.168.11.12
[mysql_cluster]
ndb-connectstring=192.168.11.12
创建ndbdata文件夹
mkdir /opt/mysql_cluster/ndbdata
启动ndb节点
/opt/mysql_cluster/bin/ndbd –defaults-file=/opt/mysql_cluster/my.cnf –initial
五、SQL节点配置(mysql)
初始化sql节点
/opt/mysql_cluster/scripts/mysql_install_db –user=mysql –datadir=/opt/mysql_cluster/data –basedir=/opt/mysql_cluster/
配置my.cnf文件(root)
mv /opt/mysql_cluster/my-large.cnf /etc/my.cnf
添加
[mysqld]
ndbcluster
ndb-connectstring=192.168.11.12
[mysql_cluster]
ndb-connectstring=192.168.11.12
修改mysql.server(mysql)
/opt/mysql_cluster/support-files/mysql.server中的datadir和basedir为
basedir=/opt/mysql_cluster
datadir=/opt/mysql_cluster/data
启动sql节点(mysql)
/opt/mysql_cluster/support-files/mysql.server start
六、查看集群状态(msyql)
ndb_mgm> show
Connected to Management Server at: localhost:1186
Cluster Configuration
———————
[ndbd(NDB)] 2 node(s)
id=11 @192.168.11.11 (mysql-5.1.56 ndb-7.1.15, Nodegroup: 0, Master)
id=12 @192.168.11.10 (mysql-5.1.56 ndb-7.1.15, Nodegroup: 0)
[ndb_mgmd(MGM)] 1 node(s)
id=1 @192.168.11.12 (mysql-5.1.56 ndb-7.1.15)
[mysqld(API)] 2 node(s)
id=21 @192.168.11.13 (mysql-5.1.56 ndb-7.1.15)
id=22 @192.168.11.14 (mysql-5.1.56 ndb-7.1.15)

mysql-cluster 7.x安装(windows)

联系:手机/微信(+86 17813235971) QQ(107644445)

标题:mysql-cluster 7.x安装(windows)

作者:惜分飞©版权所有[未经本人同意,不得以任何形式转载,否则有进一步追究法律责任的权利.]

mysql 集群配置(windows2台机器模拟)
1、环境规划
win7 192.168.1.1(管理节点,存储节点,sql节点)
win03 192.168.1.2(存储节点,sql节点)
2、安装cluster(zip包)
win7机器安装在D:\mysql-cluster中
win03机器安装在C:\mysql-cluster中
存储节点存储路径分别为:D:\mysql-cluster\ndbdata和C:\mysql-cluster\ndbdata
3、win7机器配置
创建D:\mysql-cluster\config.txt文件,内容为:
[NDBD DEFAULT]
NoOfReplicas=2
[NDB_MGMD]
ID=1
hostname=192.168.1.1
datadir=D:\mysql-cluster\data
[NDBD]
ID=21
hostname=192.168.1.1
datadir=D:\mysql-cluster\ndbdata
[NDBD]
ID=22
hostname=192.168.1.2
datadir=C:\mysql-cluster\ndbdata
[MYSQLD]
ID=11
hostname=192.168.1.1
[MYSQLD]
ID=12
hostname=192.168.1.2
复制D:\mysql-cluster\my-small.ini到c:\windows\my.ini并添加
[mysqld]
ndbcluster
ndb-connectstring=192.168.1.1
[mysql_cluster]
ndb-connectstring=192.168.1.1
4、win03机器配置
复制C:\mysql-cluster\my-small.ini到c:\windows\my.ini并添加
[mysqld]
ndbcluster
ndb-connectstring=192.168.1.1
[mysql_cluster]
ndb-connectstring=192.168.1.1
5、启动
5.1)启动管理节点(win7 上)
D:\mysql-cluster\bin>ndb_mgmd.exe –config-file=D:\mysql-cluster\config.txt –co
nfigdir=D:\mysql-cluster
5.2)启动存储节点(无先后顺序,第一个启动使用–initial)
win7
D:\mysql-cluster\bin>ndbd.exe –initial
win03
C:\mysql-cluster\bin>ndbd.exe
5.3)启动sql节点(无先后顺序)
win03
C:\mysql-cluster\bin>mysqld.exe –defaults-file=c:\windows\my.ini
win7
d:\mysql-cluster\bin>mysqld.exe –defaults-file=c:\windows\my.ini
6、查看是否启动成功
6.1)查看状态
D:\mysql-cluster\bin>ndb_mgm.exe
— NDB Cluster — Management Client —
ndb_mgm> show
Connected to Management Server at: 192.168.1.1:1186
Cluster Configuration
———————
[ndbd(NDB)] 2 node(s)
id=21 @192.168.1.1 (mysql-5.1.56 ndb-7.1.15, Nodegroup: 0, Master)
id=22 @192.168.1.2 (mysql-5.1.56 ndb-7.1.15, Nodegroup: 0)
[ndb_mgmd(MGM)] 1 node(s)
id=1 @192.168.1.1 (mysql-5.1.56 ndb-7.1.15)
[mysqld(API)] 2 node(s)
id=11 @192.168.1.1 (mysql-5.1.56 ndb-7.1.15)
id=12 @192.168.1.2 (mysql-5.1.56 ndb-7.1.15)
6.2数据操作测试
在win7上创建表,并插入数据
C:\Users\XIFENFEI>mysql -uroot
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.1.56-ndb-7.1.15-cluster-gpl MySQL Cluster Server (GPL)
Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.
mysql> use test;
Database changed
mysql> create table city(
-> id mediumint unsigned not null auto_incremen
-> name varchar(20) not null default ”
-> ) engine = ndbcluster default charset utf8;
Query OK, 0 rows affected (9.60 sec)
mysql> insert into city values(1, ‘city1’);
Query OK, 1 row affected (0.41 sec)
mysql> insert into city values(2, ‘city2’);
Query OK, 1 row affected (0.01 sec)
mysql> select * from city;
+—-+——-+
| id | name |
+—-+——-+
| 1 | city1 |
| 2 | city2 |
+—-+——-+
2 rows in set (0.00 sec)
win03机器查看数据
C:\mysql-cluster\bin>mysql -uroot
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.1.56-ndb-7.1.15-cluster-gpl MySQL Cluster Server (GPL)
Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL v2 license
Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.
mysql> use test;
Database changed
mysql> show tables;
+—————-+
| Tables_in_test |
+—————-+
| city |
+—————-+
1 row in set (0.11 sec)
mysql> select * from city;
+—-+——-+
| id | name |
+—-+——-+
| 1 | city1 |
| 2 | city2 |
+—-+——-+
2 rows in set (0.05 sec)

mysql 5.5 源码安装

联系:手机/微信(+86 17813235971) QQ(107644445)

标题:mysql 5.5 源码安装

作者:惜分飞©版权所有[未经本人同意,不得以任何形式转载,否则有进一步追究法律责任的权利.]

1.安装cmake
1)下载cmake
#wget http://www.cmake.org/files/v2.8/cmake-2.8.3.tar.gz
2)解压cmake
#tar -zvxf cmake-2.8.3.tar.gz
3)配置编译
#cd cmake-2.8.3
#yum -y install gcc
#yum -y install gcc-c++
#./configure
#make
#make install
2.安装MYSQL
1)下载MYSQL
mkdir /opt/mysql_src
#cd /opt/mysql_src
#wget http://dev.mysql.com/get/Downloads/MySQL-5.5/mysql-5.5.14.tar.gz/from/http://mysql.mirror.rafal.ca/
2)解压mysql-5.5.14.tar.gz
#tar -zvxf mysql-5.5.14.tar.gz
创建目录(mysql5.5默认已经没有data目录了)
mkdir -p /opt/mysql_src/product
mkdir -p /opt/mysql_src/data
3)配置编译
#cd mysql-5.5.14
#cmake . ##这个方法,安装路径默认

#cmake . \
-DCMAKE_BUILD_TYPE:STRING=Release \
-DCMAKE_INSTALL_PREFIX:PATH=/opt/mysql_src/product \
-DCOMMUNITY_BUILD:BOOL=ON \
-DENABLED_PROFILING:BOOL=ON \
-DENABLE_DEBUG_SYNC:BOOL=OFF \
-DINSTALL_LAYOUT:STRING=STANDALONE \
-DMYSQL_DATADIR:PATH=/opt/mysql_src/data \
-DMYSQL_MAINTAINER_MODE:BOOL=OFF \
-DWITH_EMBEDDED_SERVER:BOOL=ON \
-DWITH_EXTRA_CHARSETS:STRING=all \
-DWITH_SSL:STRING=bundled \
-DWITH_UNIT_TESTS:BOOL=OFF \
-DWITH_ZLIB:STRING=bundled \
-LH
如果出现一下错误:
cmake .
— MySQL 5.5.14
— Could NOT find Curses (missing: CURSES_LIBRARY CURSES_INCLUDE_PATH)
CMake Error at cmake/readline.cmake:82 (MESSAGE):
Curses library not found. Please install appropriate package,
remove CMakeCache.txt and rerun cmake.On Debian/Ubuntu, package name is libncurses5-dev, on Redhat and derivates it is ncurses-devel.
Call Stack (most recent call first):
cmake/readline.cmake:126 (FIND_CURSES)
cmake/readline.cmake:216 (MYSQL_USE_BUNDLED_LIBEDIT)
CMakeLists.txt:256 (MYSQL_CHECK_READLINE)
— Configuring incomplete, errors occurred!
需要安装ncurses-devel包
# yum -y install ncurses-devel
#make
#make install
#groupadd mysql
#useradd -r -g mysql mysql
#cd /opt/mysql_sc
#chown -R mysql:mysql .
#scripts/mysql_install_db –user=mysql
添加标准/etc/my.cnf文件(见mysql二进制安装程序,修改相关路径)
#./bin/mysqld_safe –user=mysql &

mysql 二进制文件安装注意事项

联系:手机/微信(+86 17813235971) QQ(107644445)

标题:mysql 二进制文件安装注意事项

作者:惜分飞©版权所有[未经本人同意,不得以任何形式转载,否则有进一步追究法律责任的权利.]

执行mysql_secure_installation报错
错误现象:
Enter current password for root (enter for none):
ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/tmp/mysql.sock’ (2)
错误原因:
mysql_secure_installation ignores –socket
解决方案:
1)ln -s /var/run/mysqld/mysqld.sock /tmp/mysql.sock
2)修改mysql_secure_installation 脚本的do_query 函数(推荐处理方法)
do_query() {
echo “$1” >$command
#sed ‘s,^,> ,’ < $command # Debugging # mysql --defaults-file=$config <$command ----此行修改如下: mysql --defaults-extra-file=$config <$command return $? } 使用mysqld_safe启动msql错误
mysqld_safe启动报错
注意:如果想把错误日志放到专门的日志目录中,需要在my.cnf中添加log-error=path选项
mysql二进制文件安装指导和my.cnf文件

mysqld_safe启动报错

联系:手机/微信(+86 17813235971) QQ(107644445)

标题:mysqld_safe启动报错

作者:惜分飞©版权所有[未经本人同意,不得以任何形式转载,否则有进一步追究法律责任的权利.]

使用二进制编译文件的mysqld_safe启动报错,如下:
[mysql@ECP-UC-DB1 ~]$ mysqld_safe
110707 21:31:19 mysqld_safe Logging to ‘/opt/mysql/mysqldata/ECP-UC-DB1.err’.
110707 21:31:19 mysqld_safe The file /usr/local/mysql/bin/mysqld
does not exist or is not executable. Please cd to the mysql installation
directory and restart this script from there as follows:
./bin/mysqld_safe&
See http://dev.mysql.com/doc/mysql/en/mysqld-safe.html for more information
解决方法:
su – root
mkdir /usr/local/mysql/bin
ln -s /opt/mysql/product/5.5/bin/mysqld /usr/local/mysql/bin/mysqld
再次执行mysqld_safe
[mysql@ECP-UC-DB1 ~]$ mysqld_safe
110707 21:32:37 mysqld_safe Logging to ‘/opt/mysql/mysqldata/ECP-UC-DB1.err’.
110707 21:32:37 mysqld_safe Starting mysqld daemon with databases from /opt/mysql/mysqldata
启动结果:
mysql 26885 23452 0 21:32 pts/0 00:00:00 /bin/sh /opt/mysql/product/5.5/bin/mysqld_safe
mysql 27653 26885 0 21:32 pts/0 00:00:00 /usr/local/mysql/bin/mysqld –basedir=/opt/mysql/product/5.5 –datadir=/opt/mysql/mysqldata –plugin-dir=/usr/local/mysql/lib/plugin –log-error=/opt/mysql/mysqldata/ECP-UC-DB1.err –open-files-limit=8192 –pid-file=/var/run/mysqld/mysqld.pid –socket=/var/run/mysqld/mysqld.sock –port=3306
问题存在原因:
1、mysqld_safe只认识/usr/local/mysql/bin/mysqld(也许是配置问题)
2、my.cnf只能放置在/etc/下面,不然使用–defaults-file也不能读取my.cnf文件(有疑惑)

mysql 安装并启动多个实例

联系:手机/微信(+86 17813235971) QQ(107644445)

标题:mysql 安装并启动多个实例

作者:惜分飞©版权所有[未经本人同意,不得以任何形式转载,否则有进一步追究法律责任的权利.]

1、数据库实例目录
drwxrwxrwx 6 mysql mysql 4096 Jul 6 23:25 mysqldata
drwxrwxr-x 5 mysql mysql 4096 Jul 6 23:23 mysqldata1
drwxrwxr-x 5 mysql mysql 4096 Jul 6 23:27 mysqldata2
2、创建实例
/opt/mysql/product/5.5/scripts/mysql_install_db –basedir=/opt/mysql/product/5.5 –datadir=/opt/mysql/mysqldata –user=mysql
/opt/mysql/product/5.5/scripts/mysql_install_db –basedir=/opt/mysql/product/5.5 –datadir=/opt/mysql/mysqldata1 –user=mysql
/opt/mysql/product/5.5/scripts/mysql_install_db –basedir=/opt/mysql/product/5.5 –datadir=/opt/mysql/mysqldata2 –user=mysql
3、修改my.cnf文件
[mysqld_multi]
mysqld = /opt/mysql/product/5.5/bin/mysqld
mysqladmin = /opt/mysql/product/5.5/bin/mysqladmin
user = root
password = passw0rd
[mysqld3306]
port = 3306
socket = /var/run/mysqld/mysqld3306.sock
pid-file = /var/run/mysqld/mysqld3306.pid
basedir = /opt/mysql/product/5.5
datadir = /opt/mysql/mysqldata
[mysqld3307]
port = 3307
socket = /var/run/mysqld/mysqld3307.sock
pid-file = /var/run/mysqld/mysqld3307.pid
basedir = /opt/mysql/product/5.5
datadir = /opt/mysql/mysqldata1
[mysqld3307]
port = 3307
socket = /var/run/mysqld/mysqld3308.sock
pid-file = /var/run/mysqld/mysqld3308.pid
basedir = /opt/mysql/product/5.5
datadir = /opt/mysql/mysqldata2
注:其他无关参数省略,日志等文件路径也不能相同(未写明)
4、启动数据库
mysqld_multi –defaults-file=/etc/mysql/my.cnf start 3306
mysqld_multi –defaults-file=/etc/mysql/my.cnf start 3307
mysqld_multi –defaults-file=/etc/mysql/my.cnf start 3308
5、登录数据库修改root密码
mysql -S /var/run/mysqld/mysqld3306.sock
mysql -S /var/run/mysqld/mysqld3307.sock
mysql -S /var/run/mysqld/mysqld3308.sock
use mysql
UPDATE user SET password=PASSWORD(‘passw0rd’) WHERE user=’root’;
FLUSH PRIVILEGES;
说明:三个库上分别操作
6、关闭数据库
mysqld_multi –defaults-file=/etc/mysql/my.cnf stop 3306
mysqld_multi –defaults-file=/etc/mysql/my.cnf stop 3307
mysqld_multi –defaults-file=/etc/mysql/my.cnf stop 3308
7、全部启动/关闭
mysqld_multi –defaults-file=/etc/mysql/my.cnf start 3306-3308
mysqld_multi –defaults-file=/etc/mysql/my.cnf stop 3306-3308

使用xtrabackup 配置主从服务器

联系:手机/微信(+86 17813235971) QQ(107644445)

标题:使用xtrabackup 配置主从服务器

作者:惜分飞©版权所有[未经本人同意,不得以任何形式转载,否则有进一步追究法律责任的权利.]

1、备份主机数据
innobackupex –user=root –password=xifenfei –defaults-file=/etc/my.cnf –stream /tmp/mysql 2>/tmp/mysql.log | gzip> /tmp/data/mysql.tar.gz
2、查看/tmp/mysql.log,记录下当前日志位置
innobackupex: MySQL binlog position: filename ‘mysql-bin.000018’, position 107
3、备份文件恢复
scp /tmp/data/mysql.tar.gz root@192.168.1.2:/tmp/
mkdir /tmp/mysql
cd /tmp/mysql
tar izxvf /tmp/mysql.tar.gz
–恢复数据库
innobackupex –apply-log –user=root –password=xifenfei /tmp/mysql
–复制到my.cnf中指定地方
innobackupex –copy-back –user=root –password=xifenfei /tmp/mysql
chmod -R mysql.mysql /var/lib/mysql
4、修改my.cnf文件
主服务器:
server-id=1
innodb_flush_log_at_trx_commit=1
sync-binlog=1
从服务器:
server-id=2
relay-log=/var/lib/mysql/replicate
relay-log-index=/var/lib/mysql/replicate.index
read-only
7、添加复制用户(主数据库上)
GRANT REPLICATION SLAVE ON *.*
TO ‘repl’@’192.168.1.2’ IDENTIFIED BY ‘xifenfei’;
8、配置从数据库
CHANGE MASTER TO
MASTER_HOST=’192.168.1.4′,
MASTER_USER=’repl’,
MASTER_PASSWORD=’xifenfei’,
MASTER_LOG_FILE=’mysql-bin.000018′,
MASTER_LOG_POS=107;
start slave;
9、查看主从是否正常
SHOW SLAVE STATUS\G
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.1.4
Master_User: repl
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000022
Read_Master_Log_Pos: 1185
Relay_Log_File: replicate.000007
Relay_Log_Pos: 588
Relay_Master_Log_File: mysql-bin.000022
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 1185
Relay_Log_Space: 1627
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 0
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id: 1
SHOW MASTER STATUS\G
*************************** 1. row ***************************
File: mysql-bin.000022
Position: 1185
Binlog_Do_DB:
Binlog_Ignore_DB:
1 row in set (0.00 sec)
SHOW PROCESSLIST\G
–从服务器进程
*************************** 2. row ***************************
Id: 22
User: system user
Host:
db: NULL
Command: Connect
Time: 1136
State: Waiting for master to send event
Info: NULL
*************************** 3. row ***************************
Id: 23
User: system user
Host:
db: NULL
Command: Connect
Time: 1676370
State: Slave has read all relay log; waiting for the slave I/O thread to update it
Info: NULL
–主服务器进程
*************************** 1. row ***************************
Id: 14
User: repl
Host: 192.168.1.2:34594
db: NULL
Command: Binlog Dump
Time: 1207
State: Master has sent all binlog to slave; waiting for binlog to be updated
Info: NULL
10、管理从服务器
start slave;
reset slave;
stop slave;