MySQL my.cnf file - Found option without preceding group - mysql

I'm trying to connect to my DB in Ubuntu remotely but I receive error message when trying to mysql -u root -p:
Found option without preceding group in config file: /etc/mysql/my.cnf at line: 1
my.cnf looks like:
[mysqld]
user = mysql
socket = /var/run/mysqld/mysqld.sock
port = 3306
basedir = /usr
datadir = /var/lib/mysql
tmpdir = /tmp
bind-address = 0.0.0.0
key_buffer = 16M
max_allowed_packet = 16M
thread_stack = 192K
thread_cache_size = 8
myisam-recover = BACKUP
query_cache_limit = 1M
query_cache_size = 16M
log_error = /var/log/mysql/error.log
expire_logs_days = 10
max_binlog_size = 100M
[client]
port = 3306
socket = /var/run/mysqld/mysqld.sock
[mysqld_safe]
socket = /var/run/mysqld/mysqld.sock
nice = 0
[mysqldump]
quick
quote-names
max_allowed_packet = 16M
[mysql]
[isamchk]
key_buffer = 16M

Missing config header
Just add [mysqld] as first line in the /etc/mysql/my.cnf file.
Example
[mysqld]
default-time-zone = "+08:00"
Afterwards, remember to restart your MySQL Service.
sudo mysqld stop
sudo mysqld start

Charset encoding
Check the charset encoding of the file. Make sure that it is in ASCII.
Use the od command to see if there is a UTF-8 BOM at the beginning, for example.

What worked for me:
Open my.ini with Notepad++
Encoding --> convert to ANSI
save

it is because of letters or digit infront of [mysqld] just check the leeters or digit anything is not required before [mysqld]
it may be something like
0[mysqld] then this error will occur

