Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting `server-id` variable in MySQL doesn't work

I've been trying to set up two databases as master & slave.

I followed the famous guide here: https://dev.mysql.com/doc/refman/5.1/en/replication-howto-existingdata.html

But no luck on my slave server, The issue I'm having is setting the server-id variable. No matter where I define it (I looked into all the possible cnf files that might allow me to define the variable)

I tried to define it like so:

[mysqld]
server-id = 2

I also tried setting it by using SET GLOBAL server_id but obviously, it didn't save the setting.

when I do:

SHOW VARIABLES LIKE 'server_id'

It returns

server_id 0

Among the cnf files I've looked into are:

etc/mysql/mysql.conf.d/mysqld.cnf
etc/mysql/mysql.conf.d/mysqld_safe_syslog.cnf
etc/mysql/conf.d/mysql.cnf
etc/mysql/debian.cnf
etc/mysql/mysql.cnf
usr/my.cnf
usr/my-new.cnf
usr/etc/my.cnf

My MySQL server is running on Ubuntu. And if it matters, I start it by typing:

service mysql start

I'd love to know where else I could look to fix this issue. Thanks a bunch!

Additional Notes:

MySQL Ignoring the global conf file

I received this warning a couple of times and it disappeared when I returned the chmod to 644 on the etc/mysql folder, although every thing stated above was attempted using both 644 and 777 permissions, with 644 the warning disappears.

like image 217
RagZ Avatar asked Oct 25 '15 10:10

RagZ


People also ask

How do I set system variables in MySQL?

System variables can be set at server startup using options on the command line or in an option file. Most of them can be changed dynamically while the server is running by means of the SET statement, which enables you to modify operation of the server without having to stop and restart it.

What is server ID in MySQL?

This server ID is used to identify individual servers within the replication topology, and must be a positive integer between 1 and (232)−1. The default server_id value from MySQL 8.0 is 1.

Why is my MySQL not working?

normally means that there is no MySQL server running on the system or that you are using an incorrect Unix socket file name or TCP/IP port number when trying to connect to the server. You should also check that the TCP/IP port you are using has not been blocked by a firewall or port blocking service.

How do I find my database server ID?

To get the server_id, use the system defined variable @@server_id. You cannot use only a single @ as user defined variable for server_id. As an alternate, you can use SHOW VARIABLES command.


2 Answers

I know it's to late, but for those who will make the mistake. It's server_id and not server-id:

[mysqld]
server_id = 2
like image 187
Groco Avatar answered Sep 25 '22 00:09

Groco


For me it worked by renaming the from /etc/mysql/conf.d/my.cnf to /etc/mysql/conf.d/my.ini

I'm not sure of the exact reason for that (feel free to edit this answer and add to it).

I tried out various combinations:

  1. Keeping the variable as: server-id and server_id
  2. Keeping the group/section as: [mysql] and [mysqld]
  3. Renaming the file to: my.cnf , mysqld.cnf, mysql.cnf, my.ini

You can keep trying various combinations out of the above options, it should definitely work. :)

like image 27
Rakmo Avatar answered Sep 26 '22 00:09

Rakmo