I am trying to log in to mysql with the --defaults-file option on the command line:
$ mysql --defaults-file ~/mycnf.cnf
But I get the following error:
mysql: unknown option '--defaults-file'
But this option is listed in the help:
$ mysql --help
...
Default options are read from the following files in the given order:
/etc/mysql/my.cnf /etc/my.cnf ~/.my.cnf
The following groups are read: mysql client
The following options may be given as the first argument:
--print-defaults Print the program argument list and exit.
--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.
--defaults-file=# Only read default options from the given file #.
Whats going on here? Here is the output of mysql --version
$ mysql --version
mysql Ver 14.14 Distrib 5.1.69, for redhat-linux-gnu (x86_64) using readline 5.1
In my case the issue was misplacement of the parameters.
the --console parameter should have been last...
My original take:
mysqld --console --defaults-file="path-to-ini/my.ini"
While should have run this:
mysqld --defaults-file="path-to-ini/my.ini" --console
It should be:
mysql --defaults-file=~/mycnf.cnf
You were missing the =.
Also note that the options used to specify option files must precede any other options. See the documentation for specific details.
I would like to add another answer to this problem to a similar situation I faced.
In my case, the command was similar to this:
/path/to/mysqld_safe start --defaults-file=/path/to/my.cnf --other-options-here
and mysql would complain
unknown variable '--defaults-file=/path/to/my.cnf'
In order to solve this, I had to "drop" the start command, making the line read like this:
/path/to/mysqld_safe --defaults-file=/path/to/my.cnf --other-options-here
And then mysql would finally start using the specified configuration file.
To solve the same issue using bash/sh script instead of directly on the cli with OSX, I had to use the full path of the mysql.client app.
$which mysql
/usr/local/zend/mysql/bin/mysql
MySql was installed by Zend Server as shown by the path below and wrapped the mysql.client version:
$mysql --version
/usr/local/zend/mysql/bin/mysql.client Ver 14.14 Distrib 5.5.27, for osx10.6 (i386) using readline 5.1
The error continues to show until I change how my bash script was calling mysql.
From:
MYSQL=`which mysql`
...
${MYSQL} --defaults-file=/dev/stdin -e "SHOW DATABASES"
output
$ ./import_dbs.sh
/usr/local/zend/mysql/bin/mysql.client: unknown variable 'defaults-file=/dev/stdin'
Change to:
MYSQL=/usr/local/zend/mysql/bin/mysql.client
...
${MYSQL} --defaults-file=/dev/stdin -e "SHOW DATABASES"
outputs
$ ./import_dbs.sh
Database
information_schema
mysql
performance_schema
test
Edit:
I could also use the following in my script:
MYSQL=`which mysql.client`
$ which mysql.client
/usr/local/zend/mysql/bin/mysql.client
Evidently there is a slight difference between calling mysql and mysql.client that affects being able to pass --defaults-file or other variables mentioned in the OP as the first parameter, within a script. I haven't tested via the shell
Related
Setup
mysql Ver 14.14 Distrib 5.7.38, for Linux (x86_64) using EditLine wrapper
Distributor ID: Ubuntu
Description: Ubuntu 18.04.5 LTS
Release: 18.04
Codename: bionic
MYSQL Keeps reseting my sql_mode and so my website is not working well.
The MySQL message is the following
Expression #18 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'testdevnew.f.created_at' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by
What I do till now is from terminal to connect inside mysql with the command
mysql -u root -p
and run the following commands
mysql> set global sql_mode='NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';
mysql> set session sql_mode='NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';
And the error is gone, but for a couple of days.. lets say that we restart mysql server and the above settings are gone.
Also tried to change the following files with the sql_mode that i would like to load after mysql restart.
File list
/etc/mysql/my.cnf
/etc/mysql/mysql.cnf
/etc/mysql/mysql.conf.d/mysqld.cnf
[mysqld]
sql_mode=NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
(I've also tried with value in quotes)
Then restart mysql
sudo service mysql restart
But the setting is not affecting mysql restart and I keep getting the error mentioned above.
mysqld --verbose --help
prints the following
sql-mode NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
Any ideas of what am I doing wrong?
You might have other my.cnf files being referenced by mysqld.
Also make sure those MySQL configuration files are owned by a mysql user and has read/write permission. Once restarted, verify using the code below whether your sql-mode configuration is loaded properly.
SELECT ##GLOBAL.sql_mode;
This thread, How to make sql-mode="NO_ENGINE_SUBSTITUTION" permanent in MySQL my.cnf has all the required steps to help you troubleshoot this issue.
Here (https://dev.mysql.com/doc/refman/5.5/en/server-system-variables.html) is sad, it is possible change value by comand line.
And here (https://dev.mysql.com/doc/refman/5.5/en/server-system-variables.html#sysvar_ft_min_word_len) is your format, but where and how i un this command, is in shell mysql or prompt linux?
i try:
me:/$ sudo mysql --ft-min-word-len=2
and the same in mysql shell:
MySQL [(none)]> mysql --ft-min-word-len=2
But both display errors, what is my mistake?
Im new on dbmanegement.
Try one of these :
1-In query editor, run set global ft-min-word-len=2;
2-Or in command line, use mysqld --ft-min-word-len=2 not mysql
3-Edit your config file (eg: /etc/mysql/my.cnf) , insert after [mysqld] section
[mysqld]
ft-min-word-len = 2
I'm used to having tab-completion for mysql keywords, database names etc in mysql, but in my freshly installed mysql (via 'apt-get install mysql-server') it only works for table names, not database names.
I am supplying the --auto-rehash option when starting the mysql command line client interface. I'm aware that I can set this as a default via my.cnf, but I want to get it working first.
The mysql docs tell me that the auto-rehash feature "requires a MySQL client that is compiled with the readline library."
'aptitude show mysql-client' tells me that I have 5.5.43-0ubuntu0.14.04.1.
For debugging purposes, how can I know if my mysql-client has readline, and if not, how do I get one that does?
Resolved: I wasn't specifying a database name when invoking the mysql command line interface!
Auto-completion works as expected if I go in as:
mysql -u root -p mysql # or
mysql -u root -p mydatabase
as opposed to:
mysql -u root -p
(and --auto-rehash clearly is on by default as per the docs)
I know this sounds stupid, but when I use
SELECT CONVERT_TZ('2004-01-01 12:00:00','UTC','Asia/Jakarta') AS time
it outputs NULL. I'm using MySQL Workbench in Ubuntu 12.04 64 bit, and it works in my other laptop/os (also using MySQL Workbench).
This will happen if you haven't loaded the time zone table into mysql.
mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root -p mysql
mysql is the name of the built-in database that holds MySQL-specific configuration data.
I found this thread after spending some time trying to figure out why after running the command in the accepted answer (which is the same on MySQL's dev site) the command was unable to convert between timezones such as
SELECT CONVERT_TZ('2004-01-01 12:00:00','UTC','MET') AS time
It turns out that on OS X there are two files that cause problems: /usr/share/zoneinfo/Factory and /usr/share/zoneinfo/+VERSION.
The fix... temporarily moving these files to a different location such as /usr/share/zoneinfo/.bak/ allows for the command
mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root -p mysql
to fully populate all of the expected timezone information.
This may or may not be a bug in my installed version of MySQL:
$ mysql --version
mysql Ver 14.14 Distrib 5.6.11, for osx10.6 (x86_64) using EditLine wrapper
I am also operating in STRICT_MODE.
In any case, I hope this saves a few headaches for anyone searching for the fix.
Apart from Windows environment, You can set Time Zone by
mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root -p mysql
In Windows environment,
1. download Time zone description tables from http://dev.mysql.com/downloads/timezones.html
2. Stop MySQL server
3. Put then inside Mysql installation package (ie. C:\Program Files\MySQL\data\mysql)`
4. Start MySQL server
..Your work is finished..
If still you are getting NULL for CONVERT_TZ
Download these database tables and insert it into mysql database http://www.4shared.com/folder/Toba2qu-/Mysql_timezone.html
Now you problem will be solved.. :)
MAMP PRO
Open Terminal
cd /usr/share/zoneinfo/
sudo mv +VERSION ~/Desktop
cd /applications/MAMP/Library/bin
sudo ./mysql_tzinfo_to_sql /usr/share/zoneinfo | ./mysql -p -u root mysql
sudo mv ~/Desktop/+VERSION /usr/share/zoneinfo/
1) In Windows, there isn't any data folder now in C:\Program Files\MySQL\ as in other answers.
2) In that case, look for C:\ProgramData\MySQL\MySQL Server 5.x\Data\mysql. Generally this folder hidden and you will not see C:\ProgramData\ some times.
3) Change the Settings in View tab to see Hidden files and Folders as explained here https://irch.info/index.php?pg=kb.page&id=133
4) Stop the MySQL service by searching for "services" in Windows Start button.
5) Then unzip the timezone_2017c_posix.zip and then copy the files in it (copy the files directly, don't copy the whole folder itself), and paste in
C:\ProgramData\MySQL\MySQLServer5.x\Data\mysql\
6) For MySQL 5.7, timezone_2017c_posix.zip will just give a .sql file after unzipping and it may not solve the issue. So go ahead and download the zip file for 5.6 even if you are running MySQL 5.7 and copy those files to C:\ProgramData\MySQL\MySQL Server 5.x\Data\mysql\
7) Restart the MySQL server. To check if the CONVERT_TZ () is working, run this sql query.
SELECT CONVERT_TZ('2004-01-01 12:00:00','UTC','Asia/Jakarta');
and check for non-null output.
These are the steps to make it work if you're in windows and using MySQL 5.7.
Right click on My Computer/Computer/This PC or whatever the name in your OS and choose Properties.
Choose "Advanced system settings" from the left panel.
Choose "Environmental Variables", enter the complete path name of your MySQL bin directory (generally it will be in, C:\Program Files\MySQL\MySQL Server 5.7\bin).
Open cmd prompt, enter into mysql using mysql -u root -p password.
Enter use mysql to select the MySQL DB.
Download the file "timezone_YYYYc_posix_sql.zip" (In the place of YYYY, substitute the maximum year available in that page like 2017 or 2018) from https://dev.mysql.com/downloads/timezones.html.
Extract it and open the file in text editor.
Copy the contents and execute in the cmd prompt.
On successful completion, you should be able to use CONVERT_TZ and other timezone functions.
If you are using MySql on Windows you have to load the timezone data into the mysql schema. Here is a good HOWTO: http://www.geeksengine.com/article/populate-time-zone-data-for-mysql.html
If you don't do this, the function CONVERT_TZ won't recognize your input timezone (i.e. your examples: 'UTC','Asia/Jakarta'), and will simply return NULL.
mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root -p mysql
if you get the error data too long for column 'abbreviation' at row 1
then see: https://bugs.mysql.com/bug.php?id=68861
the fix would be to run the following
this will add a line to disable the mysql mode and allow mysql to insert truncated data
this was because of a mysql bug where mysql would add a null character at the end (according to the above link)
mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root -p mysql
(if the above gives error "data too long for column 'abbreviation' at row 1")
mysql_tzinfo_to_sql /usr/share/zoneinfo > /tmp/zut.sql
echo "SET SESSION SQL_MODE = '';" > /tmp/mysql_tzinfo_to.sql
cat /tmp/zut.sql >> /tmp/mysql_tzinfo_to.sql
mysql --defaults-file=/etc/mysql/my.cnf --user=verifiedscratch -p mysql < /tmp/mysql_tzinfo_to.sql
On Mac OS Catalina when using XAMPP,
Go to /Applications/XAMPP/xamppfiles/bin folder in Terminal then run following.
./mysql_tzinfo_to_sql /usr/share/zoneinfo | sed -e "s/Local time zone must be set--see zic manual page/local/" | ./mysql -u root mysql
This worked for me.
For some reason, I can't even select invalid dates in my table. How do I force select? I just receive:
select * from table
>> Mysql2::Error: Invalid date: 1900-00-00
I'm not trying to insert, just select. Can I set allow invalid dates in select query?
mysql --version
mysql Ver 14.14 Distrib 5.1.61, for debian-linux-gnu (i686) using readline 6.1
mysql> select ##global.sql_mode;
+-------------------+
| ##global.sql_mode |
+-------------------+
| |
This is what I do to ignore invalid dates:
SET SQL_MODE='TRADITIONAL,ALLOW_INVALID_DATES';
Log into mysql in the command line mysql -u root -p
Enter your password
View the current sql-modes using SELECT ##GLOBAL.sql_mode;
Copy the current modes (add or delete modes as needed) and paste in next step.
Set the sql-modes using SET GLOBAL sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION,ALLOW_INVALID_DATES';
This adds ALLOW_INVALID_DATES and removes both NO_ZERO_DATE, NO_ZERO_IN_DATE
Restart the MySQL server /etc/init.d/mysql start
SQL Server Modes [Reset configuration file]
Solution Link
- From the command line which mysqld
- Should get something like /usr/sbin/mysqld which is the location of the binary file
- Sort out the path for the configuration files /usr/sbin/mysqld --verbose --help | grep -A 1 "Default options"
- Your bash response should look like this: Default options are read from the following files in the given order:
/etc/my.cnf /etc/mysql/my.cnf ~/.my.cnf
- Look at the files in successive order to see where to make changes (if a file does not exist it is not being referenced).
- Look up your current mode. Open a terminal and log into the mysql database mysql -u database_user -p -e "select ##sql_mode"
- Modify the SQL modes you want to change by adding the following code to the configuration file.
[mysqld]
sql-mode = "STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION,ALLOW_INVALID_DATES"
- Save the configuration file and restart the mysql service
This one solve my problem. I tested in local MySQL 5.7 ubuntu 18.04.
set global sql_mode="NO_ENGINE_SUBSTITUTION";
Before running this query globally I added a cnf file in /etc/mysql/conf.d directory. The cnf file name is mysql.cnf and codes
[mysqld]
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ALLOW_INVALID_DATES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
Then I restart mysql
sudo service mysql restart
Hope this can help someone.