I had this problem when I installed MySQL 8.0.15 with the community installer. The my.ini file that came with the installer did not work correctly after it had been edited. I did a full manual install by downloading that zip folder. I was able to create my own my.ini file containing only the parameters that I was concerned about and it worked.
download zip file from MySQL website
unpack the folder into C:\program files\MySQL\MySQL8.0
within the MySQL8.0 folder that you unpacked the zip folder into, create a text file and save it as my.ini
include the parameters in that my.ini file that you are concerned about. so something like this(just ensure that there is already a folder created for the datadir or else initialization won't work):
[mysqld]
basedire=C:\program files\MySQL\MySQL8.0
datadir=D:\MySQL\Data
....continue with whatever parameters you want to include
initialize the data directory by running these two commands in the command prompt:
cd C:\program files\MySQL\MySQL8.0\bin
mysqld --default-file=C:\program files\MySQL\MySQL8.0\my.ini --initialize
install the MySQL server as a service by running these two commands:
cd C:\program files\MySQL\MySQL8.0\bin
mysqld --install --default-file=C:\program files\MySQL\MySQL8.0\my.ini
finally, start the server for the first time by running these two commands:
cd C:\program files\MySQL\MySQL8.0\bin
mysqld --console

Related

I am using LOAD DATA LOCAL INFILE <URL> query In sql but ERROR: #2000 - LOAD DATA LOCAL INFILE is forbidden, check mysqli.allow_local_infile [duplicate]

Is there a MySQL command to locate the my.cnf configuration file, similar to how PHP's phpinfo() locates its php.ini?
There is no internal MySQL command to trace this, it's a little too abstract. The file might be in 5 (or more?) locations, and they would all be valid because they load cascading.
/etc/my.cnf
/etc/mysql/my.cnf
$MYSQL_HOME/my.cnf
[datadir]/my.cnf
~/.my.cnf
Those are the default locations MySQL looks at. If it finds more than one, it will load each of them & values override each other (in the listed order, I think). Also, the --defaults-file parameter can override the whole thing, so... basically, it's a huge pain in the butt.
But thanks to it being so confusing, there's a good chance it's just in /etc/my.cnf.
(If you just want to see the values: SHOW VARIABLES, but you'll need the permissions to do so.)
Run mysql --help and you will see:
Default options are read from the following files in the given order: /etc/my.cnf /etc/mysql/my.cnf ~/.my.cnf
You can actually "request" MySQL for a list of all locations where it searches for my.cnf (or my.ini on Windows). It is not an SQL query though. Rather, execute:
$ mysqladmin --help
or, prior 5.7:
$ mysqld --help --verbose
In the very first lines you will find a message with a list of all my.cnf locations it looks for. On my machine it is:
Default options are read from the following files in the given order:
/etc/my.cnf
/etc/mysql/my.cnf
/usr/etc/my.cnf
~/.my.cnf
Or, on Windows:
Default options are read from the following files in the given order:
C:\Windows\my.ini
C:\Windows\my.cnf
C:\my.ini
C:\my.cnf
C:\Program Files\MySQL\MySQL Server 5.5\my.ini
C:\Program Files\MySQL\MySQL Server 5.5\my.cnf
Note however, that it might be the case that there is no my.cnf file at any of these locations. So, you can create the file on your own - use one of the sample config files provided with MySQL distribution (on Linux - see /usr/share/mysql/*.cnf files and use whichever is appropriate for you - copy it to /etc/my.cnf and then modify as needed).
Also, note that there is also a command line option --defaults-file which may define custom path to my.cnf or my.ini file. For example, this is the case for MySQL 5.5 on Windows - it points to a my.ini file in the data directory, which is not normally listed with mysqld --help --verbose. On Windows - see service properties to find out if this is the case for you.
Finally, check the https://dev.mysql.com/doc/refman/8.0/en/option-files.html - it is described there in more details.
You could always run find in a terminal.
find / -name my.cnf
mysql --help | grep /my.cnf | xargs ls
will tell you where my.cnf is located on Mac/Linux
ls: cannot access '/etc/my.cnf': No such file or directory
ls: cannot access '~/.my.cnf': No such file or directory
/etc/mysql/my.cnf
In this case, it is in /etc/mysql/my.cnf
ls: /etc/my.cnf: No such file or directory
ls: /etc/mysql/my.cnf: No such file or directory
ls: ~/.my.cnf: No such file or directory
/usr/local/etc/my.cnf
In this case, it is in /usr/local/etc/my.cnf
You can use :
locate my.cnf
whereis my.cnf
find . -name my.cnf
This might work:
strace mysql ";" 2>&1 | grep cnf
on my machine this outputs:
stat64("/etc/my.cnf", 0xbf9faafc) = -1 ENOENT (No such file or directory)
stat64("/etc/mysql/my.cnf", {st_mode=S_IFREG|0644, st_size=4271, ...}) = 0
open("/etc/mysql/my.cnf", O_RDONLY|O_LARGEFILE) = 3
read(3, "# /etc/mysql/my.cnf: The global "..., 4096) = 4096
stat64("/home/xxxxx/.my.cnf", 0xbf9faafc) = -1 ENOENT (No such file or directory)
So it looks like /etc/mysql/my.cnf is the one since it stat64() and read() were successful.
By default, mysql search my.cnf first at /etc folder. If there is no /etc/my.cnf file inside this folder, I advise you to create new one in this folder as indicated by the documentation (https://dev.mysql.com/doc/refman/5.6/en/option-files.html).
You can also search for existing my.cnf furnished by your mysql installation. You can launch the following command
sudo find / -name "*.cnf"
You can use the following configuration file with myisam table and without innodb mysql support (from port installation of mysql on mac os x maverick). Please verify each command in this configuration file.
# Example MySQL config file for large systems.
#
# This is for a large system with memory = 512M where the system runs mainly
# MySQL.
#
# MySQL programs look for option files in a set of
# locations which depend on the deployment platform.
# You can copy this option file to one of those
# locations. For information about these locations, see:
# http://dev.mysql.com/doc/mysql/en/option-files.html
#
# In this file, you can use all long options that a program supports.
# If you want to know which options a program supports, run the program
# with the "--help" option.
# The following options will be passed to all MySQL clients
[client]
#password = your_password
port = 3306
socket = /opt/local/var/run/mysql5/mysqld.sock
# Here follows entries for some specific programs
# The MySQL server
[mysqld]
port = 3306
socket = /opt/local/var/run/mysql5/mysqld.sock
skip-locking
key_buffer_size = 256M
max_allowed_packet = 1M
table_open_cache = 256
sort_buffer_size = 1M
read_buffer_size = 1M
read_rnd_buffer_size = 4M
myisam_sort_buffer_size = 64M
thread_cache_size = 8
query_cache_size= 16M
# Try number of CPU's*2 for thread_concurrency
thread_concurrency = 8
# Don't listen on a TCP/IP port at all. This can be a security enhancement,
# if all processes that need to connect to mysqld run on the same host.
# All interaction with mysqld must be made via Unix sockets or named pipes.
# Note that using this option without enabling named pipes on Windows
# (via the "enable-named-pipe" option) will render mysqld useless!
#
#skip-networking
# Replication Master Server (default)
# binary logging is required for replication
log-bin=mysql-bin
# binary logging format - mixed recommended
binlog_format=mixed
# required unique id between 1 and 2^32 - 1
# defaults to 1 if master-host is not set
# but will not function as a master if omitted
server-id = 1
# Replication Slave (comment out master section to use this)
#
# To configure this host as a replication slave, you can choose between
# two methods :
#
# 1) Use the CHANGE MASTER TO command (fully described in our manual) -
# the syntax is:
#
# CHANGE MASTER TO MASTER_HOST=<host>, MASTER_PORT=<port>,
# MASTER_USER=<user>, MASTER_PASSWORD=<password> ;
#
# where you replace <host>, <user>, <password> by quoted strings and
# <port> by the master's port number (3306 by default).
#
# Example:
#
# CHANGE MASTER TO MASTER_HOST='125.564.12.1', MASTER_PORT=3306,
# MASTER_USER='joe', MASTER_PASSWORD='secret';
#
# OR
#
# 2) Set the variables below. However, in case you choose this method, then
# start replication for the first time (even unsuccessfully, for example
# if you mistyped the password in master-password and the slave fails to
# connect), the slave will create a master.info file, and any later
# change in this file to the variables' values below will be ignored and
# overridden by the content of the master.info file, unless you shutdown
# the slave server, delete master.info and restart the slaver server.
# For that reason, you may want to leave the lines below untouched
# (commented) and instead use CHANGE MASTER TO (see above)
#
# required unique id between 2 and 2^32 - 1
# (and different from the master)
# defaults to 2 if master-host is set
# but will not function as a slave if omitted
#server-id = 2
#
# The replication master for this slave - required
#master-host = <hostname>
#
# The username the slave will use for authentication when connecting
# to the master - required
#master-user = <username>
#
# The password the slave will authenticate with when connecting to
# the master - required
#master-password = <password>
#
# The port the master is listening on.
# optional - defaults to 3306
#master-port = <port>
#
# binary logging - not required for slaves, but recommended
#log-bin=mysql-bin
# Uncomment the following if you are using InnoDB tables
#innodb_data_home_dir = /opt/local/var/db/mysql5
#innodb_data_file_path = ibdata1:10M:autoextend
#innodb_log_group_home_dir = /opt/local/var/db/mysql5
# You can set .._buffer_pool_size up to 50 - 80 %
# of RAM but beware of setting memory usage too high
#innodb_buffer_pool_size = 256M
#innodb_additional_mem_pool_size = 20M
# Set .._log_file_size to 25 % of buffer pool size
#innodb_log_file_size = 64M
#innodb_log_buffer_size = 8M
#innodb_flush_log_at_trx_commit = 1
#innodb_lock_wait_timeout = 50
[mysqldump]
quick
max_allowed_packet = 16M
[mysql]
no-auto-rehash
# Remove the next comment character if you are not familiar with SQL
#safe-updates
[myisamchk]
key_buffer_size = 128M
sort_buffer_size = 128M
read_buffer = 2M
write_buffer = 2M
[mysqlhotcopy]
interactive-timeout
For Ubuntu 16: /etc/mysql/mysql.conf.d/mysqld.cnf
As noted by konyak you can get the list of places mysql will look for your my.cnf file by running mysqladmin --help. Since this is pretty verbose you can get to the part you care about quickly with:
$ mysqladmin --help | grep -A1 'Default options'
This will give you output similar to:
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
Depending on how you installed mysql it is possible that none of these files are present yet. You can cat them in order to see how your config is being built and create your own my.cnf if needed at your preferred location.
I don't know how you've setup MySQL on your Linux environment but have you checked?
/etc/my.cnf
Try running mysqld --help --verbose | grep my.cnf | tr " " "\n"
Output will be something like
/etc/my.cnf
/etc/mysql/my.cnf
/usr/local/etc/my.cnf
~/.my.cnf
You can also run this command.
mysql --help | grep cnf
If you're on a Mac with Homebrew, use
brew info mysql
You'll see something like
$ brew info mysql
mysql: stable 5.6.13 (bottled)
http://dev.mysql.com/doc/refman/5.6/en/
Conflicts with: mariadb, mysql-cluster, percona-server
/usr/local/Cellar/mysql/5.6.13 (9381 files, 354M) *
That last line is the INSTALLERDIR per the MySQL docs
Be aware that although mariadDB loads configuration details from the various my.cnf files as listed in the other answers here, it can also load them from other files with different names.
That means that if you make a change in one of the my.cnf files, it may get overwritten by another file of a different name. To make the change stick, you need to change it in the right (last loaded) config file - or, maybe, change it in all of them.
So how do you find all the config files that might be loaded? Instead of looking for my.cnf files, try running:
grep -r datadir /etc/mysql/
This will find all the places in which datadir is mentioned. In my case, it produces this answer:
/etc/mysql/mariadb.conf.d/50-server.cnf:datadir = /var/lib/mysql
When I edit that file (/etc/mysql/mariadb.conf.d/50-server.cnf) to change the value for datadir, it works, whereas changing it in my.cnf does not. So whatever option you are wanting to change, try looking for it this way.
If you are on Debian/Ubuntu system and already equipped with modern versions of the database (everything from 5.7 up, also true for mysql 8) the best way to locate the actual .cnf file I have found is:
sudo update-alternatives --config my.cnf
You should see a output like this:
There are 3 choices for the alternative my.cnf (providing /etc/mysql/my.cnf).
Selection Path Priority Status
------------------------------------------------------------
0 /etc/mysql/mariadb.cnf 500 auto mode
1 /etc/mysql/mariadb.cnf 500 manual mode
2 /etc/mysql/my.cnf.fallback 100 manual mode
* 3 /etc/mysql/mysql.cnf 300 manual mode
There are two lines in /etc/mysql/mysql.cnf that it makes sense to pay attention to:
!includedir /etc/mysql/conf.d/
!includedir /etc/mysql/mysql.conf.d/
MySQL will go watching for all .cnf files in /etc/mysql/conf.d/, then all files in /etc/mysql/mysql.conf.d/
Happy tuning!
Found mine using
mysqld --help --verbose | grep my.cnf
Answered for only MySQL Workbench users,
Another option is to use the whereis command.
E.g. whereis my.cnf
I installed xampp bundle with apache, php and mysql in ubuntu. There my.cnf file is located in /opt/lampp/etc/ folder. Hope it'll help somebody.
All great suggestions, in my case I didn't find it in any of those locations, but in /usr/share/mysql, I have a RHEL VM and I installed mysql5.5
You will have to look through the various locations depending on your version of MySQL.
mysqld --help -verbose | grep my.cnf
For Homebrew:
/usr/local/Cellar/mysql/8.0.11/bin/mysqld (mysqld 8.0.11)
Default possible locations:
/etc/my.cnf
/etc/mysql/my.cnf
~/.my.cnf
Found mine here:
/usr/local/etc/my.cnf
On Ubuntu (direct edit) :
$ sudo nano /etc/mysql.conf.d/mysqld.cnf
In case you are in a VPS and are trying to edit a my.cnf on an already running server you could try:
ps aux | grep mysql
You will be show the parameters the mysql command is being run and where the --defaults-file points to
Note that your server might be running more than one MySQL/MariaDB server's. If you see a line without --defaults-file parameter, that instance might be retrieving the configuration from the .cnf's that are mentioned on mysqladmin --help as others have pointed out.
You can find my.cnf or any other file with find command:
find / -name my.cnf (or any other file name)
find is a command
/ (slash) is a path
my.cnf is a file name
If you are using MAMP, access Templates > MySQL (my.cnf) > [version]
If you are running MAMP windowless you may need to customize the toolbar using the Customize button.
for me it was that i had "ENGINE=MyISAM" kind of tables , once i changed it to "ENGINE=InnoDB" it worked:)
in PhpMyAdmin on Azure App Service :)
It depend on your access right but for me
this work on phpmyadmin sql console
SHOW VARIABLES;
then after to change some variables
you can do
SET GLOBAL max_connections = 1000;
or
SET ##GLOBAL.max_connections = 1000;
give a try
MySQL configuration file:
/etc/my.cnf
try
mysql --verbose --help | grep -A 1 "Default options"
For MariaDB 10.5 on Ubuntu 20.04.4 LTS (Focal Fossa):
# The MariaDB configuration file
#
# The MariaDB/MySQL tools read configuration files in the following order:
# 0. "/etc/mysql/my.cnf" symlinks to this file, reason why all the rest is read.
# 1. "/etc/mysql/mariadb.cnf" (this file) to set global defaults,
# 2. "/etc/mysql/conf.d/*.cnf" to set global options.
# 3. "/etc/mysql/mariadb.conf.d/*.cnf" to set MariaDB-only options.
# 4. "~/.my.cnf" to set user-specific options.
#
# If the same option is defined multiple times, the last one will apply.

MySQL server will not start from the teminal using 'mysqld' after update

After a recent system update I am having an issue getting the MySQL development server to start up using the 'mysqld' command from the terminal. I receive the error "[ERROR] InnoDB: Unable to lock ./ibdata1 error: 35"
I originally installed MySQL with brew, so I thought it might be a simple issue with the path but I've double checked and mysql is pointed at the /usr/local installation. I also checked for blocking by other running instances using htop, but found nothing.
Everything I've found online for the error seems to date back to Snow Leopard or involves using the wrong command (I checked the docs) Not even sure where to start looking for the issue based on available info.
System config:
Mac OSX 10.11.5 ElCapitan
MySQL version 5.7.11
Bash 4.3
This is my my.cnf file:
[client]
user = *my username*
password = *my password (file read permission set to 700)
port = 3306
socket = /var/mysql/mysql.sock
[mysqld]
port = 3306
socket = /var/mysql/mysql.sock
# basedir = /usr
# datadir = /var/lib/mysql
skip-external-locking
key_buffer_size = 16M
max_allowed_packet = 1M
table_open_cache = 64
sort_buffer_size = 512K
net_buffer_length = 8K
read_buffer_size = 256K
read_rnd_buffer_size = 512K
myisam_sort_buffer_size = 8M
[mysqldump]
quick
max_allowed_packet = 16M
[mysql]
no-auto-rehash
Anyone have any suggestions?
Well...I feel silly now.
Using the 'mysqladmin' command I was able to determine the default order in which config files are read on my machine:
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
My my.cnf file wasn't living at any of those locations, so after moving it to the '/etc/' folder I tried starting the server and it started right up.

OpenWrt install mysql-server

I am trying to install mysql-server on OpenWrt.
mysql_install_db --force gives me error:
/usr/bin/my_print_defaults: can't load library 'libnsl.so.0'
FATAL ERROR: Could not find /usr/lib/mysqld
If you compiled from source, you need to run 'make install' to copy
the software into the correct location ready for operation.
If you are using a binary release, you must either be at the top level
of the extracted archive, or pass the --basedir option pointing to
that location.
I have install Libc but I can' find libnsl.so.0 under /usr/lib
I have my.cnf under /etc/
Content of my.cnf:
root#OpenWrt:/etc# cat my.cnf
[client]
port = 3306
socket = /var/run/mysqld.sock
[mysqld]
user = root
socket = /var/run/mysqld.sock
port = 3306
basedir = /usr
############ Don't put this on the NAND #############
# Figure out where you are going to put the databases
# And run mysql_install_db --force
datadir = /mnt/data/mysql/
######### This should also not go on the NAND #######
tmpdir = /mnt/data/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
# Here you can see queries with especially long duration
#log_slow_queries = /var/log/mysql/mysql-slow.log
#long_query_time = 2
#log-queries-not-using-indexes
# The following can be used as easy to replay backup logs or for replication.
#server-id = 1
#log_bin = /var/log/mysql/mysql-bin.log
#expire_logs_days = 10
#max_binlog_size = 100M
#binlog_do_db = include_database_name
#binlog_ignore_db = include_database_name
[mysqldump]
quick
quote-names
max_allowed_packet = 16M
[mysql]
#no-auto-rehash # faster start of mysql but no tab completition
[isamchk]
key_buffer = 16M
I also created mkdir /usr/lib/mysqld folder.
drwxr-xr-x 2 root root 4096 Mar 19 17:39 mysqld
Then I get error:
/usr/bin/my_print_defaults: can't load library 'libnsl.so.0'
Installing MySQL system tables...
/usr/bin/mysql_install_db: line 418: /usr/lib/mysqld: Permission denied
Installation of system tables failed! Examine the logs in
/var for more information.
You can try to start the mysqld daemon with:
shell> /usr/lib/mysqld --skip-grant &
and use the command line tool /usr/bin/mysql
to connect to the mysql database and look at the grant tables:
shell> /usr/bin/mysql -u root mysql
mysql> show tables
Try 'mysqld --help' if you have problems with paths. Using --log
gives you a log in /var that may be helpful.
Please consult the MySQL manual section
'Problems running mysql_install_db', and the manual section that
describes problems on your OS. Another information source are the
MySQL email archives available at http://lists.mysql.com/.
Please check all of the above before mailing us! And remember, if
you do mail us, you MUST use the /usr/bin/mysqlbug script!
I also tried:
cd /usr/lib
wget http://trac.augsburg.freifunk.net/export/3/trunk/freifunk-openwrt-kit-1.6.20-de/root/lib/libnsl.so.0 libnsl.so.0
Then I get error:
'/usr/lib/libnsl.so.0' is not an ELF file
I do not know what to do any more.
Please give me some idea! Thanks!
UPDATE:
I have updated opkg.conf
Removed mysql-server
And istall mysql-server from new url provided in opkg.conf
mysql_install_db works now great.
I can start mysqld without error BUT
I CANT CHANGE ROOT PASSWORD
/usr/bin/mysqladmin -u root password 'xxxxxxxxx'
/usr/bin/mysqladmin: can't load library 'libnsl.so.0'
any other option to change mysql root password?
UPDATE2:
Install: http://downloads.openwrt.org/attitude_adjustment/12.09/ar71xx/generic/packages/libmysqlclient_5.1.53-7_ar71xx.ipk
WORKS!!!!

multiple instances mysql on ubuntu error

I have been trying to make multiple instances of mysql on ubuntu. These are the steps I followed.
mv /etc/init.d/mysql /etc/init.d/mysql_mono.server
cp /usr/share/mysql/mysqld_multi.server /etc/init.d/mysql
With your favourite text editor, edit /etc/init.d/mysql, then find the lines:
basedir=/usr/local/mysql
bindir=/usr/local/mysql/bin
And change to:
basedir=/usr
bindir=/usr/bin
If your have a root password in localhost, edit the file /usr/bin/mysqld_multi, then find the line:
$opt_password = undef()
And change to:
$opt_password = "password"
changing "password" by the 'root'#'localhost' password.
Now create a database directory for each additional mysqld instance:
# cp -pr /var/lib/mysql /var/lib/mysql1
# cp -pr /var/lib/mysql /var/lib/mysql2
My configuration file(my.cnf) is:
[client]
port = 3306
socket = /var/run/mysqld/mysqld.sock
# Here is entries for some specific programs
# The following values assume you have at least 32M ram
# This was formally known as [safe_mysqld]. Both versions are currently parsed.
[mysqld_safe]
socket = /var/run/mysqld/mysqld.sock
nice = 0
[mysqld1]
user = root
pid-file = /var/run/mysqld1.pid
socket = /var/run/mysqld1.sock
port = 3301
datadir = /var/lib/mysql1
log = /var/log/mysql/mysql1.log
server-id = 1
log_bin = /var/log/mysql/mysql1-bin.log
[mysqld2]
user = root
pid-file = /var/run/mysqld2.pid
socket = /var/run/mysqld2.sock
port = 3302
datadir = /var/lib/mysql2
log = /var/log/mysql/mysql2.log
server-id = 2
log_bin = /var/log/mysql/mysql2-bin.log
# This replaces the startup script and checks MyISAM tables if needed
# the first time they are touched
myisam-recover = BACKUP
#max_connections = 100
#table_cache = 64
#thread_concurrency = 10
#
# * Query Cache Configuration
#
query_cache_limit = 1M
query_cache_size = 16M
#
# * Logging and Replication
#
# Both location gets rotated by the cronjob.
# Be aware that this log type is a performance killer.
# As of 5.1 you can enable the log at runtime!
#general_log_file = /var/log/mysql/mysql.log
#general_log = 1
log_error = /var/log/mysql/error.log
[mysqldump]
quick
quote-names
max_allowed_packet = 16M
[mysql]
#no-auto-rehash # faster start of mysql but no tab completition
[isamchk]
key_buffer = 16M
``!includedir /etc/mysql/conf.d/
Still I get this error when i run following command:
mysql --socket=/var/run/mysqld1.sock -uroot
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld1.sock' (2)
via http://dev.mysql.com/doc/refman/5.5/en/multiple-unix-servers.html
One way is to run multiple MySQL instances on Unix is to compile
different servers with different default TCP/IP ports and Unix socket
files so that each one listens on different network interfaces.
Compiling in different base directories for each installation also
results automatically in a separate, compiled-in data directory, log
file, and PID file location for each server.
Assume that an existing 5.1 server is configured for the default
TCP/IP port number (3306) and Unix socket file (/tmp/mysql.sock). To
configure a new 5.5.35 server to have different operating parameters,
use a CMake command something like this:
shell> cmake . -DMYSQL_TCP_PORT=port_number \
-DMYSQL_UNIX_ADDR=file_name \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql-5.5.35

How do I find the MySQL my.cnf location

Is there a MySQL command to locate the my.cnf configuration file, similar to how PHP's phpinfo() locates its php.ini?
There is no internal MySQL command to trace this, it's a little too abstract. The file might be in 5 (or more?) locations, and they would all be valid because they load cascading.
/etc/my.cnf
/etc/mysql/my.cnf
$MYSQL_HOME/my.cnf
[datadir]/my.cnf
~/.my.cnf
Those are the default locations MySQL looks at. If it finds more than one, it will load each of them & values override each other (in the listed order, I think). Also, the --defaults-file parameter can override the whole thing, so... basically, it's a huge pain in the butt.
But thanks to it being so confusing, there's a good chance it's just in /etc/my.cnf.
(If you just want to see the values: SHOW VARIABLES, but you'll need the permissions to do so.)
Run mysql --help and you will see:
Default options are read from the following files in the given order: /etc/my.cnf /etc/mysql/my.cnf ~/.my.cnf
You can actually "request" MySQL for a list of all locations where it searches for my.cnf (or my.ini on Windows). It is not an SQL query though. Rather, execute:
$ mysqladmin --help
or, prior 5.7:
$ mysqld --help --verbose
In the very first lines you will find a message with a list of all my.cnf locations it looks for. On my machine it is:
Default options are read from the following files in the given order:
/etc/my.cnf
/etc/mysql/my.cnf
/usr/etc/my.cnf
~/.my.cnf
Or, on Windows:
Default options are read from the following files in the given order:
C:\Windows\my.ini
C:\Windows\my.cnf
C:\my.ini
C:\my.cnf
C:\Program Files\MySQL\MySQL Server 5.5\my.ini
C:\Program Files\MySQL\MySQL Server 5.5\my.cnf
Note however, that it might be the case that there is no my.cnf file at any of these locations. So, you can create the file on your own - use one of the sample config files provided with MySQL distribution (on Linux - see /usr/share/mysql/*.cnf files and use whichever is appropriate for you - copy it to /etc/my.cnf and then modify as needed).
Also, note that there is also a command line option --defaults-file which may define custom path to my.cnf or my.ini file. For example, this is the case for MySQL 5.5 on Windows - it points to a my.ini file in the data directory, which is not normally listed with mysqld --help --verbose. On Windows - see service properties to find out if this is the case for you.
Finally, check the https://dev.mysql.com/doc/refman/8.0/en/option-files.html - it is described there in more details.
You could always run find in a terminal.
find / -name my.cnf
mysql --help | grep /my.cnf | xargs ls
will tell you where my.cnf is located on Mac/Linux
ls: cannot access '/etc/my.cnf': No such file or directory
ls: cannot access '~/.my.cnf': No such file or directory
/etc/mysql/my.cnf
In this case, it is in /etc/mysql/my.cnf
ls: /etc/my.cnf: No such file or directory
ls: /etc/mysql/my.cnf: No such file or directory
ls: ~/.my.cnf: No such file or directory
/usr/local/etc/my.cnf
In this case, it is in /usr/local/etc/my.cnf
You can use :
locate my.cnf
whereis my.cnf
find . -name my.cnf
This might work:
strace mysql ";" 2>&1 | grep cnf
on my machine this outputs:
stat64("/etc/my.cnf", 0xbf9faafc) = -1 ENOENT (No such file or directory)
stat64("/etc/mysql/my.cnf", {st_mode=S_IFREG|0644, st_size=4271, ...}) = 0
open("/etc/mysql/my.cnf", O_RDONLY|O_LARGEFILE) = 3
read(3, "# /etc/mysql/my.cnf: The global "..., 4096) = 4096
stat64("/home/xxxxx/.my.cnf", 0xbf9faafc) = -1 ENOENT (No such file or directory)
So it looks like /etc/mysql/my.cnf is the one since it stat64() and read() were successful.
By default, mysql search my.cnf first at /etc folder. If there is no /etc/my.cnf file inside this folder, I advise you to create new one in this folder as indicated by the documentation (https://dev.mysql.com/doc/refman/5.6/en/option-files.html).
You can also search for existing my.cnf furnished by your mysql installation. You can launch the following command
sudo find / -name "*.cnf"
You can use the following configuration file with myisam table and without innodb mysql support (from port installation of mysql on mac os x maverick). Please verify each command in this configuration file.
# Example MySQL config file for large systems.
#
# This is for a large system with memory = 512M where the system runs mainly
# MySQL.
#
# MySQL programs look for option files in a set of
# locations which depend on the deployment platform.
# You can copy this option file to one of those
# locations. For information about these locations, see:
# http://dev.mysql.com/doc/mysql/en/option-files.html
#
# In this file, you can use all long options that a program supports.
# If you want to know which options a program supports, run the program
# with the "--help" option.
# The following options will be passed to all MySQL clients
[client]
#password = your_password
port = 3306
socket = /opt/local/var/run/mysql5/mysqld.sock
# Here follows entries for some specific programs
# The MySQL server
[mysqld]
port = 3306
socket = /opt/local/var/run/mysql5/mysqld.sock
skip-locking
key_buffer_size = 256M
max_allowed_packet = 1M
table_open_cache = 256
sort_buffer_size = 1M
read_buffer_size = 1M
read_rnd_buffer_size = 4M
myisam_sort_buffer_size = 64M
thread_cache_size = 8
query_cache_size= 16M
# Try number of CPU's*2 for thread_concurrency
thread_concurrency = 8
# Don't listen on a TCP/IP port at all. This can be a security enhancement,
# if all processes that need to connect to mysqld run on the same host.
# All interaction with mysqld must be made via Unix sockets or named pipes.
# Note that using this option without enabling named pipes on Windows
# (via the "enable-named-pipe" option) will render mysqld useless!
#
#skip-networking
# Replication Master Server (default)
# binary logging is required for replication
log-bin=mysql-bin
# binary logging format - mixed recommended
binlog_format=mixed
# required unique id between 1 and 2^32 - 1
# defaults to 1 if master-host is not set
# but will not function as a master if omitted
server-id = 1
# Replication Slave (comment out master section to use this)
#
# To configure this host as a replication slave, you can choose between
# two methods :
#
# 1) Use the CHANGE MASTER TO command (fully described in our manual) -
# the syntax is:
#
# CHANGE MASTER TO MASTER_HOST=<host>, MASTER_PORT=<port>,
# MASTER_USER=<user>, MASTER_PASSWORD=<password> ;
#
# where you replace <host>, <user>, <password> by quoted strings and
# <port> by the master's port number (3306 by default).
#
# Example:
#
# CHANGE MASTER TO MASTER_HOST='125.564.12.1', MASTER_PORT=3306,
# MASTER_USER='joe', MASTER_PASSWORD='secret';
#
# OR
#
# 2) Set the variables below. However, in case you choose this method, then
# start replication for the first time (even unsuccessfully, for example
# if you mistyped the password in master-password and the slave fails to
# connect), the slave will create a master.info file, and any later
# change in this file to the variables' values below will be ignored and
# overridden by the content of the master.info file, unless you shutdown
# the slave server, delete master.info and restart the slaver server.
# For that reason, you may want to leave the lines below untouched
# (commented) and instead use CHANGE MASTER TO (see above)
#
# required unique id between 2 and 2^32 - 1
# (and different from the master)
# defaults to 2 if master-host is set
# but will not function as a slave if omitted
#server-id = 2
#
# The replication master for this slave - required
#master-host = <hostname>
#
# The username the slave will use for authentication when connecting
# to the master - required
#master-user = <username>
#
# The password the slave will authenticate with when connecting to
# the master - required
#master-password = <password>
#
# The port the master is listening on.
# optional - defaults to 3306
#master-port = <port>
#
# binary logging - not required for slaves, but recommended
#log-bin=mysql-bin
# Uncomment the following if you are using InnoDB tables
#innodb_data_home_dir = /opt/local/var/db/mysql5
#innodb_data_file_path = ibdata1:10M:autoextend
#innodb_log_group_home_dir = /opt/local/var/db/mysql5
# You can set .._buffer_pool_size up to 50 - 80 %
# of RAM but beware of setting memory usage too high
#innodb_buffer_pool_size = 256M
#innodb_additional_mem_pool_size = 20M
# Set .._log_file_size to 25 % of buffer pool size
#innodb_log_file_size = 64M
#innodb_log_buffer_size = 8M
#innodb_flush_log_at_trx_commit = 1
#innodb_lock_wait_timeout = 50
[mysqldump]
quick
max_allowed_packet = 16M
[mysql]
no-auto-rehash
# Remove the next comment character if you are not familiar with SQL
#safe-updates
[myisamchk]
key_buffer_size = 128M
sort_buffer_size = 128M
read_buffer = 2M
write_buffer = 2M
[mysqlhotcopy]
interactive-timeout
For Ubuntu 16: /etc/mysql/mysql.conf.d/mysqld.cnf
As noted by konyak you can get the list of places mysql will look for your my.cnf file by running mysqladmin --help. Since this is pretty verbose you can get to the part you care about quickly with:
$ mysqladmin --help | grep -A1 'Default options'
This will give you output similar to:
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
Depending on how you installed mysql it is possible that none of these files are present yet. You can cat them in order to see how your config is being built and create your own my.cnf if needed at your preferred location.
I don't know how you've setup MySQL on your Linux environment but have you checked?
/etc/my.cnf
Try running mysqld --help --verbose | grep my.cnf | tr " " "\n"
Output will be something like
/etc/my.cnf
/etc/mysql/my.cnf
/usr/local/etc/my.cnf
~/.my.cnf
You can also run this command.
mysql --help | grep cnf
If you're on a Mac with Homebrew, use
brew info mysql
You'll see something like
$ brew info mysql
mysql: stable 5.6.13 (bottled)
http://dev.mysql.com/doc/refman/5.6/en/
Conflicts with: mariadb, mysql-cluster, percona-server
/usr/local/Cellar/mysql/5.6.13 (9381 files, 354M) *
That last line is the INSTALLERDIR per the MySQL docs
Be aware that although mariadDB loads configuration details from the various my.cnf files as listed in the other answers here, it can also load them from other files with different names.
That means that if you make a change in one of the my.cnf files, it may get overwritten by another file of a different name. To make the change stick, you need to change it in the right (last loaded) config file - or, maybe, change it in all of them.
So how do you find all the config files that might be loaded? Instead of looking for my.cnf files, try running:
grep -r datadir /etc/mysql/
This will find all the places in which datadir is mentioned. In my case, it produces this answer:
/etc/mysql/mariadb.conf.d/50-server.cnf:datadir = /var/lib/mysql
When I edit that file (/etc/mysql/mariadb.conf.d/50-server.cnf) to change the value for datadir, it works, whereas changing it in my.cnf does not. So whatever option you are wanting to change, try looking for it this way.
If you are on Debian/Ubuntu system and already equipped with modern versions of the database (everything from 5.7 up, also true for mysql 8) the best way to locate the actual .cnf file I have found is:
sudo update-alternatives --config my.cnf
You should see a output like this:
There are 3 choices for the alternative my.cnf (providing /etc/mysql/my.cnf).
Selection Path Priority Status
------------------------------------------------------------
0 /etc/mysql/mariadb.cnf 500 auto mode
1 /etc/mysql/mariadb.cnf 500 manual mode
2 /etc/mysql/my.cnf.fallback 100 manual mode
* 3 /etc/mysql/mysql.cnf 300 manual mode
There are two lines in /etc/mysql/mysql.cnf that it makes sense to pay attention to:
!includedir /etc/mysql/conf.d/
!includedir /etc/mysql/mysql.conf.d/
MySQL will go watching for all .cnf files in /etc/mysql/conf.d/, then all files in /etc/mysql/mysql.conf.d/
Happy tuning!
Found mine using
mysqld --help --verbose | grep my.cnf
Answered for only MySQL Workbench users,
Another option is to use the whereis command.
E.g. whereis my.cnf
I installed xampp bundle with apache, php and mysql in ubuntu. There my.cnf file is located in /opt/lampp/etc/ folder. Hope it'll help somebody.
All great suggestions, in my case I didn't find it in any of those locations, but in /usr/share/mysql, I have a RHEL VM and I installed mysql5.5
You will have to look through the various locations depending on your version of MySQL.
mysqld --help -verbose | grep my.cnf
For Homebrew:
/usr/local/Cellar/mysql/8.0.11/bin/mysqld (mysqld 8.0.11)
Default possible locations:
/etc/my.cnf
/etc/mysql/my.cnf
~/.my.cnf
Found mine here:
/usr/local/etc/my.cnf
On Ubuntu (direct edit) :
$ sudo nano /etc/mysql.conf.d/mysqld.cnf
In case you are in a VPS and are trying to edit a my.cnf on an already running server you could try:
ps aux | grep mysql
You will be show the parameters the mysql command is being run and where the --defaults-file points to
Note that your server might be running more than one MySQL/MariaDB server's. If you see a line without --defaults-file parameter, that instance might be retrieving the configuration from the .cnf's that are mentioned on mysqladmin --help as others have pointed out.
You can find my.cnf or any other file with find command:
find / -name my.cnf (or any other file name)
find is a command
/ (slash) is a path
my.cnf is a file name
If you are using MAMP, access Templates > MySQL (my.cnf) > [version]
If you are running MAMP windowless you may need to customize the toolbar using the Customize button.
for me it was that i had "ENGINE=MyISAM" kind of tables , once i changed it to "ENGINE=InnoDB" it worked:)
in PhpMyAdmin on Azure App Service :)
It depend on your access right but for me
this work on phpmyadmin sql console
SHOW VARIABLES;
then after to change some variables
you can do
SET GLOBAL max_connections = 1000;
or
SET ##GLOBAL.max_connections = 1000;
give a try
MySQL configuration file:
/etc/my.cnf
try
mysql --verbose --help | grep -A 1 "Default options"
For MariaDB 10.5 on Ubuntu 20.04.4 LTS (Focal Fossa):
# The MariaDB configuration file
#
# The MariaDB/MySQL tools read configuration files in the following order:
# 0. "/etc/mysql/my.cnf" symlinks to this file, reason why all the rest is read.
# 1. "/etc/mysql/mariadb.cnf" (this file) to set global defaults,
# 2. "/etc/mysql/conf.d/*.cnf" to set global options.
# 3. "/etc/mysql/mariadb.conf.d/*.cnf" to set MariaDB-only options.
# 4. "~/.my.cnf" to set user-specific options.
#
# If the same option is defined multiple times, the last one will apply.