I installed mysql with homebrew with this guide https://gist.github.com/nrollr/3f57fc15ded7dddddcc4e82fe137b58e
Now I need to delete the server variable NO_ZERO_DATE from the mysql configuration but i don't found mysql conf file. Where is located this file?
In MacOS the my.ini file is found as my.cnf, you can look for it in terminal with
> mysql --help
"Default options are read from the following files in the given order:
/etc/my.cnf /etc/mysql/my.cnf /usr/local/etc/my.cnf ~/.my.cnf"
But if you hadn't found the cnf in the locations that help show you, try with the next command
> ls $(brew --prefix mysql)/support-files/my-*
For example, I got this file
/usr/local/opt/mysql/support-files/my-default.cnf
then you need to copy this file to one of your default directories, in my case /etc/my.cnf
> sudo cp /usr/local/opt/mysql/support-files/my-default.cnf /etc/my.cnf
Finally open your cnf file and delete STRICT_TRANS_TABLES from sql_mode
> nano /etc/my.cnf
sql_mode=NO_ENGINE_SUBSTITUTION
Exit with ctrl+x and press S
Don't forget to restart your mysql server
> sudo mysql.server stop
> sudo mysql.server start
I am trying to copy a new my.cnf to my mysql5 directory in the command line. I have used:
cp my.cnf /opt/local/etc/mysql5
However when I execute the command, I get Permission Denied.
I am the directory where my.cnf resides.
Thanks for your help.
You are trying to copy the file to root user's directory. You'll need to use sudo.
Try
$ sudo cp my.cnf /opt/local/etc/mysql5
when I use mysqlbinlog command I can't find the file.
lihaodeMacBook-Pro:data lihao$ mysqlbinlog --start-position=106 --stop-position=125 mysqlbin.000001 > ~/tmp1.sql
mysqlbinlog: File 'mysql-bin.000001' not found (Errcode: 13)
lihaodeMacBook-Pro:data lihao$ ls -a
. ib_logfile0 library mysql-bin.000001
.. ib_logfile1 lihaodeMacBook-Pro.local.err mysql-bin.000002
lihaodeMacBook-Pro:data lihao$ mysqlbinlog /usr/local/mysql-5.1.63-osx10.6-x86_64/data/mysql-bin.000001
/*!40019 SET ##session.max_insert_delayed_threads=0*/;
/*!50003 SET #OLD_COMPLETION_TYPE=##COMPLETION_TYPE,COMPLETION_TYPE=0*/;
DELIMITER /*!*/;
mysqlbinlog: File '/usr/local/mysql-5.1.63-osx10.6-x86_64/data/mysql-bin.000001' not found (Errcode: 13)
I find the solution of the question by myself.I can't find the file because I don't have permission to read or write the file.I can use the command by add sudo at front of the commend.
Mysql Server 5.7 issue resolved:
there are two possibilities over here.
One is either your bin-log file is in /var/log/mysql in that case:
cd /var/log/mysql/
then access the file as sudo user
sudo mysqlbinlog mysql-bin.00000x
if file is in /var/lib/mysql then one needs sudo access to even read the file so follow these two steps:
Login as sudo root user
sudo -i
Once u are sudo user then go to the following directory: (without being a sudo user this location will deny the permission to even enter the directory)
cd /var/lib/mysql/
after that access the file
sudo mysqlbinlog mysql-bin.00000x
In my case it was permission related. Ensure you're sudo when using mysqlbinglong utility.
Should somebody submit an issue to the creators of the mysqlbinlog utility ? The error should be a bit more clear in my opinion.
Our Mysql queries use temporary tables which creates temporary files in the process. Currently the files are written to /tmp. How exactly can the path of the temp folder to which mysql writes to be changed?
You should edit your my.cnf
tmpdir = /whatewer/you/want
and after that restart mysql
P.S. Don't forget give write permissions to /whatewer/you/want for mysql user
Here is an example to move the mysqld tmpdir from /tmp to /run/mysqld which already exists on Ubuntu 13.04 and is a tmpfs (memory/ram):
sudo vim /etc/mysql/conf.d/local.cnf
Add:
[mysqld]
tmpdir = /run/mysqld
Then:
sudo service mysql restart
Verify:
SHOW VARIABLES LIKE 'tmpdir';
==================================================================
If you get an error on MySQL restart, you may have AppArmor enabled:
sudo vim /etc/apparmor.d/local/usr.sbin.mysqld
Add:
# Site-specific additions and overrides for usr.sbin.mysqld.
# For more details, please see /etc/apparmor.d/local/README.
/run/mysqld/ r,
/run/mysqld/** rwk,
Then:
sudo service apparmor reload
sources: http://2bits.com/articles/reduce-your-servers-resource-usage-moving-mysql-temporary-directory-ram-disk.html, https://blogs.oracle.com/jsmyth/entry/apparmor_and_mysql
This is answered in the documentation:
Where MySQL Stores Temporary Files
On Unix, MySQL uses the value of the TMPDIR environment variable as
the path name of the directory in which to store temporary files. If
TMPDIR is not set, MySQL uses the system default, which is usually
/tmp, /var/tmp, or /usr/tmp.
On Windows, Netware and OS2, MySQL checks in order the values of the
TMPDIR, TEMP, and TMP environment variables. For the first one found
to be set, MySQL uses it and does not check those remaining. If none
of TMPDIR, TEMP, or TMP are set, MySQL uses the Windows system
default, which is usually C:\windows\temp.
if you dont have apparmor or selinux issues, but still get errorcode 13's:
mysql must be able to access the full path. I.e. all folders must be mysql accessible, not just the one you intend in pointing to.
example, you try using this in your mysql configuration: tmp = /some/folder/on/disk
# will work, as user root:
mkdir -p /some/folder/on/disk
chown -R mysql:mysql /some
# will not work, also as user root:
mkdir -p /some/folder/on/disk
chown -R mysql:mysql /some/folder/on/disk
This maybe helpful for MySql with AppArmor
stop mysql :
sudo /etc/init.d/mysql stop
Create directory called /somewhere/tmp
Edit Config:
sudo vim /etc/mysql/my.cnf # or perhaps sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf
change
tmpdir = /somewhere/tmp/
Then
sudo vim /etc/apparmor.d/usr.sbin.mysqld
Add
# Allow data dir access
/somewhere/ r,
/somewhere/** rwk,
sudo chown -R root:root /somewhere
sudo chmod -R 1777 /somewhere
Restart
sudo /etc/init.d/apparmor reload
sudo /etc/init.d/mysql restart
You can also set the TMPDIR environment variable.
In some situations (Docker in my case) it's more convenient to set an environment variable than to update a config file.
Works for 5.7 on centos 8
mkdir /tmp/1 /tmp/1
semanage fcontext -a -t mysqld_db_t "/tmp/1(/.*)?"
restorecon -Rv /tmp/1
semanage fcontext -a -t mysqld_db_t "/tmp/2(/.*)?"
restorecon -Rv /tmp/2
to my.cnf tmpdir=/tmp/1:/tmp/2
sudo service mysql restart
If you are a MariaDB user, all this above apply, by don't forget to unlock the "home" protection by doing this.
touch /etc/systemd/system/mariadb.service.d/override.conf
nano /etc/systemd/system/mariadb.service.d/override.conf
Inside override.conf put this content and save.
[Service]
ProtectHome=false
Then run the following commands :
systemctl daemon-reload
/scripts/restartsrv_mysql
After restarting mysql, the variables can be checked by :
mysqladmin variables|grep tmp
I would like to log information on mysql database performances (tables spaces, number of queries...) in a file and then forward to a syslog remote server. Mysql is installed
on Linux. Is it possible?
Thanks
Creating a log file for example:
% sudo touch filename.log
Setting owner/group
% sudo chown mysql:wheel filename.log
Setting permissions to -rw-r-----
% sudo chmod 644 filename.log
To log queries taking longer than 2 seconds to a log file in /var/log directory add these to the my.cnf file:
[mysqld]
log_slow_queries=/var/log/mysql_slow_query.log
long_query_time=2