I am running phpmyadmin and installed apache server on my personal computer. My problem is that I am trying to set MySQL event_scheduler to always be enabled even when the server restarts. I was reading that by setting the following command line in the server configuration file (my.cnf or my.ini) it should work: event_scheduler=DISABLED. However, where do I locate this my.cnf or my.ini file, and also should the command line be event_scheduler=DISABLED or event_scheduler=ENABLED seeing that I want it to always be enabled?
You should set 'ON' value (not ENABLED).
In the configuration file in [mysqld] section specify 'event-scheduler' option (not event_scheduler).
Also, you can start your MySQL server with '--event-scheduler' option, e.g. -
shell> mysqld --event-scheduler=ON
More information - event_scheduler system variable.
Add to my.cnf file to [mysqld] section.
GLOBAL event_scheduler=ON
Restart your mysql server. Check status with this command :
mysql> select ##GLOBAL.event_scheduler;
+--------------------------+
| ##GLOBAL.event_scheduler |
+--------------------------+
| ON |
+--------------------------+
1 row in set (0.00 sec)
mysql> SHOW VARIABLES LIKE 'event_scheduler';
+-----------------+-------+
| Variable_name | Value |
+-----------------+-------+
| event_scheduler | ON |
+-----------------+-------+
1 row in set (0.01 sec)
Here the path for my.ini on XAMPP:
xampp\mysql\bin\my.ini
Open my.ini and add the following
[mysqld]
event_scheduler=ON
then restart MySQL service.
To check the status use the below MySQL query:
SELECT ##event_scheduler
For WAMP:
Edit your my.ini file and under the [mysqld] section, add this:
event-scheduler=on
restart all services
verify by running this query:
select ##event_scheduler;
To get to your my.ini file, just click the WAMP tray icon and hover over the 'MySQL' menu, and click 'my.ini'.
FOR MAMP on OS X:
the default installation does not include a my.cnf file so you need to create one and set up your default configuration. Therefore, to enable the the scheduler on an OS X MAMP stack, you need to,
stop your MySQL server
create a my.cnf file in your /Applications/MAMP/conf/ folder, you will need root access to do this (open a terminal window),
sudo touch /Applications/MAMP/conf/my.cnf
sudo nano /Applications/MAMP/conf/my.cnf
the 2nd cmd will open the nano editor, paste the following in your file,
[mysqld]
event_scheduler=ON
Save (^O) and exit (^X) the nano editor
restart your MySQL server.
Related
I am trying to use OUTFILE on Ubuntu 20.04 and getting this error:
MySQL server version: 8.0.21
Code:
mysql> select * into OUTFILE '/home/yash/Desktop/data2.txt' from ticket;
ERROR 1290 (HY000): The MySQL server is running with the --secure-file-priv option so it cannot execute this statement
I tried many solutions but it didn't work on Ubuntu 20.04
If anyone can give a solution for Ubuntu 20.04 and MySQL 8.0.21 then it will be appreciated.
You can use
SHOW VARIABLES LIKE "secure_file_priv";
to see the directory that MySQL thinks that it is secure to load or save files.
You have now two options:
Move your file to the directory specified by secure-file-priv.
Disable secure-file-priv. This must be removed from startup and cannot be modified dynamically. So you have to change it in my.conf
In my.con you should find secure-file-priv= and change it to
[mysql]
secure-file-priv='/home/yash/Desktop/'
So that your desktop will become a save directory.
And you can disable the secure file option, which is not recommended by
[mysql]
secure-file-priv=''
As per your question you want to store the result of the query in a text file try 'tee' MySQL command
Try this in your MySQL prompt
tee /home/yash/Desktop/data2.txt;
select * from ticket;
Are you using any shell script or connecting MySQL DB from the terminal?
If not working then disable "secure_file_priv" in mysqld.cnf then restart.
set secure-file-priv = "" in mysqld.cnf file and the check SHOW VARIABLES LIKE "secure_file_priv"; and you get the below sample output
+------------------+-------+
| Variable_name | Value |
+------------------+-------+
| secure_file_priv | |
I'm install MySql on my OsX 10.11 El Capitan. If I try to start my query I have a strange error if my query have Group By.
So if I try to execute this query from Terminal:
SET GLOBAL sql_mode=(SELECT REPLACE(##sql_mode,'ONLY_FULL_GROUP_BY',''));
I can execute my query never problem. Now if I try to re-start my macbook, I have the some problem and I can re-execute the query.
There is any way to fix this sql_mode permanently ?
I have tro to open "etc/mysql/my.cnf" file but there isn't this file on my mac. How can I apply this change ?
You could set my.cnf and add your sql_mode config
[mysqld]
sql_mode=ONLY_FULL_GROUP_BY
By default, the OS X installation does not use a my.cnf, and MySQL just uses the default values.
To set up your own my.cnf, you could just create a file straight in /etc.
If you're using MAMP PRO it's worth noting this from the guide:
You cannot edit your my.cnf file directly. You must use the MAMP PRO interface to edit your my.cnf file. In the menu go to File > Edit Template > MySQL > my.cnf.
Then you can add the sql_mode you want under the [mysqld] heading. e.g:
[mysqld]
sql_mode=ONLY_FULL_GROUP_BY
This is what worked for me.
If you want to turn ONLY_FULL_GROUP_BY off, you need to check first the value of the sql_mode variable :
(default values)
mysql> show variables like 'sql_mode'\G
*************************** 1. row ***************************
Variable_name: sql_mode
Value: 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
1 row in set (0,01 sec)
Edit MySQL config file my.conf . Usually in /etc/my.cnf like scaisEdge said.
but, you must write :
[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
(all values without ONLY_FULL_GROUP_BY - you can copy/paste this line)
Restart your MySQL, and enjoy.
the right way to do that by following these steps
Quit MAMP.
Run following command in the Terminal:
touch /Applications/MAMP/conf/my.cnf && open -t /Applications/MAMP/conf/my.cnf
When this file is empty, then add the following below. If the file is not empty, then simply add the line sql_mode="" right after the line [mysqld]
[mysqld]
sql_mode=""
Save the config file and close the text editor; restart MAMP and start the servers.
reference: https://mampsupportforum.com/forums/latest/mamp-mamp-pro-disable-mysql-strict-mode
I want to know how to check whether MySQL strict mode is on or off in localhost(xampp).
If on then for what modes and how to off.
If off then how to on.
I already followed http://dev.mysql.com/doc/refman/5.7/en/sql-mode.html#sql-mode-full and https://mariadb.com/kb/en/mariadb/sql_mode/ and other related sites too. But I didn't get an exact answer for my question.
->STRICT_TRANS_TABLES is responsible for setting MySQL strict mode.
->To check whether strict mode is enabled or not run the below sql:
SHOW VARIABLES LIKE 'sql_mode';
If one of the value is STRICT_TRANS_TABLES, then strict mode is enabled, else not.
In my case it gave
+--------------+------------------------------------------+
|Variable_name |Value |
+--------------+------------------------------------------+
|sql_mode |STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION|
+--------------+------------------------------------------+
Hence strict mode is enabled in my case as one of the value is STRICT_TRANS_TABLES.
->To disable strict mode run the below sql:
set global sql_mode='';
[or any mode except STRICT_TRANS_TABLES. Ex: set global sql_mode='NO_ENGINE_SUBSTITUTION';]
->To again enable strict mode run the below sql:
set global sql_mode='STRICT_TRANS_TABLES';
To Change it permanently in ubuntu do the following
in the ubuntu command line
sudo nano /etc/mysql/my.cnf
Then add the following
[mysqld]
sql_mode=
First, check whether the strict mode is enabled or not in mysql using:
SHOW VARIABLES LIKE 'sql_mode';
If you want to disable it:
SET sql_mode = '';
or any other mode can be set except the following.
To enable strict mode:
SET sql_mode = 'STRICT_TRANS_TABLES';
You can check the result from the first mysql query.
Check the value with
SELECT ##GLOBAL.sql_mode;
then clear the ##global.sql_mode by using this command:
SET ##GLOBAL.sql_mode=''
To change it permanently in Windows (10), edit the my.ini file. To find the my.ini file, look at the path in the Windows server. E.g. for my MySQL 5.7 instance, the service is MYSQL57, and in this service's properties the Path to executable is:
"C:\Program Files\MySQL\MySQL Server 5.7\bin\mysqld.exe" --defaults-file="C:\ProgramData\MySQL\MySQL Server 5.7\my.ini" MySQL57
I.e. edit the my.ini file in C:\ProgramData\MySQL\MySQL Server 5.7\. Note that C:\ProgramData\ is a hidden folder in Windows (10). My file has the following lines of interest:
# Set the SQL mode to strict
sql-mode="STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
Remove STRICT_TRANS_TABLES, from this sql-mode line, save the file and restart the MYSQL57 service. Verify the result by executing SHOW VARIABLES LIKE 'sql_mode'; in a (new) MySQL Command Line Client window.
(I found the other answers and documents on the web useful, but none of them seem to tell you where to find the my.ini file in Windows.)
In my case, I need to add:
sql_mode="STRICT_TRANS_TABLES"
under [mysqld] in the file my.ini located in C:\xampp\mysql\bin.
You can check the local and global value of it with:
SELECT ##SQL_MODE, ##GLOBAL.SQL_MODE;
I want to know how to check whether MySQL strict mode is on or off in
localhost(xampp).
SHOW VARIABLES LIKE 'sql_mode';
If result has "STRICT_TRANS_TABLES", then it's ON. Otherwise, it's OFF.
If on then for what modes and how to off.
If off then how to on.
For Windows,
Go to C:\Program Files\MariaDB XX.X\data
Open the my.ini file.
*On the line with "sql_mode", modify the value to turn strict mode ON/OFF.
Save the file
**Restart the MySQL service
Run SHOW VARIABLES LIKE 'sql_mode' again to see if it worked;
*3.a. To turn it ON, add STRICT_TRANS_TABLES on that line like this: sql_mode=STRICT_TRANS_TABLES. *If there are other values already, add a comma after this then join with the rest of the value.
*3.b. To turn it OFF, simply remove STRICT_TRANS_TABLES from value. *Remove the additional comma too if there is one.
**6. To restart the MySQL service on your computer,
Open the Run command window (press WINDOWS + R button).
Type services.msc
Click OK
Right click on the Name MySQL
Click Restart
on Debian 10
I start mysql from ./opt/lampp/xampp start
I do strace ./opt/lampp/sbin/mysqld and see that my.cnf is there:
stat("/opt/lampp/etc/my.cnf", {st_mode=S_IFREG|0644, st_size=5050, ...}) = 0
openat(AT_FDCWD, "/opt/lampp/etc/my.cnf", O_RDONLY|O_CLOEXEC) = 3
hence, I add sql_mode config to /opt/lampp/etc/my.cnf instead of /etc/mysql/my.cnf
on server console:
$ mysql -u root -p -e "SET GLOBAL sql_mode = 'NO_ENGINE_SUBSTITUTION';"
Today I was trying to set the sql_mode=TRADITIONAL permanently but all efforts were in vain not because there are wrong answers but due to the way xampp configured the mysqld startup script. Let me explain in detail.
Of course you all try our best before coming to SO, so do I. I followed the comments in A:\xampp\mysql\bin\my.ini (given below):
# You can copy this file to
# A:/xampp/mysql/bin/my.cnf to set global options,
# mysql-data-dir/my.cnf to set server-specific options (in this
# installation this directory is A:/xampp/mysql/data) or
# ~/.my.cnf to set user-specific options.
So I tried A:/xampp/mysql/bin/my.cnf, A:/xampp/mysql/data/my.cnf but it wasn't even reading those files. Hours wasted in creating .cnf files in above locations. Worst part was it wasn't even working if I edit those my.ini files (i.e A:/xampp/mysql/bin/my.ini and A:/xampp/mysql/data/my.ini)
Then I checked all the folders to know how that control panel works and found thta xampp uses the mysql_start.bat script to start the msql deamon. Here is the bat file contents:
#echo off
cd /D %~dp0
echo Diese Eingabeforderung nicht waehrend des Running beenden
echo Please dont close Window while MySQL is running
echo MySQL is trying to start
echo Please wait ...
echo MySQL is starting with mysql\bin\my.ini (console)
mysql\bin\mysqld --defaults-file=mysql\bin\my.ini --standalone
if errorlevel 1 goto error
goto finish
:error
echo.
echo MySQL konnte nicht gestartet werden
echo MySQL could not be started
pause
:finish
Here we can clearly see that it is explicitly using the argument --defaults-file to tell MySQL daemon from where to read the files. Now I hope you have plenty of ideas to fix this.
Note: I've already added A:/xampp/mysql/bin to my PATH.
Now we have several options as I've mentioned below:
Add the exact path to the --defaults-file (i.e. --defaults-file=mysql\bin\my.cnf)
You can just ommit the flag and let mysqld read from default locations (can see those using mysql --help) Now you've 2 options:
either edit those default my.ini files or
follow the comments to create my.cnf files according to your installation
directory.
I just deleted that --defaults-file flag and let it run with MySQL's default configuration instead of xampp's. By the was I also have to change A:\xampp\mysql\data\my.ini from this:
[mysqld]
datadir=C:/xampp/mysql/data
[client]
to
[mysqld]
datadir=A:\xampp\mysql\data
[client]
to update the data directory. After that I just created a my.conf file in A:\xampp\mysql\data (data dir). with sql_mode option in it. It also worked with my.cnf in the A:\xampp\mysql\bin.
I have attached some screenshots for better understanding:
Updated data dir in A:\xampp\mysql\data\my.ini:
(option 1) Add my.cnf in A:\xampp\mysql\data:
(option 2) Add my.cnf in A:\xampp\mysql\bin:
You may found another solution too. Hope you are able to fix whatever issue you have regarding those config files.
For ubuntu :
Once you are connected to your VPS via SSH, please try connecting to your mysql with "root"
user: mysql -u root -p
Enter "root" user password and you will be in the mysql environment (mysql>), then simply check what is sql_mode, with the following command:
SHOW VARIABLES LIKE 'sql_mode';
Basically, you will see the table as your result, if the table has a value of STRICT_TRANS_TABLES, it means that this option is enabled, so you need to remove the value from this table with the following command:
set global sql_mode='';
This will set your table's value to empty and disable this setting. Like this:
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| sql_mode | |
+---------------+-------+
Please make sure to perform these commands within the MySQL environment and not simply via SSH. I think this moment was missed in the article provided below and the author assumes that the reader understands it intuitively.
I am trying to write the results of MySQL script to a text file using the following code in my script.
SELECT p.title, p.content, c.name FROM post p
LEFT JOIN category c ON p.category_id=c.id
INTO OUTFILE 'D:\MySql\mysqlTest.txt';
However, I am getting the following
ERROR 1290 (HY000): The MySQL server is running with the --secure-file-priv option so it cannot execute this statement
How do I solve this?
Ubuntu 16.04 (EASY): Find out where you are allowed to write
mysql> SELECT ##GLOBAL.secure_file_priv;
+---------------------------+
| ##GLOBAL.secure_file_priv |
+---------------------------+
| /var/lib/mysql-files/ |
+---------------------------+
1 row in set (0.00 sec)
Then, just write there
mysql> SELECT * FROM train INTO OUTFILE '/var/lib/mysql-files/test.csv' FIELDS TERMINATED BY ',';
Query OK, 992931 rows affected (1.65 sec)
mysql>
Mac OSX: Mysql installed via MAMP
Find out where you are allowed to write
mysql> SELECT ##GLOBAL.secure_file_priv;
+---------------------------+
| ##GLOBAL.secure_file_priv |
+---------------------------+
| NULL |
+---------------------------+
1 row in set (0.00 sec)
NULL means you're screwed so you have to create the file "~/.my.cnf"
Enable read/write for MySQL installed via MAMP (on Mac):
open "MAMP" use spotlight
click "Stop Servers"
edit ~/.my.cnf (using vi or your favorite editor) and add the following lines:
$ vi ~/.my.cnf
[mysqld_safe]
[mysqld]
secure_file_priv="/Users/russian_spy/"
click "Start Servers" (in MAMP window)
Now check if it works:
a. start mysql (default MAMP user is root, password is also root)
$ /Applications/MAMP/Library/bin/mysql -u root -p
b. in mysql look at the white-listed paths
mysql> SELECT ##GLOBAL.secure_file_priv;
+---------------------------+
| ##GLOBAL.secure_file_priv |
+---------------------------+
| /Users/russian_spy/ |
+---------------------------+
1 row in set (0.00 sec)
c. Finally, test by exporting a table train into a CSV file
mysql> SELECT * FROM train INTO OUTFILE '/Users/russian_spy/test.csv' FIELDS TERMINATED BY ',';
Query OK, 992931 rows affected (1.65 sec)
mysql>
Edit the (/etc/my.cnf file for CentOS) or (my.ini file for Windows)
Add
secure-file-priv = ""
line at the end
Stop mysql service using systemctl stop mysqld
Restart it using systemctl start mysqld
It will now allow you to import and export the data.
Replace "\" to "/" in your file path.
Like this:
INTO OUTFILE 'D:/MySql/mysqlTest.txt';
You cannot export data as it is configured in mysql config files. Open my.cnf config file and check.
Quote from MySQL doc
This variable is used to limit the effect of data import and export operations, such as those performed by the LOAD DATA and SELECT ... INTO OUTFILE statements and the LOAD_FILE() function. These operations are permitted only to users who have the FILE privilege.
secure_file_priv may be set as follows:
If empty, the variable has no effect.
If set to the name of a directory, the server limits import and export
operations to work only with files in that directory. The directory
must exist; the server will not create it.
If set to NULL, the server disables import and export operations. This
value is permitted as of MySQL 5.7.6.
(An empty value is the default, or it can be explicitly specified in my.cnf as secure_file_priv="". A NULL value can be set with secure_file_priv=NULL.)
So, if you want to export data, then you need to comment this option and restart mysql server. Then you will be able to export.
Just create a file /etc/my.cnf with the following content
[mysqld]
secure_file_priv = ''
You can use this oneliner:
echo "[mysqld]\nsecure_file_priv\t\t= ''\n" | sudo tee /etc/my.cnf
And then restart mysql. If brew was used to install the mysql run the following command:
brew services restart mysql
FOR MAC OS, if installed via HOMEBREW:
Edit my.cnf
PATH: /usr/local/etc/my.cnf
COPY this:
# Default Homebrew MySQL server config
[mysqld]
# Only allow connections from localhost
bind-address = 0.0.0.0
secure-file-priv = ''
SAVE
Explanation:
Secure_file_prive = NULL -- Limit mysqld not allowed to import and export
Secure_file_priv = '/tmp/' -- Limit mysqld import and export can only occur in /tmp/ directory
Secure_file_priv = '' -- does not restrict the import of mysqld
This is the example of my SQL that worked perfectly in WAMP SERVER (windows):
SELECT display_name,user_email,user_registered FROM test_wp_users
ORDER BY user_registered ASC
INTO OUTFILE 'C:/wamp64/tmp/usersbyemail.csv'
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '\n';
PS: Note that bars in path should be left-to-right to work perfectly in MYSQL.
In my my.ini I only had
# Secure File Priv.
and I tried to put:
# Secure File Priv.
secure-file-priv = ""
and
# Secure File Priv.
secure-file-priv = NULL
without making it work.
I finally deleted the line and left alone:
secure-file-priv = ""
Working correctly.
That's because secure_file_priv is set to NULL
mysql> show variables like secure_file_priv;
| secure_file_priv | NULL |
You must stop mysql server
shell>/usr/local/mysql/support-files/mysql.server stop
Then restart mysql with the option defining where you want your files to be written to, for example to /tmp
shell>/usr/local/mysql/support-files/mysql.server start --secure-file-priv=/tmp
Then in mysql terminal you should see where your files can now be written to
mysql> show variables like secure_file_priv;
| secure_file_priv | /private/tmp/ |
On Mac you can find this folder by using Go To Folder /private/tmp in Finder
Go to C:\ProgramData\MySQL\MySQL Server 8.0 and you will find my.ini file. Open my.ini file in text editor (recommended notepad++) and then search for secure_file_priv and then replace will secure_file_priv="" and then save the file.
and restart your laptop.
I just installed MySQL 5.7 on Windows 10. I am intending to run bugzilla on this computer, so I'd like the settings from this bugzilla mysql settings page, which are
max_allowed_packet=16M
ft_min_word_len=2
When I run mysql --help from cmd, I get a line that says
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.7\my.ini C:\Program Files\MySQL\MySQL Server 5.7\my.cnf
None of those files exist until C:\Program Files\MySQL\MySQL Server 5.7\my.ini, which is where I added the settings from above. HOWEVER, if I open mysql -u username -p from the same window, I get
mysql> SHOW VARIABLES LIKE 'max_allowed_packet';
+--------------------+---------+
| Variable_name | Value |
+--------------------+---------+
| max_allowed_packet | 4194304 |
+--------------------+---------+
1 row in set (0.00 sec)
mysql> SHOW VARIABLES LIKE 'ft_min_word_len';
+-----------------+-------+
| Variable_name | Value |
+-----------------+-------+
| ft_min_word_len | 4 |
+-----------------+-------+
1 row in set (0.00 sec)
And if I do mysql --help again, I get a line that says
max-allowed-packet 16777216
So I'm really confused. Am I logging into different mysql installs or something? Current full mysql --help here.
Find the spot where your my.ini is first picked up. A typical spot will be in the basedir visible with
select ##basedir;
Do the same for ##datadir and write those values down in case you make changes and want to undo what you have done. Such as messing it up and your data is not pointed to upon startup. You log file will tell you if it is broken.
Note too my comments above about specifying the port number with command line tools with a -P (uppercase).
For the my.ini you will need to Open as Administrator to make changes there anyway. Then perform a server restart. (mysqladmin).
Depending on your actual mysql version, attempt to modify, say, the verbosity level. And continue until you isolate where the file you want is picked up for your variables you wish to load on startup. Note in my below it suggests I have two servers running. Which I do on ports 3306 and 3307 for 5.6 and 5.7.13, respectively.
[mysqld]
basedir=C:\\Program Files\\MySQL\\MySQL Server 5.7\\
datadir=C:\\ProgramData\\MySQL\\MySQL Server 5.7\\Data\\
port=3307
log_error_verbosity=2
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER
When you first setup the server on Windows, it is highly likely that you don't even have a my.ini that is active. There is a default stub not Live. And the values are merely baked in. It took me a while to realize there was truly no file loading anything until I found the spot.