Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can i get server_id in MYSQL?

Tags:

mysql

I am referring this document. I require server_id for uuid short function of mysql.

https://dev.mysql.com/doc/refman/5.1/en/server-system-variables.html#sysvar_server_id

How can i print server_id through mysql console? Thanks

like image 726
user609306 Avatar asked Mar 18 '14 14:03

user609306


People also ask

What is Server_id in MySQL?

In MySQL 5.7, server_id must be specified if binary logging is enabled, otherwise the server is not allowed to start. server_id is set to 0 by default. On a replication source server and each replica, you must specify server_id to establish a unique replication ID in the range from 1 to 232 − 1.

How do I find MySQL 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.

Where is auto CNF?

First, this means there is a new file (in 5.6+) located in the datadir named auto. cnf. In this file is a unique uuid for the server. This is great, but if you are unaware of it, and simply copy the datadir to set up a slave, and do not remove this file, then you're in for some errors.


1 Answers

You can do it with:

SELECT @@server_id

as @@ points to global-defined variables (not like single @ which is for session-defined variables)

For example,

SELECT CONCAT(@@server_id, UUID());
like image 60
Alma Do Avatar answered Oct 08 '22 16:10

Alma Do