How change values from Server System Variables - mysql

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

Related

LOAD_FILE returns only null

I want to insert the image to the database with this query:
SELECT LOAD_FILE('/Users/juliagaskevich/cool-background.svg');
I checked that:
File size < max_allowed_packet.
File has read, write and execute permissions to everyone.
The user, what I'm using to execute the query has FILE privilege.
mysql> show variables like "secure_file_priv" returns NULL.
System configuration:
macOS Monterey, version 12.5, chip Apple M1
MySQL Ver 8.0.29 for macos12 on arm64 (MySQL Community Server - GPL)
MySQL Config:
[mysqld]
user = mysql_deamon
slow_query_log_file = my-slow-query.log
slow-query-log
log-queries-not-using-indexes
general_log_file = my-GENERAL.log
max_allowed_packet = 1073741824
Also, I tried to fix my problem with guys' ideas, but...
1.vi my.cnf
secure-file-priv=/mysql/dataload(Change /mysql/dataload to your own
directory.)
2.restart mysql service
Changed my.cnf
Changed my.cnf (without quotes in secure-file-priv path)
The statement SELECT LOAD_FILE(...) delivers one string. To INSERT,
use the statement LOAD DATA INFILE ...
1290 ERROR with null secure_file_priv result
1.vi my.cnf
secure-file-priv=/mysql/dataload(Change /mysql/dataload to your own directory.)
2.restart mysql service
The statement SELECT LOAD_FILE(...) delivers one string. To INSERT, use the statement LOAD DATA INFILE ...
SOLVING
If you are using mac, you have the /etc/my.cnf (file, where is MySQL config stored), so put there this string secure_file_priv = ""
Run this to apply config changes mysqld --defaults-file=/etc/my.cnf --validate-config --log_error_verbosity=2 AND IF you have any warnings or errors fix it, because it can solve your problem
If you are using some different user than root, the user have to have a FILE privileges mysql> GRANT privilege ON privilege_level TO account_name;, for example mysql> GRANT FILE ON *.* TO pizzaadmin;
The most important thing: To apply changes, you have to restart mysqld.
There are few steps:
stop it (You can do this with this command mysqladmin shutdown)
start again (You can do this with just executing mysqld in terminal)

The MySQL syntax that is not run always fails on Ubuntu

I am a linux beginner, especially ubuntu. I want to manage the mysql database installed on my Ubuntu web server by using Putty. But the MySQL syntax that I run always fails. Example syntax:
mysql -u root -p
All failed messages are the same for any syntax:
mysql: unknown variable 'bind-address = 0.0.0.0'
I don't know whether to run the Mysql syntax on Ubuntu I need to go to a certain Folder/Path, like in windows if I want to run the mysql syntax I need to go to the path where MySql is installed, for example C:/xampp/mysql/bin and then run the syntax mysql -u root -p.
is there anything I miss? and what should i do? please help, thank you.
Option 1: A typo in a title
Have a look in your my.cnf file.
Maybe you have a typo: There should be [mysqld] instead of [mysql] section
[mysqld] bind-address=0.0.0.0
OR
[mysqld]
bind-address=0.0.0.0
Source
Option 2: Is it Maria DB?
Are you sure you are using MySQL ?
This looks like a MariaDB error.
Try to remove the bind-address from your mysql.cnf file.
Option 3: Check for any whites-pace?
Try editing the file and using show all characters in your editor (e.g. Notepad Plus Plus). Maybe there are whitespace characters ( such as spaces ) causing problems.

Mysql : can't set lower_case_table_names variable

