社区微信群开通啦,扫一扫抢先加入社区官方微信群
社区微信群
安装方法有很多这里我介绍两种,1、yum 安装mysql;2、手动安装mysql
普通删除模式
强力删除模式
,如果使用上面命令删除时,提示有依赖的其它文件,则用该命令可以对其进行强力删除参考:http://www.cnblogs.com/feiye512/p/9257687.html
1、下载
下载地址:http://dev.mysql.com/downloads/mysql/5.6.html#downloads
下载版本:我这里选择的5.6.33,通用版,linux下64位
也可以直接复制64位的下载地址,通过命令下载:
cd /usr/local/src
wget http://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.33-linux-glibc2.5-x86_64.tar.gz
/usr/local/mysql
目录权限为mysql用户bash: ./vmware-install.pl: /usr/bin/perl: bad interpreter: 没有那个文件或目录
解决方法
yum install perl gcc kernel-devel
yum upgrade kernel kernel-devel
FATAL ERROR: please install the following Perl modules before executing ./scripts/mysql_install_db:
Data::Dumper
解决方法 :安装autoconf库
yum -y install autoconf
启动脚本
cp support-files/mysql.server /etc/init.d/mysqld
chmod 755 /etc/init.d/mysqld
cp support-files/my-default.cnf /etc/my.cnf
修改启动脚本
vi /etc/init.d/mysqld
修改项:
basedir=/usr/local/mysql/
datadir=/usr/local/mysql/data/mysql
Starting MySQL. SUCCESS!
export PATH=$PATH:/usr/local/mysql/bin
source /etc/profile
windows下修改的是my.ini
[mysqld]
skip-grant-tables
重启
/etc/init.d/mysql restart(有些用户可能需要使用/etc/init.d/mysqld restart)
或者service mysql restart
密码重置
mysql -uroot
use mysql;
mysql> update user set password=password("root") where user="root";
mysql> flush privileges;
然后去掉skip-grant-tables配置文件,重启即可
mysql -uroot
use mysql;
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root' WITH GRANT OPTION;
flush privileges;
首先安装俩数据库,一个作为主库,一个作为从库,安装步骤如mysql手动安装.
主从复制配置过程
主从服务器分别作以下操作:
版本一致
初始化表,并在后台启动mysql
修改root的密码
两台mysql:192.168.101:3306 mysql:192.168.103:3306
修改主服务器master:
vi /etc/my.cnf
[mysqld]
log-bin=mysql-bin
server-id=101
sync_binlog = 1
binlog_checksum = none
binlog_format = mixed
auto-increment-increment = 2
auto-increment-offset = 1
slave-skip-errors = all
详细介绍:
server-id=1 #数据库唯一ID,主从的标识号绝对不能重复。#[必须]
log-bin=mysql-bin #开启bin-log,并指定文件目录和文件名前缀#[必须]
binlog-do-db=test #需要同步的数据库。如果是多个同步库,就以此格式另写几行即可。如果不指明对某个具体库同步,就去掉此行,表示同步所有库(除了ignore忽略的库)。
binlog-ignore-db=mysql #不同步mysql系统数据库。如果是多个不同步库,就以此格式另写几行;也可以在一行,中间逗号隔开。
sync_binlog = 1 #确保binlog日志写入后与硬盘同步
binlog_checksum = none #跳过现有的采用checksum的事件,mysql5.6.5以后的版本中binlog_checksum=crc32,而低版本都是binlog_checksum=none
binlog_format = mixed #bin-log日志文件格式,设置为MIXED可以防止主键重复。
3、修改从服务器slave:
vi /etc/my.cnf
[mysqld]
log-bin=mysql-bin
server-id=103
sync_binlog = 1
binlog_checksum = none
binlog_format = mixed
auto-increment-increment = 2
auto-increment-offset = 2
slave-skip-errors = all
4、重启两台服务器的mysql
/etc/init.d/mysql restart
5、在主服务器上建立帐户并授权slave:
mysql -uroot -proot
CREATE USER 'repl'@'%' IDENTIFIED BY '123456';
grant replication slave,replication client on *.* to 'repl'@'192.168.3.%' identified by "123456";
mysql> flush privileges;
mysql> show grants for repl@'192.168.3.%'; 查看指定用户权限
一般不用root帐号,%表示所有客户端都可能连,只要帐号,密码正确,此处可用具体客户端IP代替,如192.168.145.226,加强安全。
6、登录主服务器的mysql,查询master的状态
mysql>show master status;
+------------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000002 | 318 | | |
+------------------+----------+--------------+------------------+
1 row in set (0.00 sec)
注:执行完此步骤后不要再操作主服务器MYSQL,防止主服务器状态值变化
flush privileges;
7、配置从服务器Slave:
CREATE USER 'repl'@'%' IDENTIFIED BY '123456';
mysql>change master to master_host='192.168.3.100',master_user='repl',master_password='123456', master_log_file='mysql-bin.000023',master_log_pos=191; //注意不要断开,318数字前后无单引号。
如果运行报错:
则运行change master to master_auto_position=0
Mysql>start slave; //启动从服务器复制功能
RESET SLAVE; //重置从服务器复制功能
stop slave; //停掉从服务器复制功能
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.2.222 //主服务器地址
Master_User: mysync //授权帐户名,尽量避免使用root
Master_Port: 3306 //数据库端口,部分版本没有此行
Connect_Retry: 60
Master_Log_File: mysql-bin.000004
Read_Master_Log_Pos: 600 //#同步读取二进制日志的位置,大于等于
Exec_Master_Log_Pos
Relay_Log_File: ddte-relay-bin.000003
Relay_Log_Pos: 251
Relay_Master_Log_File: mysql-bin.000004
Slave_IO_Running: Yes //此状态必须YES
Slave_SQL_Running: Yes //此状态必须YES
注:Slave_IO及Slave_SQL进程必须正常运行,即YES状态,否则都是错误的状态(如:其中一个NO均属错误)。
以上操作过程,主从服务器配置完成。
flush privileges;
按上面操作反向即可,主主复制,最好将库锁住,仅仅允许读,以保证数据一致性;待主主同步环境部署后再解锁;
锁住后,就不能往表里写数据,但是重启mysql服务后就会自动解锁!
mysql> flush tables with read lock; //注意该参数设置后,如果自己同步对方数据,同步前一定要记得先解锁!
如果觉得我的文章对您有用,请随意打赏。你的支持将鼓励我继续创作!