Related
I want to set the event_scheduler global to ON even if MySQL is restarted; how can I achieve this?
SET GLOBAL event_scheduler = ON;
You can set
event_scheduler=ON
in my.ini or my.cnf file, then restart your server for the setting to take effect.
Once set event_scheduler will always remain ON no matter whether your server restarts.
Open your /etc/mysql/my.ini file and add:
event_scheduler = on
under the [mysqld] section
(tested under mysql 5.5.35-0+wheezy1 - Debian)
One Way - You can set your system variables and use those variables if there is any possibility to restart your mysql.
Here is link Using system variables in mysql
On our Windows Server 2012 system, none of these or any other solutions worked. Then I looked at the registry entry for start up:
"C:\Program Files\MySQL\MySQL Server 5.6\bin\mysqld.exe" --defaults-file="C:\ProgramData\MySQL\MySQL Server 5.6\my.ini" MySQL56
The trick, the evil, is ProgramData. It's not Program Files. Look in Program Files and you'll see a my-default.ini file, put there just to royally screw you up.
The trick is to find the path in the registry, which was for me: HKEY_LOCAL_MACHINE\SYSTEM\Services\MySQL56
sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf
Add this line at the end of the file:
event_scheduler=ON
Than reboot and check if daemon is started after reboot:
Log into mysql bash:
mysql -u <user> -p
Than run the command:
SHOW PROCESSLIST;
Now you should see the event scheduler daemon in the list
I am trying to enable logging on MySQL on my Mac, OS X version 10.8.3.
Everywhere I searched, I get the same answer, i.e. to add the following to my.cnf:
[mysqld]
general_log=1
log=/var/log/mysql-query.log
and then restart mysql.
Permissions on the log file are correct and owner is _mysql like all other MySQL files.
However, doesn't matter how much I try, once my.cnf has been modified, MySQL won't restart. It would only shutdown and that's it. Via command line or via Preferences Pane, it won't start again.
I tried enabling log vie Workbench too, but as soon as log=... entry goes into my.cnf, MySQL refuses to start. I have to manually delete this entry to start MySQL.
Can anybody please guiding me on how to enable logging for MySQL on OS X 10.8.3?
Ok, finally wasting more than a day, what worked for me is this:
general-log
general_log_file = /var/log/mysql-query.log
For almost 10 years, in all the Linux systems I have ever used and installed, which must be at least 100 if not more, it has always been a simple entry like log=< path to log file > under [mysqld] section. Apparently it was the same on Macs too what I read from various blogs etc, however on this particular setup which I am doing, this is the first time that I am setting it up like above.
So my current working /etc/my.cnf file is as follows:
[client]
socket=/var/mysql/mysql.sock
[mysqld]
socket=/var/mysql/mysql.sock
general-log
general_log_file = /var/log/mysqld.log
I had to do:
touch /etc/my.cnf
chown _mysql /etc/my.cnf
to create one.
Also I had to do:
touch /var/log.mysqld.log
chown _mysql /var/log/mysqld.log
followed by restarting mysql via Workbench. Also tried restart via command line as follows:
/usr/local/mysql/bin/mysqladmin -uroot -p shutdown
sudo /usr/local/mysql/bin/mysqld_safe &
Main thing is, finally it is working and I can move ahead with my day.
I'm running MySQL Workbench 5.2.47 on Mac Mountain Lion. The above steps (create a /etc/my.cnf, create a dummy log file for mysql to populate, etc) could all be accomplished in MySQL Workbench.
1) Go to Server Admin -> Options File(Configuration).
2) Set your options, including location of 'general-log' under the 'Logging' tab. Click 'Apply'.
3) Startup / Shutdown -> Stop Server
4) Startup / Shutdown -> Start Server
Logging should now be turned on for all your statements.
#zeeshan's answer was pointed me to the write direction the most important thing is to make sure the permissions are right just as zeehan has mentioned.
/etc/my.cnf
[mysqld]
general_log = 1
general_log_file = /var/log/mysql-query.log
Then just chown the log and my.cnf files to be owned by "_mysql".
sudo chown _mysql /var/log/mysql-query.log
sudo chown _mysql /etc/my.cnf
Should be able to restart the mysqld using system_preferences.
When I am trying to check binary log:
SHOW BINARY LOGS;
I get this error:
ERROR 1381 (HY000): You are not using binary logging.
How to resolve this? Can anybody help?
Set the log-bin variable in your MySQL configuration file, then restart MySQL.
An example my.cnf (on Linux/unix) or my.ini (on Windows) would look like:
[client]
...
[mysqld]
...
log-bin=mysql-bin
---
Once restarted, MySQL automatically creates a new binary log (does so upon every restart).
You may also wish to look at the following variables:
server-id = 1
expire_logs_days = 4
sync_binlog = 1
Read details on the MySQL documentation. If you're after replication setup (a primary reason for using binary logs), check out Replication configuration checklist.
Line
log-bin=mysql-bin
must placed above lines:
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
You will need to activate binary logging at startup
Add the following lines in /etc/my.cnf under the [mysqld] section
[mysqld]
log-bin=mysql-bin
expire-logs-days=7
Then, run this
service mysql restart
The next time you login to mysql, you will see a binary log listing and will rotate out after 7 days.
The default location of the binary logs will be /var/lib/mysql or where datadir is defined. If you specify a folder before the binlog name, then that folder is the location.
For example
[mysqld]
log-bin=/var/log/mysql-bin
expire-logs-days=7
UPDATE 2012-07-12 02:20 AM EDT
Please restart mysql as follows and tell us if binary logging in on
service mysql restart --log-bin=mysql-bin
To enable the binary log, start the server with the --log-bin[=base_name] option.
If no base_name value is given, the default name is the value of the pid-file option (which by default is the name of host machine) followed by -bin.
If the basename is given, the server writes the file in the data directory unless the basename is given with a leading absolute path name to specify a different directory. It is recommended that you specify a basename.
Or you can directly use:
log-bin=mysql-bin
and then restart your mysql service. Then binary file will be generated. If you are using lampp on Linux machine then you will find this file in /lampp/var/mysql/mysql-bin.000001
FWIW, I had the same issue after I tried to set up my.cnf.master and my.cnf.slave files and symlink them to my.cnf for master and slave, respectively. The idea was to be able to switch the machine from master to slave and back easily.
It turned out that mysqld simply did not handle the symlink as expected. Hard-linking the file worked (ln my.cnf.master my.cnf). Careful if you do something like this, as overwriting one of the hard-linked filenames could break the link and create two separate files instead (depending on the method of rewriting employed by the software you use for it).
I've found logging will silently fail to happen even if my.cnf config is right, so you can also try re-creating your log folder.
This may be necwssary if the logs are in an odd state. (In my case, I had simply ceased logging in my.cnf and then re-enabled it, but nothing happened, probably because the existing files were not the latest updates?).
Something like this should work:
sudo service mysql stop
sudo mv /var/log/mysql /tmp/mysqlold # or rm -fr if you're brave
mkdir /var/log/mysql
chown -R mysql:mysql /var/log/mysql
sudo service mysql start
Obligatory warning: Obviously, take care when deleting anything on a database server. This will destroy/disrupt/corrupt any replication using this database as master (though you can resume replication as a slave). That said, I believe this should be safe insofar as it doesn't delete the database itself.
I went out of my mind with this issue on a MySQL 5.5 master running Debian. None of the above worked. Finally, I rebooted the server and logging was enabled.
Remove section [mysqld_safe] and replace with [mysqld].
It works for me.
I've read that Mysql server creates a log file where it keeps a record of all activities - like when and what queries execute.
Can anybody tell me where it exists in my system? How can I read it?
Basically, I need to back up the database with different input [backup between two dates] so I think I need to use log file here, that's why I want to do it...
I think this log must be secured somehow because sensitive information such as usernames and password may be logged [if any query require this]; so may it be secured, not easily able to be seen?
I have root access to the system, how can I see the log?
When I try to open /var/log/mysql.log it is empty.
This is my config file:
[client]
port = 3306
socket = /var/run/mysqld/mysqld.sock
[mysqld_safe]
socket = /var/run/mysqld/mysqld.sock
nice = 0
[mysqld]
log = /var/log/mysql/mysql.log
binlog-do-db=zero
user = mysql
socket = /var/run/mysqld/mysqld.sock
port = 3306
basedir = /usr
datadir = /var/lib/mysql
tmpdir = /tmp
skip-external-locking
bind-address = 127.0.0.1
#
# * Fine Tuning
#
key_buffer = 16M
max_allowed_packet = 16M
thread_stack = 192K
thread_cache_size = 8
general_log_file = /var/log/mysql/mysql.log
general_log = 1
Here is a simple way to enable them. In mysql we need to see often 3 logs which are mostly needed during any project development.
The Error Log. It contains information about errors that occur while
the server is running (also server start and stop)
The General Query Log. This is a general record of what mysqld is
doing (connect, disconnect, queries)
The Slow Query Log. Ιt consists of "slow" SQL statements (as
indicated by its name).
By default no log files are enabled in MYSQL. All errors will be shown in the syslog (/var/log/syslog).
To Enable them just follow below steps:
step1: Go to this file (/etc/mysql/conf.d/mysqld_safe_syslog.cnf) and remove or comment those line.
step2: Go to mysql conf file (/etc/mysql/my.cnf) and add following lines
To enable error log add following
[mysqld_safe]
log_error=/var/log/mysql/mysql_error.log
[mysqld]
log_error=/var/log/mysql/mysql_error.log
To enable general query log add following
general_log_file = /var/log/mysql/mysql.log
general_log = 1
To enable Slow Query Log add following
log_slow_queries = /var/log/mysql/mysql-slow.log
long_query_time = 2
log-queries-not-using-indexes
step3: save the file and restart mysql using following commands
service mysql restart
To enable logs at runtime, login to mysql client (mysql -u root -p) and give:
SET GLOBAL general_log = 'ON';
SET GLOBAL slow_query_log = 'ON';
Finally one thing I would like to mention here is I read this from a blog. Thanks. It works for me.
Click here to visit the blog
The MySQL logs are determined by the global variables such as:
log_error for the error message log;
general_log_file for the general query log file (if enabled by general_log);
slow_query_log_file for the slow query log file (if enabled by slow_query_log);
To see the settings and their location, run this shell command:
mysql -se "SHOW VARIABLES" | grep -e log_error -e general_log -e slow_query_log
To print the value of error log, run this command in the terminal:
mysql -e "SELECT ##GLOBAL.log_error"
To read content of the error log file in real time, run:
sudo tail -f $(mysql -Nse "SELECT ##GLOBAL.log_error")
Note: Hit Control-C when finish
When general log is enabled, try:
sudo tail -f $(mysql -Nse "SELECT CONCAT(##datadir, ##general_log_file)")
To use mysql with the password access, add -p or -pMYPASS parameter. To to keep it remembered, you can configure it in your ~/.my.cnf, e.g.
[client]
user=root
password=root
So it'll be remembered for the next time.
You have to activate the query logging in mysql.
edit /etc/my.cnf
[mysqld]
log=/tmp/mysql.log
restart the computer or the mysqld service
service mysqld restart
open phpmyadmin/any application that uses mysql/mysql console and run a query
cat /tmp/mysql.log ( you should see the query )
From the MySQL reference manual:
By default, all log files are created in the data directory.
Check /var/lib/mysql folder.
In my (I have LAMP installed) /etc/mysql/my.cnf file I found following, commented lines in [mysqld] section:
general_log_file = /var/log/mysql/mysql.log
general_log = 1
I had to open this file as superuser, with terminal:
sudo geany /etc/mysql/my.cnf
(I prefer to use Geany instead of gedit or VI, it doesn't matter)
I just uncommented them & save the file then restart MySQL with
sudo service MySQL restart
Run several queries, open the above file (/var/log/mysql/mysql.log) and the log was there :)
Enter MySQL/MariaDB server command-line tool as root
Set file path (you can replace general.log with the file name of your choice).
SET GLOBAL general_log_file='/var/log/mysql/general.log';
Set log file format
SET GLOBAL log_output = 'FILE';
Enable the server general log
SET GLOBAL general_log = 'ON';
Check your configurations in global configuration variables.
SHOW VARIABLES LIKE "general_log%";
Enter exit to leave MySQL command-line and Tail your queries by
tail -f /var/log/mysql/general.log
or
less /var/log/mysql/general.log
To disable the general server log
SET GLOBAL general_log = 'OFF';
To complement loyola's answer it is worth mentioning that as of MySQL 5.1 log_slow_queries is deprecated and is replaced with slow-query-log
Using log_slow_queries will cause your service mysql restart or service mysql start to fail
In addition to the answers above you can pass in command line parameters to the mysqld process for logging options instead of manually editing your conf file. For example, to enable general logging and specifiy a file:
mysqld --general-log --general-log-file=/var/log/mysql.general.log
Confirming other answers above, mysqld --help --verbose gives you the values from the conf file (so running with command line options general-log is FALSE); whereas mysql -se "SHOW VARIABLES" | grep -e log_error -e general_log gives:
general_log ON
general_log_file /var/log/mysql.general.log
Use slightly more compact syntax for the error log:
mysqld --general-log --general-log-file=/var/log/mysql.general.log --log-error=/var/log/mysql.error.log
shell> mysqladmin flush-logs
shell> mv host_name.err-old backup-directory
I locked my root user out from our database. I need to get all privileges back to the root user. I have my password and I can log in to MySQL. But the root user has no all privileges.
I had the same problem as the title of this question, so incase anyone else googles upon this question and wants to start MySql in 'skip-grant-tables' mode on Windows, here is what I did.
Stop the MySQL service through Administrator tools, Services.
Modify the my.ini configuration file (assuming default paths)
C:\Program Files\MySQL\MySQL Server 5.5\my.ini
or for MySQL version >= 5.6
C:\ProgramData\MySQL\MySQL Server 5.6\my.ini
In the SERVER SECTION, under [mysqld], add the following line:
skip-grant-tables
so that you have
# SERVER SECTION
# ----------------------------------------------------------------------
#
# The following options will be read by the MySQL Server. Make sure that
# you have installed the server correctly (see above) so it reads this
# file.
#
[mysqld]
skip-grant-tables
Start the service again and you should be able to log into your database without a password.
How to re-take control of the root user in MySQL.
DANGER: RISKY OPERATTION
Start session ssh (using root if possible).
Edit my.cnf file using.
sudo vi /etc/my.cnf
Add line to mysqld block.*
skip-grant-tables
Save and exit.
Restart MySQL service.
service mysql restart
Check service status.
service mysql status
Connect to mysql.
mysql
Using main database.
use mysql;
Redefine user root password.
UPDATE user SET `authentication_string` = PASSWORD('myNuevoPassword') WHERE `User` = 'root';
Edit file my.cnf.
sudo vi /etc/my.cnf
Erase line.
skip-grant-tables
Save and exit.
Restart MySQL service.
service mysqld restart
Check service status.
service mysql status
Connect to database.
mysql -u root -p
Type new password when prompted.
This action is very dangerous, it allows anyone to connect to all databases with no restriction without a user and password. It must be used carefully and must be reverted quickly to avoid risks.
After trying lots of things, this is what worked for me:
sudo mysql -u root
ALTER USER 'root'#'localhost' IDENTIFIED WITH mysql_native_password BY 'newpassword';
What that does is first we use sudo to log in mysql as root without needing a password. Then we just update root's password.
After that, I restarted mysqld:
sudo service mysql restart
And the newpassword logged root in!
On the Linux system you can do following (Should be similar for other OS)
Check if mysql process is running:
sudo service mysql status
If runnning then stop the process:
(Make sure you close all mysql tool)
sudo service mysql stop
If you have issue stopping then do following
Search for process: ps aux | grep mysqld
Kill the process: kill -9 process_id
Now start mysql in safe mode with skip grant
sudo mysqld_safe --skip-grant-tables &
I'm in windows 10, using WAMP64 server. Searched for my.cnf and my.ini. Found my.ini in C:\wamp64\bin\mariadb\mariadb10.2.14.
Following the instructions from the colleagues:
Opened the quick start menu from Wampserver, selected 'Stop All Services'
Opened my.ini in a text editor, searched for [mysqld]
Added 'skip-grant-tables' at the end of the [mysqld] section (but within it)
Save the file, leave the editor open
In the Wampserver menu, select "Restart Services'. There will be a warning about the skip-grant-tables option
In the Wampserver menu select MySQL to open the prompt
It asked for a password, just press enter
Paste the command ALTER USER 'root'#'localhost' IDENTIFIED WITH mysql_native_password BY 'newpassword';
It must report that the operation was successful (no tables affected)
In the my.ini file, erase the 'skip-grant-tables' line, save the file
In the WampServer menu, select once more Restart Service
Now you can enter with the new password. Thanks to all answers here.
If you use mysql 5.6 server and have problems with C:\Program Files\MySQL\MySQL Server 5.6\my.ini:
You should go to C:\ProgramData\MySQL\MySQL Server 5.6\my.ini.
You should add skip-grant-tables and then you do not need a password.
# SERVER SECTION
# ----------------------------------------------------------------------
#
# The following options will be read by the MySQL Server. Make sure that
# you have installed the server correctly (see above) so it reads this
# file.
#
# server_type=3
[mysqld]
skip-grant-tables
Note: after you are done with your work on skip-grant-tables, you should restore your file of C:\ProgramData\MySQL\MySQL Server 5.6\my.ini.
Use the following command (notice the "d"): mysqld --skip-grant-tables
if you are running on Apple MacBook OSX then:
Stop your MySQL server (if it is already running).
Find your MySQL configuration file, my.cnf. (For me it was placed #
/Applications/XAMPP/xamppfiles/etc. You can just search if you
can't find it).
Open my.cnf file in any text editor.
Add "skip-grant-tables" (without quotes) at the end of [mysqld] section and save the file.
Now start your MySQL server. It'll start with skip-grant-tables option.
Do what you want now!!
PS: Please remove skip-grant-tables from my.cnf file once you are done with whatsoever you want to do ELSE MySQL server will always run without access grants.
Please run this below command from the console to skip the user table verification while launching mysql database from command prompt
mysqld -skip-grant-tables
Edit my.ini file and add skip-grant-tables and restart your mysql server :
[mysqld]
port= 3306
socket = "C:/xampp/mysql/mysql.sock"
basedir = "C:/xampp/mysql"
tmpdir = "C:/xampp/tmp"
datadir = "C:/xampp/mysql/data"
pid_file = "mysql.pid"
# enable-named-pipe
key_buffer = 16M
max_allowed_packet = 1M
sort_buffer_size = 512K
net_buffer_length = 8K
read_buffer_size = 256K
read_rnd_buffer_size = 512K
myisam_sort_buffer_size = 8M
log_error = "mysql_error.log"
skip-grant-tables
# Change here for bind listening
# bind-address="127.0.0.1"
# bind-address = ::1
if this is a windows box, the simplest thing to do is to stop the servers, add skip-grant-tables to the mysql configuration file, and restart the server.
once you've fixed your permission problems, repeat the above but remove the skip-grant-tables option.
if you don't know where your configuration file is, then log in to mysql send SHOW VARIABLES LIKE '%config%' and one of the rows returned will tell you where your configuration file is.
This is how to do it on Ubuntu 20.4. This worked for me.
Go to /etc/mysql/mysql.conf.d/
You can write into terminal
cd /etc/mysql/mysql.conf.d/,
then you need to edit the file which is named mysqld.cnf.
On my PC, that file was a read-only file, so I needed to first change the permissions.
I wrote
sudo chmod +rw mysqld.cnf in the terminal.
After that, I edited the file by typing sudo gedit mysqld.cnf
in the terminal.
In the file, you will see [mysqld] somewhere, below [mysqld] add
skip-grant-tables in a new line, so that it looks like this
[mysqld]
skip-grant-tables
Restart the mysql service by writting sudo service mysql restart in terminal.
If your server wasn't running then write sudo service mysql start in terminal.
Another thing worth mentioning here is that
I also had another problem which I fixed in almost the exact same manner.
My server wasn't listening at the port 3306,
so I also had to add port = 3306 in that mysqld.cnf file.
Now I have
[mysqld]
skip-grant-tables
port = 3306
in the mysqld.cnf file.
I see that the question is old, but maybe my configuration will help someone. I use this configuration in scripts:
sed -i 's/^#skip-grant-tables.*/skip-grant-tables/g' /etc/my.cnf
service mysql restart
mysql -e "UPDATE mysql.user SET authentication_string='' WHERE user='root';"
sed -i 's/^skip-grant-tables.*/#skip-grant-tables/g' /etc/my.cnf
service mysql restart