数据库版本:MySQL 5.6.27
操作系统 :CentOS 7.4
Linux 环境下 MySQL 的配置文件的位置是在 /etc/my.cnf
Master 的配置如下:
log-bin=mysql-bin server-id=1 :用于标识唯一的数据库 binlog-ignore-db=information_schema binlog-ignore-db=performance_schema binlog-ignore-db=sys binlog-ignore-db=mysql binlog-do-db=yzdd binlog-ignore-db:表示同步的时候忽略的数据库 binlog-do-db:指定需要同步的数据库
然后重启 MySQL:service mysqld restart
,指定从属账号
GRANT REPLICATION SLAVE ON *.* TO 'root'@'localhost' IDENTIFIED BY '123456' >FLUSH PRIVILEGES;
Slave 的配置
log-bin=mysql-bin server-id=3 binlog-ignore-db=information_schema binlog-ignore-db=performance_schema binlog-ignore-db=sys binlog-ignore-db=mysql replicate-do-db=yzdd replicate-ignore-db=mysql log-slave-updates slave-skip-errors=all slave-net-timeout=60
stop slave; #关闭Slave change master to master_host='localhost',master_user='root',master_password='dongshang2018',master_log_file='mysql-bin.000004', master_log_pos=28125; start slave
stop slave; start slave; reset master; reset slave; show master status; show slave status \g;
取消 mysql 的 salve 设置
stop slave; change master to master_host=' '; mysql> show slave status \G Empty set (0.00 sec)
TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
解决方法:在 vi /etc/my.cnf
文件中加上:
explicit_defaults_for_timestamp=true
保存后再次启动就可以了。
Windows 下启动多个mysql服务
1、下载mysql免安装版,在D,E盘分别复制一份解压
2、进入解压的mysql目录,自己下载的MySQL-server-5.5,进入 MySQL-server-5.5 目录,打开 my.ini
配置文件,在配置文件中找到如下配置项进行更改: D 盘下的MySQL-server:
[client] port=3306 The TCP/IP Port the MySQL Server will listen on port=3306 #Path to installation directory. All paths are usually resolved relative to this. basedir="D:\MySQL-Server-5.5" #Path to the database root datadir="D:\MySQL-Server-5.5\data"
E 盘下的MySQL-server:
[client] port=3307 The TCP/IP Port the MySQL Server will listen on port=3307 #Path to installation directory. All paths are usually resolved relative to this. basedir="E:\MySQL-Server-5.5" #Path to the database root datadir="E:\MySQL-Server-5.5\data"
port 端口默认为 3306,可以保持一个 mysql 服务为默认端口,如 D 盘中的 mysql 配置文件中 port 配置项不进行修改,只修改 E 盘中的 port 配置(但 basedir 和 datadir这两项都必须修改成相应目录下的路径,如:D 盘修改为:basedir="D:\MySQL-Server-5.5"
和 datadir="D:\MySQL-Server-5.5\data"
。
3、打开 cmd 命令界面,分别使用命令进入对应mysql目录,如进入 D:\MySQL-server-5.5\bin
输入命令:
mysqld -install mysql3307 --defaults-file="F:\mysql3307\my.ini"
提示:Service successfully installed.
表示服务已经安装成功 如进入 E:\MySQL-server-5.5\bin
目录,输入命令:
mysqld -install mysql3307 --defaults-file="D:\SOFT_PHP_PACKAGE\mysql3307\my.ini"
提示:Service successfully installed.
表示服务已经安装成功
4、打开“运行
” 输入“regedit
” 打开注册表,依次展开 HKEY_LOCAL_MACHINE—>SYSTEM—>CurrentControlSet—>services,找到上面安装的 MySQL 和 MySQL2 服务,修改参数 ImagePath值:
MySQL修改为:D:\MySQL-Server-5.5\bin\mysqld --defaults-file=D:\MySQL-Server-5.5\my.ini MySQL
MySQL2修改为:E:\MySQL-Server-5.5\bin\mysqld --defaults-file=E:\MySQL-Server-5.5\my.ini MySQL2
5、启动服务,可以在 cmd 界面输入命令:net start MySQL
来启动 MySQL 服务,也可以在 “运行
” 里面输入 “services.msc
” 打开服务面板,找到 MySQL 右击启动
6,此时登入MySQL是会报错
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
尝试修改root用户密码
打开 my.ini
,找到 [mysqld]
在下面添加
skip-grant-tables
此时使用root账号,密码处按回车即可登录,然后修改密码:
UPDATE user SET Password=PASSWORD('123456') where USER='root'; mysql> FLUSH PRIVILEGES;
或者进入 E:\MySQL-server-5.5\bin
目录
执行 mysqladmin -u root password 123456
Change Master to Master_host='localhost', Master_port=3306, Master_user='root', Master_Password='123456';