MySQL ignoring the options I set in ~/.my.conf - mysql

I am trying to turn off ONLY_FULL_GROUP_BY in my local ~.my.cnf options file.
Here are my system details:
$ sudo service mysql status
* /usr/bin/mysqladmin Ver 8.42 Distrib 5.7.25, for Linux on x86_64
Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Server version 5.7.25-0ubuntu0.18.04.2
Protocol version 10
Connection Localhost via UNIX socket
UNIX socket /var/run/mysqld/mysqld.sock
Uptime: 19 min 35 sec
Threads: 1 Questions: 14 Slow queries: 0 Opens: 108 Flush tables: 1
Open tables: 27 Queries per second avg: 0.011`
~.my.cnf has the following content:
[mysqld]
key_buffer_size=32M
max_allowed_packet=512M
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,
ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
When I use "mysqld --help --verbose" this is what I see:
$ sudo mysqld --help --verbose
mysqld Ver 5.7.25-0ubuntu0.18.04.2 for Linux on x86_64 ((Ubuntu))
Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Starts the MySQL database server.
Usage: mysqld [OPTIONS]
Default options are read from the following files in the given order:
/etc/my.cnf /etc/mysql/my.cnf ~/.my.cnf
So my ~/.my.cnf is being read last meaning that it should override any settings made in previous files.
When I use "mysqld --print-defaults" to see what is being set, here's what I get:
$ sudo mysqld --print-defaults
mysqld would have been started with the following arguments:
--user=mysql --pid-file=/var/run/mysqld/mysqld.pid
-- socket=/var/run/mysqld/mysqld.sock --port=3306 --basedir=/usr
--datadir=/var/lib/mysql --tmpdir=/tmp --lc-messages-dir=/usr/share/mysql
--skip-external-locking
--bind-address=127.0.0.1 --key_buffer_size=16M --max_allowed_packet=16M
--thread_stack=192K --thread_cache_size=8
--myisam-recover-options=BACKUP --query_cache_limit=1M
--query_cache_size=16M --log_error=/var/log/mysql/error.log
--expire_logs_days=10 --max_binlog_size=100M --key_buffer_size=32M
--max_allowed_packet=512M
--sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,
ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
It would appear my settings have been actioned.
Using another method shows the same:
$ sudo mysqladmin variables | grep sql_mode
| sql_mode
ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,
ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
$ sudo mysqladmin variables | grep max_allowed_packet
| max_allowed_packet| 16777216
However, when I look at the settings of sql_mode and max_allowed_packet in mysql itself I see they still have their system default values:
$ mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.7.25-0ubuntu0.18.04.2 (Ubuntu)
Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> select ##global.sql_mode;
+--------------------------------------------------------------------------+
| ##global.sql_mode |
+--------------------------------------------------------------------------+
| ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE, |
| NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER, |
| NO_ENGINE_SUBSTITUTION |
+--------------------------------------------------------------------------+
mysql> select ##global.max_allowed_packet;
+-----------------------------+
| ##global.max_allowed_packet |
+-----------------------------+
| 16777216 |
+-----------------------------+
What am I'm doing wrong?

Your personal ~/.my.cnf can only affect programs run by you, for example mysql client or mysqldump, etc.
It does no good to write a section for [mysqld] in your personal ~/.my.cnf file, because your user is probably not the one who launches mysqld.
You could declare your preferred sql_mode for your own sessions in the MySQL client by writing the option into a [client] section:
[client]
max_allowed_packet=512M
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,
ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
But [client] only applies to MySQL tools like mysql and mysqldump. It doesn't affect any of your own apps, like if you code something in Java, Python, Ruby, or PHP, etc.
If you want an option to affect all clients, including your apps, you must apply the option in the global MySQL Server config, which is probably /etc/my.cnf as described in the other answer.
You can also change many global options dynamically without restarting mysqld. I often do this right after I edit the /etc/my.cnf file, so I can get the change without interrupting service.
mysql> SET GLOBAL sql_mode='...whatever...';
Final note: I recommend NOT disabling ONLY_FULL_GROUP_BY. That sql_mode is a useful way to prevent bogus query results. It's much better to keep that sql_mode enabled, and fix your SQL queries so they don't cause errors.

mysqld usually runs as its own user mysql, so ~/.my.cnf is meaningless unless it is in the home directory of the mysql user. For server configurations, you typically put settings in the /etc/my.cnf file or /etc/my.cnf.d depending on your mysql version.

Related

xquery error from BaseX: [sql:init] Could not find driver: com.mysql.jdbc.Driver

Which specific JDBC driver am I missing below?
nicholas $
nicholas $ basex mysql.xq
Stopped at /home/nicholas/flwor/mysql.xq, 3/9:
[sql:init] Could not find driver: com.mysql.jdbc.Driver
nicholas $
nicholas $ cat mysql.xq
xquery version "3.0";
sql:init("com.mysql.jdbc.Driver"),
let $con := sql:connect("jdbc:mysql://localhost:3306/northwind")
return sql:execute($con, "SELECT first_name FROM customers LIMIT 3;")
nicholas $
nicholas $ mysql -h localhost -P 3306 --protocol=tcp -u user -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2901
Server version: 8.0.21 MySQL Community Server - GPL
Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
mysql> SELECT first_name FROM northwind.customers LIMIT 3;
+------------+
| first_name |
+------------+
| Alexander |
| Amritansh |
| Andre |
+------------+
3 rows in set (0.00 sec)
mysql>
I've tried installing a few JDBC results from looking through apt on Ubuntu, but it looks like I probably need to connect those up with BaseX so that they're picked up.
And, incidentally, I would presumably need to send a user and password to run the above query, specific to MySQL?
You need to install the appropriate JAR, and add it to your classpath.
Using packaged drivers:
sudo apt install libmariadb-java
Edit your mysql.xq file to load org.mariadb.jdbc.Driver instead of com.mysql.jdbc.Driver, and run basex with the following command:
JAVA_CLASSPATH=/usr/share/java/mariadb-java-client.jar basex
Authentication information can be provided in various ways, e.g. using parameters in the connection string, and/or information in the MariaDB/MySQL client configuration file.

Connect to remote mysql database from within a container

From my local computer, I can easily connect to a remote instance of mysql database using the mysql cli command (assuming environment variables are set):
# mysql -u root -p$DB_PASSWORD -h $DB_HOST --port=$DB_PORT
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 7365
Server version: 5.7.14-google (Google)
Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
+--------------------+
3 rows in set (0.05 sec)
However, using docker it just hangs:
docker run --rm -it --name mysql -e MYSQL_RANDOM_ROOT_PASSWORD=yes mysql \
mysql -u root -p$DB_PASSWORD -h $DB_HOST --port=$DB_PORT
mysql: [Warning] Using a password on the command line interface can be insecure.
show databases;
^C
^C
exit
exit
^C
and have to docker container stop mysql from another terminal window for it to exit the mysql container.
I tried even attaching to the container and run the same command to no avail. Tried connecting to an AWS MySQL instance and Google Cloud SQL instance, also tried to enter variables directly in the command line all with the same result. Why is it hanging and how can I make it work? Thanks!
Try expose the default port for MySQL
docker run -p 3306:3306 ...
I was using Google Cloud SQL and the IP address needed to be whitelisted for it to allow access. So adding that solved the connection issue.
I tried all the ways but below step has resolved my issue.
run command inside container
dpkg-reconfigure tzdata
it will ask you to select for Geographical area and Time zone, then you are done.

MySQL first time create database error

So I have just installed linux and started messing around with apache,php,mysql and I have this error when creating database. I was unable to find an answer so i hope you guys can help me.
max#MaxLNX:~$ mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 67
Server version: 5.5.47-0ubuntu0.14.04.1 (Ubuntu)
Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> create database firstdb;
ERROR 1006 (HY000): Can't create database 'firstdb' (errno: 13)
Error means that your mysql server doesn't have enough space.
Check the file system size, and remove unwanted software(s),or files.
There may be a permissions issue with the MySQL data directory. You could try setting the permissions as follows (adjust the path to your data directory)
chown -R mysql:mysql /usr/local/mysql/data
reply if it worked
Try using "sudo". On a Linux system, "sudo" means "superuser" and should help you gain access to make a database. Try this in your terminal:
sudo mysql -u root -p

mysqldump always returns "option '--tables' cannot take an argument"

I am trying to backup a mysql database using mysqldump command, but the message I get is mysqldump: option '--tables' cannot take an argument.
Here you are:
root#myhost:~# mysqldump mydatabase --user myuser --password mypassword
Warning: Using unique option prefix table instead of tables is deprecated and will be removed in a future release. Please use the full name instead.
mysqldump: option '--tables' cannot take an argument
I have tryed several argument combinations, but I finally discovered that the result is the same if I just try to get the command version or event with no arguments at all:
root#myhost:~# mysqldump --version
Warning: Using unique option prefix table instead of tables is deprecated and will be removed in a future release. Please use the full name instead.
mysqldump: option '--tables' cannot take an argument
root#myhost:~# mysqldump
Warning: Using unique option prefix table instead of tables is deprecated and will be removed in a future release. Please use the full name instead.
mysqldump: option '--tables' cannot take an argument
As you can see in the following lines, it is mysql server 5.5 running on debian 7.
System version:
root#myhost:~# uname -a
Linux myhost 3.2.0-4-amd64 #1 SMP Debian 3.2.41-2+deb7u2 x86_64 GNU/Linux
mysql client version:
root#myhost:~# mysql --version
mysql Ver 14.14 Distrib 5.5.35, for debian-linux-gnu (x86_64) using readline 6.2
mysql server version:
root#myhost:~# mysql -h localhost --user=myuser --password=mypassword mydatabase
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 75
Server version: 5.5.35-0+wheezy1-log (Debian)
Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> quit
Bye
I have looked for this problem on the web, but I cannot see anyone reporting this precise issue. I am not an expert on mysql but I can say it is a very simple install. Should you need more information, please tell me.
Thanks in advance,
ivan
Following #DCoder indications I inspected /etc/mysql/my.cnf which, among others, contained
[client]
port = 3306
socket = /var/run/mysqld/mysqld.sock
table = true
After removing table = true line from /etc/mysql/my.cnf, mysqldump command works as expected:
root#myhost:~# mysqldump
Usage: mysqldump [OPTIONS] database [tables]
OR mysqldump [OPTIONS] --databases [OPTIONS] DB1 [DB2 DB3...]
OR mysqldump [OPTIONS] --all-databases [OPTIONS]
For more options, use mysqldump --help
My conclusion is that table=true option is not suitable for mysqldump command and must be removed from [client] in the options file. [client] section groups option settings applied to all client programs.
Should another command need that option set, it should be placed in another program section, neither in [mysqldump] nor in [client].
Try this
mysqldump --tab = dir_name options db_name tbl_name
--tab writes each dumped file as a tab-delimited text file in the "dir_name" directory.
db_name is the db containing the table to the exported.
tbl_name is the table to be exported.
"options" part may include options such as --host or --user.
e.g.
mysqldump --tab = /tmp office contact

mysql connection profiles configuration file

Is there a way to save the connection params(like host, port, username, password, db) to the mysql servers I frequently access as shortcuts?
I am looking for something similar to ssh config for mysql from terminal in ubuntu. preferably with ssh tunneling support as well.
You could use the --defaults-file option combined with an shell alias,
for example:
% cat db01
[mysql]
user=root
password=<your_pwd>
host=<your_host>
% alias my_db01='mysql --defaults-file=db01'
% my_db01
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 41
Server version: 5.1.54-1ubuntu4 (Ubuntu)
Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL v2 license
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
So you can create different files with different settings.