how to edit secure_file_priv using MYSQL Docker container - mysql

I created MySQL cluster of nodes (2 datanodes, 1 management node, and 1 MySQL server node) on Docker Following the instructions from this link:
https://mysqlmed.wordpress.com/2017/09/04/mysql-cluster-in-docker-quick-step-by-step
Then I created a MySQL table to import a csv file (named daily.csv) using the command:
LOAD DATA INFILE 'C:/Users/Utilisateur/Desktop/daily.csv' INTO TABLE daily IGNORE 1 LINES;
and I got the error:
ERROR 1290 (HY000): The MySQL server is running with the --secure-file-priv option so it cannot execute this statement.
When I add LOAD DATA LOCAL INFILE ..
I get this error:
ERROR 2 (HY000): File 'C:/Users/Utilisateur/Desktop/daily.csv' not found (Errcode: 2 - No such file or directory)
When i check my secure-file-priv using the command:
SELECT ##global.secure_file_priv
I get the Following path: /var/lib/mysql-files/ but I have no idea how to access to it in order to copy my csv file, or even to access my.ini MySQL config file to change the variable secure-file-priv into NULL, which as I saw is another solution to get permissions to access my file.
As I am using Docker, I have no idea how to access the MySQL container config file.
I tried many ways but I see no issue. Could you please help me with this I would be very delighted as I spent a lot of time trying to fix it??
I followed these instructions but don't know where the file /etc/mysql/my.cnf to change the variable secure_file_priv to NULL is:
Mysql making --secure-file-priv option to NULL

In your case it might be sufficient to mount your local directory inside the directory expected by mysql (/var/lib/mysql-files/).
Try starting the container with an additional -v parameter, like this:
docker run -d -v C:/Users/Utilisateur/Desktop/:/var/lib/mysql-files --net=cluster --name=mysql1 --ip=192.168.0.10 -e MYSQL_RANDOM_ROOT_PASSWORD=true mysql/mysql-cluster mysqld
Or copy the file into the folder:
docker cp C:/Users/Utilisateur/Desktop/daily.csv mysql1:/var/lib/mysql-files
assuming the name of your container is mysql1, as in the link you provided.

Related

Trying to update root password on mysql or create a new user is giving me /mysql/user.MYD error

I tried to make a mysql_secure_installation but after I enter the password is giving me this:
...Failed! Error: File './mysql/user.MYD' not found (Errcode: 2 - No such file or directory)
Connecting using mysql cli and trying to create a new user gives me the same.
Mysql is 5.7 and installed via Homebrew
You haven't initialized the database. Your error means, that the table in which users are stored doesn't exist.
Have a look in your /etc/my.cnf file. There should be an entry datadir. Make sure this directory is empty. Then do
# mysql_install_db --defaults-file=/etc/my.cnf
This creates the schema mysql and all necessary tables. After that you can do
# mysql_secure_installation

MySQL LOAD DATA INFILE error 13 on a Pi

I am trying to use the LOAD DATA INFILE MySQL command on a Raspberry Pi running Raspbian. There are lot of similar questions on here but none seems to answer my problem exactly.
My code works fine on my Windows dev machine but on the Pi I get this error:
Can't get stat of '/var/www/transfer/categories.csv' (Errcode: 13)
Mysql statement is:
LOAD DATA INFILE '/var/www/transfer/categories.csv'
IGNORE INTO TABLE category
FIELDS TERMINATED BY ',' ENCLOSED BY '"';
The code is running in PHP and the database is MySQL.
The file and its '/transfer' folder have read permissions for World.
I have read a little about apparmor but can't see how to check or change how it is configured. There are 2 files in the /etc/apparmor.d folder. One is .usr.sbin.mysqld.swp but it doesn't seem to contain text and the other file refers to lightdm.
The database server and client is on the same server, so the LOCAL keyword doesn't apply.
My MySQL user has global privileges, so includes the FILE privilege.
I have checked the secure_file_priv setting and there is none.
I am sure this is some sort of permission or privilege issue, but I've run out of ideas. I want the file to live under the www folder because the system user has FTP rights to put it there. Ultimately I want to also create the file on the same machine but for now I'm happy to just read the file created under Windows.
$ errno 13
EACCES 13 Permission denied
Check your permissions; especially folder permissions. You can try su or sudo -u to the MySQL user and running ls -la /var/www/transfer/; if you don't see anything then you know the issue has to do with permissions of the folder and/or its contents.
If MySQL is running locally; to see which user: ps -elf | grep mysql
To switch to the MySQL user and test: sudo -u <mysql> bash

mysqldump: Got error: 1: "Can't create/write to file '*.txt' (Errcode: 13 "Permission denied")" when executing 'SELECT INTO OUTFILE'