I'm installing new software on a new Ubuntu 16.0.4 machine and installed MySQL with apt-get. The version I get is 5.7.22 but can't get it to accept
my settings of the configuration variable lower_case_table_names.
I'm adding lines like:
[mysql]
lower_case_table_names = 1
When I edit any of the *.cnf files in /etc/mysql to have this setting or if I add it to ~/.my.cnf I get
mysql: [ERROR] unknown variable 'lower_case_table_names=1'
if I try to start mysql. Similarly I can't use it on the mysql command line like the doc says I can.
/usr/bin/mysql --lower_case_table_names=1 -u root -p
However:
If I go into the SQL command interpreter and type
mysql> select ##lower_case_table_names;
I get back a result showing the variable is set to 0. However it cannot be changed with a SET statement...
So whats the deal with why I can't set this variable ?
~/.my.cnf file:
[mysqld]
lower_case_table_names = 1
[mysql]
lower_case_table_names = 1
Why is mysql not liking this variable name when clearly it still has a setting for it?
The problem is that this variable does not apply to mysql. It only applies
to mysqld. Stop mysqld, change the my.cnf to have a setting for [mysqld], and then start mysqld. This will set the lower_case_table_names value for the mysql server.
If you run /usr/bin/mysql (a command line mysql shell) it will not want a setting for this var in the config file. The shell will behave as the mysql server behaves.

mysql allow invalid dates on select

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.

Setting global sql_mode in MySQL

