3

How can I enable binlog in mysql? The documents say to start the server with --log-bin but when I do:

service mysql start --log-bin=/binlog

I get:

start: invalid option: --log-bin=/binlog

And when I add

log-bin = /binlog

to /etc/mysql/my.cnf it doesn't log anything.

4
  • Uncomment the log_bin line from your my.cnf
    – Dan
    Jul 18, 2015 at 7:13
  • @dan - what's that supposed to do? It's already not working without it. Jul 18, 2015 at 8:17
  • Please share my.cnf and the log since you restart the mysqld
    – Anatoly
    Jul 18, 2015 at 12:02
  • @Anatoly - it's too long to share. It's just the default file with the extra line I added at the end. Jul 18, 2015 at 23:20

4 Answers 4

14
+150

"service mysql start" won't accept mysql-specific options, since that's a command of the init system. You would need to pass the --log-bin to mysqld. But you should prefer specifying that in the config file ;-)

add in the [mysqld] stanza of my.cnf

log-bin = /path/to/log

and maybe:

expire-logs-days = 14
max-binlog-size  = 500M
server-id        = 1

and beware that the specified file+path must be writable by the mysql user! Your example specified /binlog. The mysql user ist surely not allowed to write files in /. You may specify a relative path like log-bin=binlog which will then create a file called binlog inside your MySQL data directory where permissions are already set up.

8
  • I think you're on to something, I didn't realize the line had to go in a specific section, I moved it to the mysqld area and now I get: start: Job failed to start - /binlog is 777 and owned my mysql.mysql - this is in a vagrant VM by the way. Any ideas? Jul 25, 2015 at 2:56
  • This may be due to AppArmor blocking MySQL, as /binlog is a non-standard location. Check your logs. Jul 25, 2015 at 8:20
  • If you skip an argument to log-bin, it will be saved in your data directory as ${HOSTNAME}-bin. Jul 25, 2015 at 8:26
  • Thanks @sam_pan_mariusz - skipping the argument does work, probably AppArmor is the culprit I hadn't thought of that. Jul 26, 2015 at 0:18
  • 1
    On ubuntu 16.04 for mysql 5.7 my.cnf includes config files under /etc/mysql/mysql.conf.d/. To enable bin log these options should be add to file /etc/mysql/mysql.conf.d/mysqld.cnf. Thanks for the solution.
    – cubbuk
    Aug 31, 2017 at 8:26
7

In MySQL 5.7 you will also need to add the server-id as follows

[mysqld]
 server_id=master-01
 log_bin

If you do not add the server_id option, the server will not start. This is from the MySQL 5.7 reference.

4
  • where are the logs saved when you don't specify the path? Sep 30, 2016 at 22:39
  • @YahyaUddin which logs? Do you mean the binary logs? The binary logs are stored in datadir folder
    – Joseph
    Oct 1, 2016 at 11:18
  • Where's that? ..... Oct 1, 2016 at 11:19
  • I was banging my head from an hour... Thanks for the tip on server-id.
    – Fr0zenFyr
    Apr 28, 2017 at 9:52
3

service mysqld stop

Edit /etc/mysql/my.cnf : Under the logging and Replication Locate log_bin. Un comment the log_bin

service mysqld start

0
-4

You can start the server with

mysqld --log-bin=/binlog
2
  • 1
    That's a one-time approach at best, not suitable for production use.
    – Sven
    Apr 2, 2018 at 18:20
  • Agree, His question was it says "invalid option" when he use --login-bin option. This is how you use the option. Apr 2, 2018 at 20:33

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .