一、下载文件
二、安装cmake
#tar zxfv cmake-2.8.10.1.tar.gz
#cd cmake-2.8.10.1
#./configure --prefix=/usr/local/cmake && make && make install
三、创建用户
#groupadd mysql
#useradd -g mysql mysql
四、建立相关文件夹
#mkdir -p /data/mysql/3306
#mkdir -p /data/mysql/3307
#mkdir -p /etc/mysql/3306
#mkdir -p /etc/mysql/3307
#mkdir -p /usr/local/mysql
#chown mysql.mysql -R /data/mysql/3306
#chown mysql.mysql -R /data/mysql/3307
五、创建实例一
#tar zxfv mysql-5.5.28.tar.gz
#cd mysql-5.5.28
#/usr/local/cmake/bin/cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql/3306 -DMYSQL_DATADIR=/data/mysql/3306 -DWITH_INNOBASE_STORAGE_ENGINE=on -DMYSQL_TCP_PORT=3306 -DMYSQL_UNIX_ADDR=/data/mysql/3306/mysqld.sock -DENABLED_LOCAL_INFILE=1 -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DSYSCONFDIR=/etc/mysql/3306
#make && make install
我执行时提示错误:
CMake Error at cmake/readline.cmake:83 (MESSAGE):
Curses library not found. Please install appropriate package,
remove CMakeCache.txt and rerun cmake.On Debian/Ubuntu, packagename is libncurses5-dev, on Redhat and derivates it isncurses-devel.
Call Stack (most recent call first):
cmake/readline.cmake:127 (FIND_CURSES)
cmake/readline.cmake:216(MYSQL_USE_BUNDLED_LIBEDIT)
CMakeLists.txt:251 (MYSQL_CHECK_READLINE)
搜到别人的解决方案:
1安装:yum install ncurses-devel 2.再安装:yum install bison 3.删除mysql-5.5.28/CMakeCache.txt 然后重复执行一次上次的命令即可。
配置文件复制:
#cp /usr/local/mysql/3306/support-files/my-medium.cnf /etc/mysql/3306/my.cnf
修改配置文件。在相应的下面增加(我只写了增加的)
#vim /etc/mysql/3306/my.cnf
[client]
default-character-set=utf8
[mysqld]
log-error=/data/mysql/3306/mysql_error.log
character_set_server=utf8
collation-server=utf8_general_ci
lower_case_table_names=1
character_set_client=utf8
[mysql]
default-character-set = utf8六、初始化实例1
#/usr/local/mysql/3306/scripts/mysql_install_db --user=mysql --datadir=/data/mysql/3306 --basedir=/usr/local/mysql/3306启动实例1:
#/usr/local/mysql/3306/bin/mysqld_safe --user=mysql --datadir=/data/mysql/3306/ --basedir=/usr/local/mysql/3306/我启动时报错了,删除/etc/my.cnf再启动OK。原因:
读取my.cnf的顺序:
1./etc/my.cnf。
2.$DATADIR/my.cnf。们编译时最后一个参数
-DSYSCONFDIR=/etc/mysql/3306
3.defaults-extra-file 启动的时候,加此参数指定
4.~/.my.cnf
测试连接 :/usr/local/mysql/3306/bin/mysql -uroot -P3306 -p(默认空的进去了改密码)
OK继续创建下一个实例
七、创建实例二(跟实例一一样只是路径不同)
#tar zxfv mysql-5.5.28.tar.gz
#cd mysql-5.5.28
#/usr/local/cmake/bin/cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql/3307 -DMYSQL_DATADIR=/data/mysql/3307 -DWITH_INNOBASE_STORAGE_ENGINE=on -DMYSQL_TCP_PORT=3307 -DMYSQL_UNIX_ADDR=/data/mysql/3307/mysqld.sock -DENABLED_LOCAL_INFILE=1 -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DSYSCONFDIR=/etc/mysql/3307
#make && make install复制配置文件
#cp /usr/local/mysql/3307/support-files/my-medium.cnf /etc/mysql/3307/my.cnf编辑文件
vim /etc/mysql/3307/my.cnf
初始化
#/usr/local/mysql/3307/scripts/mysql_install_db --user=mysql --datadir=/data/mysql/3307 --basedir=/usr/local/mysql/3307
启动
#/usr/local/mysql/3307/bin/mysqld_safe --user=mysql --datadir=/data/mysql/3307/ --basedir=/usr/local/mysql/3307/ 八、安全策略和远程访问
#cd /usr/local/mysql/3307/
#./bin/mysql_secure_installation我全部选的n.自己测试而已。。
开启远程访问:用root进入到各自端口下mysql执行:
mysql> grant all on *.* to root@'%' identified by 'root';
mysql> FLUSH PRIVILEGES;
********************************************************************************************************************************
娘的要末日了。下面开始学习主从配置。用上面的2个实例3306做主,3307从。
5.5的主从配置比较简单:
1、主库3306增加用户,并刷新权限(只能从192.168.221.131访问)
GRANT REPLICATION SLAVE ON *.* TO 'slave'@'192.168.221.131' IDENTIFIED BY '111111' with grant option;
flush privileges;2.主库3306数据备份。备份前先停止读操作
flushtables with readlock;#设置只读
mysqldump -u root -p beiker > /data/beiker.sql
unlocktables;#解除锁定
3.配置主库3306配置文件my.cnf
#vim /etc/mysql/3306/my.cnf
server-id=1 服务器id,1为主服务器(一般都已经有了,就不修改了。)
log_bin=mysql-bin #binlog的文件名,一般也已经有了。
binlog-do-db=test #要同步的数据库可多个
binlog-do-db=test02 #要同步的数据库可多个
binlog-ignore-db=mysql #不需同步的数据库
binlog-ignore-db=mysql01 #不需同步的数据库
4.重启主库3306
SHOW MASTER STATUS;
会显示,我只同步了test库。忽略的库也没配置
FILE POSITION Binlog_Do_DB Binlog_Ignore_DB
mysql-bin.000026 107 test
FILE 和POSITION要记录。从库3307时配置时需要。
5.配置从库3307配置文件
#vim /etc/mysql/3307/my.cnf
server-id=2 #原有server-id=1,改为2
log-bin=mysql-bin #启动MySQ二进制日志系统
replicate-do-db=test #要同步的数据库
replicate-do-db=test01 #要同步的数据库
replicate-ignore-db=mysql #不同步的数据库
replicate-ignore-db=mysql01 #不同步的数据库
6.重启从库3307数据库
SLAVE STOP;
CHANGE MASTER TO MASTER_HOST = '192.168.221.130',MASTER_USER = 'slave',MASTER_PASSWORD = '111111',MASTER_LOG_FILE = 'mysql-bin.000026',
MASTER_LOG_POS = 107 ,MASTER_PORT=3306;
SLAVE START;
SHOW SLAVE STATUS要指定端口为3306.默认会用本实例的端口我的默认会用3307.第一次失败了 重新设置的。 此时配置完毕,可以试试在主从3306操作。看看是否能在 从库3307看到