[英]MySQL Master-Slave Replication “Unknown database” error
I'm trying to setup master-slave replication between 2 mysql servers on CentOS. 我正在尝试在CentOS上的2个mysql服务器之间设置主从复制。 Once setup if I create a database called 'fakeDB' on the master it creates it on the slave.
一旦设置好,如果我在主数据库上创建了一个名为“ fakeDB”的数据库,它将在从数据库上创建它。 Awesome!
太棒了! But if I then try to create a table on the master I get this error on the slave:
但是,如果我随后尝试在主服务器上创建表,则会在从服务器上收到此错误:
Last_Errno: 1049
Last_Error: Error 'Unknown database 'fakeDB'' on query. Default database: 'fakeDB'. Query: 'create table tmp (name varchar(100))'
But the database exists on the slave! 但是数据库存在于从属服务器上! So I then started over and created the database and tmp table on both servers.
因此,我重新开始并在两台服务器上创建了数据库和tmp表。 I reset everything and then tried to insert a row on the master.
我重置了所有内容,然后尝试在主数据库上插入一行。 I then got this error on the slave:
然后我在奴隶上得到了这个错误:
Last_SQL_Errno: 1146
Last_SQL_Error: Error 'Table 'fakeDB.tmp' doesn't exist' on query. Default database: 'fakeDB'. Query: 'insert into tmp values ('asdf')'
But again that database exists and so does the table on both servers. 但是该数据库又存在了,两台服务器上的表也都存在。 I can access them manually.
我可以手动访问它们。 Here is the variables I set in the my.cnf file on both servers.
这是我在两台服务器上的my.cnf文件中设置的变量。
server-id = 1 #set as 2 for master
log_bin = /var/lib/mysql/mysql-bin.log
relay-log = /var/lib/mysql/mysql-relay-bin.log
binlog_do_db = fakeDB
What am I doing wrong? 我究竟做错了什么?
Ok. 好。 I figured it out.
我想到了。 Turns out it was something stupid.
原来这是愚蠢的。 I had this option set in my configuration file on the slave:
我在从属服务器的配置文件中设置了此选项:
lower_case_table_names=1
So when I created the database on the master as fakeDB
it created it on the slave as fakedb
. 因此,当我在主数据库上将数据库创建为
fakeDB
时,在从属数据库上将数据库创建为fakedb
。 So on the slave I can issue use fakeDB;
因此,在从属服务器上,我可以发布
use fakeDB;
and it works because the command is case insensitive but then the queries issued from the master weren't so insert into fakeDB.tmp
failed because the database name is fakedb
. 它之所以有效,是因为该命令不区分大小写,但是从主服务器发出的查询却不那么
insert into fakeDB.tmp
失败,因为数据库名称是fakedb
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.