Linux. No SELinux (disabled).
I try to run this command as my linuxuser (member of group mysql):
mysqldump --user=root --tab "/some/folder" dbname
Getting this error:
mysqldump: Got error: 1: "Can't create/write to file 'sometable.txt' (Errcode: 13 "Permission denied")" when executing 'SELECT INTO OUTFILE'
If I look in the folder, there is a sometable.sql file, but no txt file.
As I understand, the sql file is created from the user's name who run the command (linuxuser in my case), but the txt file gets generated by mysql server (mysql user in this case). Note that mysql user is also a member of mysql group.
What could be the problem? Tried everything :)
If you trying to execute a mysqldump in a client diferent that the server
can be a problem
I tried with mysqldump Ver 10.14 Distrib 5.5.56-MariaDB, for Linux (x86_64), and works only with the /tmp/ dir.
Perhaps, help info say that will not work
-T, --tab=name Create tab-separated textfile for each table to given path. (Create .sql and .txt files.) NOTE: This only works if mysqldump is run on the same machine as the mysqld server.
The solution was to change "some/folder" to an external location. Looks like there were permission problems because originally the folder mentioned was under Perforce root and probably it had read-only permissions.
I then changed the new folder permissions to:
mylinuxuser:mysql
making sure that both the user with which the process was started, as well as mysql server have permissions to write there. This is because the sql file is written from user's name and txt file is written from mysql server's name.
I also added my user to the mysql group.
This was something I just found and wanted to pass along for the folks searching for the same answer.
This has been occurring on systems running systemd. In the /lib/systemd/system/mariadb.service file is the setting, 'PrivateTmp=true'. This is a security measure to prevent the data from being seen by folks who shouldn't be seeing it.
If you run:
SELECT * TO OUTFILE '/var/tmp/tablename.txt' FROM TABLENAME;
It will create the file but it creates it in a systemd protected directory.
/var/tmp/systemd-private-[hash]-mariadb-[hash]/tmp/tablename.txt
You can either save the data from here which is perfectly acceptable or stop mariadb, create the directory /etc/systemd/system/mariadb.service.d and in that directory create the file 'mariadb.conf' (as an example; any file should do) with the following:
[Service]
PrivateTmp=false
Run systemctl daemon-reload to reload the configuration and restart mariadb.
You should be able to create backups now.
What has worked for me (in Windows), trying to export a file using:
SELECT * INTO OUTFILE 'C:/documents/dumps' from file
MySQL Service properties --> Log on: take note account defined.
Directory C:\documents\dumps --> properties --> Security: account defined above needs read/write privileges

Starting Mysql in OSX 10 (no brew, no daemon, just a simple start)

I don't want to install MySQL on my computer, I don't want to change configuration of my OS, I want just start the mysql process writing the db on a local folder given from parameters.
I downloaded the mysql bundle from the mysql web site, and tried to start it using the mysqld command inside the bin folder in this way:
./bin/mysqld -b /Users/me/tools/mysql-5.6.28-osx10.10-x86_64 -h ~/Projects/my-project/db
But I have this error when it executes:
2016-01-25 11:13:24 33251 [ERROR] Fatal error: Can't open and lock privilege tables: Table 'mysql.user' doesn't exist
Everyone can read and write in the db folder, what can be the problem?
Solved.
I found this page in the mysql doc http://dev.mysql.com/doc/refman/5.7/en/binary-installation.html.
To create and start a new db is needed to execute mysql_install_db (before Mysql v5.7.6) using the appropriate datadir and basedir.
In MySQL 5.6 the script is located under the scripts folder, not in the bin folder as is wrote in the docs.

Can't open and lock privilege tables: Table 'mysql.user' doesn't exist

I installed MySQL community server 5.7.10 using binary zip. I extracted the zip in c:\mysql and created the data folder in c:\mysql\data. I created the config file as my.ini and placed it in c:\mysql (root folder of extracted zip). Below is the content of the my.ini file
# set basedir to your installation path
basedir=C:\mysql
# set datadir to the location of your data directory
datadir=C:\mysql\data
I'm trying to start MySQL using mysqld --console, but the process is aborted with the below error.
2015-12-29T18:04:01.141930Z 0 [ERROR] Fatal error: Can't open and lock privilege tables: Table 'mysql.user' doesn't exist
2015-12-29T18:04:01.141930Z 0 [ERROR] Aborting
Any help on this will be appreciated.
You have to initialize the data directory by running the following command
mysqld --initialize [with random root password]
mysqld --initialize-insecure [with blank root password]
The mysql_install_db script also needs the datadir parameter:
mysql_install_db --user=root --datadir=$db_datapath
On Maria DB you use the install script mysql_install_db to install and initialize. In my case I use an environment variable for the data path. Not only does mysqld need to know where the data is (specified via commandline), but so does the install script.
mysqld --initialize to initialize the data directory then mysqld &
If you had already launched mysqld& without mysqld --initialize you might have to delete all files in your data directory
You can also modify /etc/my.cnf to add a custom path to your data directory like this :
[mysqld]
...
datadir=/path/to/directory
As suggested above, i had similar issue with mysql-5.7.18, i did this in this way
1. Executed this command from "MYSQL_HOME\bin\mysqld.exe --initialize-insecure"
2. then started "MYSQL_HOME\bin\mysqld.exe"
3. Connect workbench to this localhost:3306 with username 'root'
4. then executed this query "SET PASSWORD FOR 'root'#'localhost' = 'root';"
password was also updated successfully.
I had the same problem. For some reason --initialize did not work.
After about 5 hours of trial and error with different parameters, configs and commands I found out that the problem was caused by the file system.
I wanted to run a database on a large USB HDD drive. Drives larger than 2 TB are GPT partitioned! Here is a bug report with a solution:
https://bugs.mysql.com/bug.php?id=28913
In short words: Add the following line to your my.ini:
innodb_flush_method=normal
I had this problem with mysql 5.7 on Windows.
My problem was caused by an incorrect db restore.
When I dumed the db it also picked up the system mysql tables because I added a space after -p as mentioned here: mysqldump is dumping undesired system tables
Launching the docker instance would work, then I'd restore (and corrupt) the db and it would still keep running, but after restarting it would Exit with error code 1.
The solution was to dump and restore properly without the system tables.
I face the same issue with version Mysql 5.7.33 when the server has rebooted. I fix it by copy other server user files scp /var/lib/mysql/mysql/user.* root#dest:/var/lib/mysql/mysql.