I have a bash script that connects to a mysql server and pulls information. I have my .my.cnf file in my home directory. I want to change the location of the .cnf file to ~myname/.my.cnf
My question is how do I reference this new location in my script or in my mysql call to the database?
Thanks
Here's the doc reference for how MySQL looks at Options Files:
https://dev.mysql.com/doc/refman/5.7/en/option-files.html
File Name Purpose
/etc/my.cnf Global options
/etc/mysql/my.cnf Global options
SYSCONFDIR/my.cnf Global options
$MYSQL_HOME/my.cnf Server-specific options (server only)
defaults-extra-file The file specified with --defaults-extra-file, if any
~/.my.cnf User-specific options
~/.mylogin.cnf User-specific login path options (clients only)
Note: you want to use defaults-extra-file option when connecting with mysql client. mysql --defaults-extra-file=~/path/to/file/.filename < script
You should consider using --login-path as an alternative. Login path reference. The file is not plain text. You use mysql_config_editor to create your login paths, which stores username, password, host, etc.
I don't know what you mean by "~myname/.my.cnf". This would expand to a directory made of a concatenation of your username and "myname" which doesn't make any sense. I guess you might mean "~/something/.my.cnf"
The '~' expands to $HOME hence simply redefining $HOME before invoking mysql should suffice (although this will confuse further references to '~'.
HOME=$HOME/myname
mysql <somescript.sql
Related
I wanted to disable some options in the MySql server strict mode, but for some reason I'm not even able to find its configuration file (my.cnf)
Currently installed MySql:
Ver 14.14 Distrib 5.7.20, for macos10.12 (x86_64)
Output generated by
mysql --help
Default options are read from the following files in the given order:
/etc/my.cnf
/etc/mysql/my.cnf
/usr/local/mysql/etc/my.cnf
~/.my.cnf
But there is no such file as my.conf
I had done some research work on SO but none of the advises has worked for me.
What I'm supposed to do?
There are defaults built into MySQL. The configuration file(s), if any, override the defaults.
Note that the config files are not looked at except during startup. So, editing or creating such a file has no effect until you restart mysqld.
If you mess up the syntax, mysqld will not start. Then you need to find the error, either during startup, or in a log file. (Or you could ask here "what is my syntax error".)
As for the location, and name, of the config files that will be used:
$ mysql --help
gives you the list for mysql, but perhaps you need it for the server, so try
$ mysqld --help --verbose
gives you long output; maybe 50 lines from the top, you should see something like:
Usage: mysqld [OPTIONS]
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
You asked about my.conf; was that a typo?
Regardless, If those files are missing, you can create them, make them readable by mysql, and put things into it preceded by [mysqld] so that the server will see them.
Personal override
Regardless of what is in the defaults and/or config files, you can add to the last file given. In the examples above that is 'hidden' .my.cnf in your home directory. All you need to do is create a few lines:
[mysql]
some_setting = somevalue
[client]
some_setting = somevalue
That helps for the "mysql" commandline tool and/or other clients (maybe).
But if you need to make changes to the server mysqld, it needs to be in one of the other files. Again, the minimum is something like
[mysqld]
some_setting = somevalue
Note the mysqld to refer to the server. And remember to restart the service.
Another note: If you see (in an existing config file), !includedir ..., then go to that directory to find any number of further files. You could add your own file, say z.cnf (so it would be picked last) with the two (or more) lines as indicated above.
If you have installed Mysql 8 or Above using the package installer from mysql website, then follow what i did
Create the config file in your home directory vim ~/.my.cnf
Do open System preferences in mac
Then Select the configuration file you created on the option.
The content in this website says.
I had the urgent need to configure some specific stuff in MySQL 5.7 on my developer machine, a MacBook Pro running Mac OS Sierra. Unfortunately, I did not find a my.cnf file that could be customized anywhere?
Internet research showed that MySQL Database Server on Mac OS runs without a my.cnf config file by default, simply started with default values.
Luckily, it is pretty simple to customize the MySQL Server installation by creating and editing a custom my.cnf file like this:
sudo cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf
Then edit / customize the /etc/my.cnf file as required and restart your MySQL Server.
Or you can refer to this answer
You could try:
$ locate mysql | grep my.cnf
It should reveal the location(s) if it exists.
What if there are more than one my.cnf files on my server?
Which configuration file will be looked by MySQL?
Assuming one runs mysql under linux, there the option-files will be read in that order:
the file specified by option --defaults-file=/PATH/TO/my.cnf while startup of mysqld
/etc/my.cnf
/etc/mysql/my.cnf
SYSCONFDIR/my.cnf (usually sysconfdir is /etc)
$MYSQL_HOME/my.cnf
the path set by --defaults-extra-file=/PATH/TO/my.cnf
~/my.cnf (your homedir, usually used for mysql-client configuration)
Also keep in mind that there are three options which change this behavior in MySQL:
-defaults-file=/PATH/TO/my.cnf - only read that option-file
-defaults-extra-file=/PATH/TO/myextra.cnf - read all global option-files, then this
-no-defaults - ignore every option-file and start with default
Please also refer to the docs on option-files: MySQL-Docs
The one specified on the command line that starts the mysqld process, or if no configuration file is specified, the default location. On Linux it is in /etc. I don't know where the Windows default is, but you can look in the documentation.
How to give a specific .my.cnf config file to the mysql command line?
$ mysql --my-config=.my.cnf
The --defaults-file option lets you specify which options file you want to use. It would be a good idea to give it the full path to your options file.
mysql --defaults-file=/home/user/.my.cnf database
In here: http://dev.mysql.com/doc/refman/5.5/en/option-files.html it says you can also specify "defaults-extra-file" for additional params. Otherwise it defaults to the various my.cnf (depending on OS).
I have installed XAMPP on OSX Lion.
Because I want to serve a folder from one of my development folders I have added a virtualhost to /Applications/XAMPP/xamppfiles/etc/extra/httpd-vhosts.conf
<VirtualHost *:80>
ServerAdmin email#gmail.com
DocumentRoot "/Users/myosxUsername/Documents/dir/dir/htdocs"
ServerName qmh
ErrorLog "logs/qmh-error_log"
CustomLog "logs/qmh-access_log" common
</VirtualHost>
and also added an entry to the hosts file
127.0.0.1 qmh
Because of permission issue with the server accessing the directory /Users/myosxUsername/Documents/dir/dir/htdocs I have also changed the user in httpd.conf to my myosxUsername
User myosxusername
Group admin
# previous setting below
# User nobody
# Group nobody
After those changes virtual hosts work fine.
The problem is that when i now use phpmyadmin to create a new database i get the error message
db_create.php: Missing parameter: new_db
if I change the user back to:
User nobody
Group nobody
then phpmyadmin works fine, but my virtualhost directory cannot be accessed due to permission issue.
I assume I somehow have to tell apache to not use the new user for mysql access somehow? Your help is appreciated. Thanks
See item 2.8 from phpMyAdmin FAQ (http://wiki.phpmyadmin.net/pma/FAQ_2.8)
In the php.ini directive session.save_path and upload_tmp_dir, if these directories don't exist, are read-only or not accessable (f.e.
due to base_dir restrictions) this error will occur. See trk
PHP installed from a packages (eg. an rpm) might set the permissions on these directories for an assumed user (eg. 'apache'). -
Users of other web servers, eg Lighttpd, may need to change the
ownership of these directories (eg. to 'lighttpd').
On Windows, if PHP is using directories for session.save_path and upload_tmp_dir that are somewhere within the main "Temp"
directory, you must create those directories yourself; unlike other
Windows programs PHP will not create them itself.
If you are using Hardened-PHP (/suhosin patch) with the ini directive varfilter.max_request_variables set to the default (200) or
another low value, you could get this error if your table has a high
number of columns. Adjust this setting accordingly ( request limits,
thanks to Klaus Dorninger for the hint).
In config.inc.php, try to leave the $cfg['PmaAbsoluteUri'] directive empty. See also FAQ 4.7.
Maybe you have a broken PHP installation or you need to upgrade your Zend Optimizer. See http://bugs.php.net/31134.
In the php.ini directive arg_separator.input, a value of ";" will cause this error. Replace it with "&;".
(tip from https://serverfault.com/questions/385465/phpmyadmin-missing-parameter)
My main MySQL user's /home//my.cnf file looks like this (Linux system):
[client]
host=localhost
user=<user>
password=********
database=h2o_amr
I want to point mysqldump to this config file, which is in the directory where the mysqldump file will be written:
[client]
host=localhost
user=<user>
password=********
How do I point mysqldump to this config file? I have searched for an answer to this in the man pages and the Internet before posting this question.
There are three options to change the default behavior:
--no-defaults: Don't read default options from any option file.
--defaults-file=#: Only read default options from the given file #.
--defaults-extra-file=#: Read this file after the global files are read.
This information was copied from the integrated manual, i.e.mysqldump --help | grep -A7 'Default options'.
Note: The parameter needs to be in first position if you add others parameters, if not it will not be recognized.
According to the documentation, there is a --defaults-file=PATH option that does exactly what you need. I tried it myself with mysqldump and it appears to have worked.
There are also other ways to have MySQL read option files without using that argument: using the default paths MySQL clients search through to compile the list of options (1st and 2nd table).