I am trying to set sql_mode in MySQL but it throws an error.
Command:
set global sql_mode='NO_BACKSLASH_ESCAPES','STRICT_TRANS_TABLE','NO_AUTO_CREATE_USER','NO_ENGINE_SUBSTITUTION'
Is this not the proper way to set multiple modes?
What are the advantages of setting session and global modes?
Which is preferred?
I have different users trying to update the database with different UNC values and instead of setting the session mode to NO_BACKSLASH_ESCAPES, I though it would make sense to set a global mode for this. Does this make sense?
Please let me know.
Thanks.
BTW, if you set globals in MySQL:
SET GLOBAL sql_mode = 'NO_ENGINE_SUBSTITUTION';
SET SESSION sql_mode = 'NO_ENGINE_SUBSTITUTION';
This will not set it PERMANENTLY, and it will revert after every restart.
So you should set this in your config file (e.g. /etc/mysql/my.cnf in the [mysqld] section), so that the changes remain in effect after MySQL restart:
Config File: /etc/mysql/my.cnf
[mysqld]
sql_mode = NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
UPDATE: Newer versions of Mysql (e.g. 5.7.8 or above) may require slightly different syntax:
[mysqld]
sql-mode="STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION"
Make sure that there is a dash between sql-mode not an underscore, and that modes are in double quotes.
Always reference the MySQL Docs for your version to see the sql-mode options.
I resolved it.
the correct mode is :
set global sql_mode="NO_BACKSLASH_ESCAPES,STRICT_TRANS_TABLE,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
Setting sql mode permanently using mysql config file.
In my case i have to change file /etc/mysql/mysql.conf.d/mysqld.cnf as mysql.conf.d is included in /etc/mysql/my.cnf. i change this under [mysqld]
[mysqld]
sql_mode = "STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
just removed ONLY_FULL_GROUP_BY sql mode cause it was causing issue.
I am using ubuntu 16.04, php 7 and mysql --version give me this mysql Ver 14.14 Distrib 5.7.13, for Linux (x86_64) using EditLine wrapper
After this change run below commands
sudo service mysql stop
sudo service mysql start
Now check sql modes by this query SELECT ##sql_mode and you should get modes that you have just set.
For someone who googling this error for MySQL 8.
MySQL 8.0.11 remove the 'NO_AUTO_CREATE_USER' from sql-mode.
MySQL 5.7: Using GRANT to create users. Instead, use CREATE USER.
Following this practice makes the NO_AUTO_CREATE_USER SQL mode
immaterial for GRANT statements, so it too is deprecated. MySQL
8.0.11: Using GRANT to create users. Instead, use CREATE USER. Following this practice makes the NO_AUTO_CREATE_USER SQL mode
immaterial for GRANT statements, so it too is removed.
Taken from here
So, your sql_mode can be like this:
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION
Or if you're using Docker you can add next command to docker-compose.yml
mysql:
image: mysql:8.0.13
command: --sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION
ports:
- 13306:${MYSQL_PORT}
Copy to Config File: /etc/mysql/my.cnf OR /bin/mysql/my.ini
[mysqld]
port = 3306
sql-mode=""
MySQL restart.
Or you can also do
[mysqld]
port = 3306
SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
MySQL restart.
Access the database as the administrator user (root maybe).
Check current SQL_mode
mysql> SELECT ##sql_mode;
To set a new sql_mode, exit the database, create a file
nano /etc/mysql/conf.d/<filename>.cnf
with your sql_mode content
[mysqld]
sql_mode=NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
Restart Mysql
mysql> sudo service mysql stop
mysql> sudo service mysql start
We create a file in the folder /etc/mysql/conf.d/
because in the main config file /etc/mysql/my.cnf
the command is written to include all the settings files from the folder /etc/mysql/conf.d/
For Temporary change use following command
set global sql_mode="NO_BACKSLASH_ESCAPES,STRICT_TRANS_TABLE,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
For permanent change : go to config file /etc/my.cnf or /etc/mysql/mysql.conf.d/mysqld.cnf and add following lines then restart mysql service
[mysqld]
sql_mode = "STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
Check the documentation of sql_mode
Method 1:
Check default value of sql_mode:
SELECT ##sql_mode //check current value for sql_mode
SET GLOBAL sql_mode = "NO_BACKSLASH_ESCAPES,STRICT_TRANS_TABLE,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION";
Method 2:
Access phpmyadmin for editing your sql_mode
Login on phpmyadmin and open localhost
Top on Variables present on the top in menu items and search out for sql mode
Click on edit button to modify sql_mode based on your requirements
Save the changes
Restart server after executing above things
In my case mysql and ubuntu 18.04
I set it permanently using this command
sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf
Append the line after the configuration. See example highlighted in the image below.
sql_mode = ""
Note :You can also add different modes here, it depends on your need
NO_BACKSLASH_ESCAPES,STRICT_TRANS_TABLE,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
See Available sql modes reference and Documentation
Then save.
After saving you need to restart your mysql service, follow the command below:
sudo service mysql restart
Hope this helps :-)
In my case i have to change file /etc/mysql/mysql.conf.d/mysqld.cnf change this under [mysqld]
Paste this line on [mysqld] portion
sql_mode = "STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
I just had a similar problem where MySQL (5.6.45) wouldn't accept sql_mode from any config file.
The solution was to add init_file = /etc/mysql/mysql-init.sql to the config file and then execute SET GLOBAL sql_mode = ''; in there.
If someone want to set it only for the current session then use the following command
set session sql_mode="NO_BACKSLASH_ESCAPES,STRICT_TRANS_TABLE,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
Updating this for users Using MAMP PRO {works with MAMP users too}. Because I seem to have got stuck on finding a solution for this, but people recommended I should edit the my.cnf file in the /Applications/MAMP/tmp/mysql/my.cnf folder which does not work because it gets reset after every restart of mysql server.
Referring this document:
The configuration file “my.cnf” of MySQL can be found here:
“/Applications/MAMP/tmp/mysql/my.cnf”. Please note: Editing this file
does NOT work as it will be overwritten every time MySQL is restarted
by MAMP PRO with a “my.cnf” file that is created from the MySQL
template. You must edit this template (menu File > Open Template >
MySQL (my.cnf) > 5.7.30) to modify the MySQL configuration. Manually
adding “my.cnf” files to other locations is not recommended. Every
configuration aspect can be handled with the MySQL template.
Once this is done, add the following in the my.cnf file:
[mysqld]
sql_mode = STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
Restart the Mysql Server. That should do the trick.
set global sql_mode="NO_BACKSLASH_ESCAPES,STRICT_TRANS_TABLE,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"