Better Stack MySQL logging

Start logging & collecting metrics in 2 minutes

What you would like to collect from your MySQL?

Collect both logs & metrics from your MySQL instance

Collect logs & metrics from your MySQL instance using Vector and Prometheus mysqld exporter.

1. Install mysqld exporter

Install mysqld exporter
curl https://logs.betterstack.com/scripts/mysqld_exporter | bash

2. Create MySQL user

Create a dedicated MySQL user for Vector to securely scrape metrics:

Log in to MySQL
mysql -u root -p
Create a new User
CREATE USER 'better_stack_metrics'@'localhost' IDENTIFIED BY 'your_password_here';
GRANT PROCESS, REPLICATION CLIENT, SHOW DATABASES ON *.* TO 'better_stack_metrics'@'localhost';
GRANT SELECT ON performance_schema.* TO 'better_stack_metrics'@'localhost';

If you're running MySQL 8.0 or later and want to collect user statistics, you'll also need to add access to user statistics:

Add access to user statistics
GRANT SELECT ON mysql.user TO 'better_stack_metrics'@'localhost';

Flush privileges & exist MySQL:

Flush privileges & exit MySQL
FLUSH PRIVILEGES;
exit;

3. Configure mysqld exporter

Content of .my.cnf file
[client]
user=better_stack_metrics
password=your_password_here

4. Run mysqld exporter

Run mysqld exporter
mysqld_exporter --config.my-cnf=".my.cnf"

5. Setup Vector

Select your platform:

Install and configure Vector on Ubuntu or Debian:

Set up Vector
curl -sSL https://logs.betterstack.dev/setup-vector/mysql_with_metrics/$SOURCE_TOKEN \
  -o /tmp/setup-vector.sh && \
  bash /tmp/setup-vector.sh

Curious about what the script does?

  • Installs Vector using official package.
  • Configures Vector for your Better Stack source.
  • Enables and restarts Vector.

The script will ask for confirmation before making any changes.

Collect only logs from your MySQL instance

Select your platform:

Install and configure Vector on Ubuntu or Debian:

Set up Vector
curl -sSL https://logs.betterstack.dev/setup-vector/mysql_with_metrics/$SOURCE_TOKEN \
  -o /tmp/setup-vector.sh && \
  bash /tmp/setup-vector.sh

Curious about what the script does?

  • Installs Vector using official package.
  • Configures Vector for your Better Stack source.
  • Enables and restarts Vector.

The script will ask for confirmation before making any changes.

You should see your logs in Better Stack → Live tail.

Need help?

Please let us know at [email protected].
We're happy to help! 🙏

Additional information

Prefer setting up Vector manually?
Find step-by-step instructions in our dedicated Vector guide.