It is not exactly mucilage, though it is having similarities. The structure is called as slime layer or more specifically capsule. It protects the bacteria from drying out (dissication) and also protects the pathogenic ones from the immune system by avoiding detection.