mysqlimport from --secure-file-priv folder, but still got error - mysql

I had set --secure-file-priv as following:
mysql> show variables like '%secure%';
+--------------------------+----------+
| Variable_name | Value |
+--------------------------+----------+
| require_secure_transport | OFF |
| secure_auth | ON |
| secure_file_priv | E:\test\ |
+--------------------------+----------+
but I got an error like this:
D:\Tool\mysql-5.7.17-win32\bin>mysqlimport -u root -p my_test tb < e:test/new/outfile.sql
Enter password:
mysqlimport: Error: 1290, The MySQL server is running with the --secure-file-priv option so it cannot execute this statement, when using table: tb
Another error:
D:\Tool\mysql-5.7.17-win32\bin>mysqlimport -u root -p my_test tb < e:test\new\outfile.sql
Enter password:
mysqlimport: Error: 1290, The MySQL server is running with the --secure-file-priv option so it cannot execute this statement, when using table: tb
what should I do to tackle this?

The fact is that in my.ini you did not specify the correct directory
Secure File Priv.
secure-file-priv="F:/directory"

Related

MySQL 5.6 Where is Show Master Status information stored

I am looking for a way to pull the information that is returned from Show Master Status so that I can assign the File and Position values to a variable.
I was able to set slave_relay_log_info and slave_work_info to tables but that does not show the local Master information I need.
SHOW MASTER STATUS;
I am not sure what table holds the Show Master Status data.
In Linux bash script you can try below command through mysql client to store the File and Position in variables
For File:
mysql -u username -p password -h IP -P Port -e "show master status" | grep "File"| cut -d ":" -f2
For Position:
mysql -u username -p password -h IP -P Port -e "show master status" | grep "Position"| cut -d ":" -f2
For MySQL 8.0 the log file and log position are in the log_status table of the performance_schema schema:
mysql> SELECT * FROM log_status ;
+--------------------------------------+------------------------------------------------------------------------------------------+------------------+-----------------------------------------------------------+
| SERVER_UUID | LOCAL | REPLICATION | STORAGE_ENGINES |
+--------------------------------------+------------------------------------------------------------------------------------------+------------------+-----------------------------------------------------------+
| 506c04ec-815c-11ed-a962-0800272d3b77 | {"gtid_executed": "", "binary_log_file": "mysql-bin.000022", "binary_log_position": 157} | {"channels": []} | {"InnoDB": {"LSN": 36558461, "LSN_checkpoint": 36558461}} |
+--------------------------------------+------------------------------------------------------------------------------------------+------------------+-----------------------------------------------------------+
The values can be extracted directly like this:
mysql> SELECT JSON_EXTRACT(`LOCAL`, '$.binary_log_file') AS file, JSON_EXTRACT(`LOCAL`, '$.binary_log_position') AS position FROM log_status ;
+--------------------+----------+
| file | position |
+--------------------+----------+
| "mysql-bin.000022" | 157 |
+--------------------+----------+

mysql 1290: have set "secure_file_priv" and used absolute path

System: Centos
Vesion:
Server version: 5.5.56-log Source distribution
What I did:
Have set the secure_file_priv in my /etc/my.cnf
mysql> SHOW VARIABLES LIKE "secure_file_priv";
+------------------+---------------+
| Variable_name | Value |
+------------------+---------------+
| secure_file_priv | /target_file |
+------------------+---------------+
Have restarted myssql service by service mysql restart, and inaddition I have restart the server/machine too
and I set chmod 777 /target_file
But I still get
>> select * from mytable into outfile '/target_file/config';
>> ERROR 1290 (HY000): The MySQL server is running with the --secure-file-priv option so it cannot execute this statement
Did I miss something?

Can't connect to Mysql installation on Centos 7

Install MySQL using mysql57-community-release-el7-7.noarch.rpm
started the MySQL server using service mysqld start
when I try to connect MySQL or any other client app on the localhost I get.
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: NO)
I never set an admin password not sure what is the default and what am I missing.
First you will have to reset the password,in some cases theres no need to enter any password simply press Enter when prompted and then you can change the password using ALTER USER command,but if it doesn't works Go through the following procedure,
First you will have to get the temporary password , type in the terminal :
grep 'temporary password' /var/log/mysqld.log
You will get a temporary password at the end of the sentence, login to mysql using that temporary password as
mysql -u root -p
Enter Password : (Enter you Temporary password Here)
Now you will have to change the default password, for that you will have to go through some rules.
NOTE: Type the following command inside mysql
mysql> SHOW VARIABLES LIKE 'validate_password%';
You will get a table like :
+--------------------------------------+--------+
| Variable_name | Value |
+--------------------------------------+--------+
| validate_password_dictionary_file | |
| validate_password_length | 8 |
| validate_password_mixed_case_count | 1 |
| validate_password_number_count | 1 |
| validate_password_policy | MEDIUM |
| validate_password_special_char_count | 1 |
+--------------------------------------+--------+
For minimal validation, type(optional you can change it anytime)
mysql> SET GLOBAL validate_password_length=6;
mysql> SET GLOBAL validate_password_policy=LOW;
This will check for minimum 6 digit password
Now you can change the default password,
For E.g if you want to set 123456 as your new password
mysql> ALTER USER 'root'#'localhost' IDENTIFIED BY '123456';
Hope it will solve your problem.
Check /var/log/messages for more details.

Shell script: Launch Mysql script using shell variable

I have a problem launching MySQL script from shell. I assign a value to my variable ${x}, using filename. So I have to launch a MySQL script using this variable. I would like to launch script without insert all MySQL code in shell (is too long) but using:
mysql -h localhost -uuser -ppsw DB < script.sql
My tentatives are:
mysql -h localhost -uuser -ppsw DB -e "set #x=${x}; source script.sql"
mysql -h localhost -uuser -ppsw DB -e "set #x=${x};"
mysql -h localhost -uuser -ppsw DB< script.sql
But not work for me. Could you help me?
I was surprised that your first solution didn’t work:
mysql -h localhost -uuser -ppsw DB -e "set #x=${x}; source script.sql"
Analysis
source is a MySQL command
set #x=${x}; is an SQL statement.
I thought that there may be an issue combining the two types as one statement as the MySQL --execute=statement, -e statement is supposed to execute the statement and quit.
The and quit part is why the redirected stdin is ignored when I tried my first idea:
mysql -h localhost -uuser -ppsw DB -e "set #x=${x};" < script.sql
Solution
After further experiments, I figured out that simply appending a semi-colon to the source command will prevent the syntax error.
I can’t say why this works as a semi-colon isn’t usually required to terminate the last SQL statement of a list but there you have it:
mysql -h localhost -uuser -ppsw DB -e "set #x=${x}; source script.sql;"
As Glenn Jackman pointed out, if the shell variable is a non-numeric string, the shell variable will have to be wrapped in single quotes so that when the MySQL variable is being assigned, MySQL will treat the right hand side (the shell variable) as a string literal instead of as an identifier for a column name:
mysql -h localhost -uuser -ppsw DB -e "set #x='$x'; source script.sql;"
This version will also work safely with numeric strings as can be seen in the examples below. I’ve also removed the curly braces around the shell variable since they’re not necessary.
Examples
Contents of t.sql:
select now();
select #variable as 'Contents of variable';
Use a numeric string as the shell variable:
$ number=3
$ mysql -e "set #variable=$number; source t.sql;"
+---------------------+
| now() |
+---------------------+
| 2015-10-02 13:06:45 |
+---------------------+
+----------------------+
| Contents of variable |
+----------------------+
| 3 |
+----------------------+
Use a non-numeric string as the shell variable generates errors:
$ text=text
$ mysql -e "set #variable=$text; source t.sql;"
ERROR 1054 (42S22) at line 1: Unknown column 'text' in 'field list'
$ text="This is a string"
$ mysql -e "set #variable=$text; source t.sql;"
ERROR 1064 (42000) at line 1: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'a string' at line 1
Now wrap the shell variable in single quotes:
$ mysql -e "set #variable='$text'; source t.sql;"
+---------------------+
| now() |
+---------------------+
| 2015-10-02 13:08:04 |
+---------------------+
+----------------------+
| Contents of variable |
+----------------------+
| This is a string |
+----------------------+
$ text=text
$ mysql -e "set #variable='$text'; source t.sql;"
+---------------------+
| now() |
+---------------------+
| 2015-10-02 13:10:53 |
+---------------------+
+----------------------+
| Contents of variable |
+----------------------+
| text |
+----------------------+
$ mysql -e "set #variable='$number'; source t.sql;"
+---------------------+
| now() |
+---------------------+
| 2015-10-02 13:11:42 |
+---------------------+
+----------------------+
| Contents of variable |
+----------------------+
| 3 |
+----------------------+
Using a non-existing shell variable will set the MySQL variable to an empty string:
$ mysql -e "set #variable='$nonexistent'; source t.sql;"
+---------------------+
| now() |
+---------------------+
| 2015-10-02 13:06:14 |
+---------------------+
+----------------------+
| Contents of variable |
+----------------------+
| |
+----------------------+

sqoop import from mysql to hive, username getting changed (Access Denied for user)

I am trying to import some data from mysql to hive via sqoop. It works when both sqoop and mysql db are on the same host, otherwise it fails. This is the query I am executing.
[user#xyz ~]$ sqoop import --connect "jdbc:mysql://abc.something.com/test" --username user --password pass --table dataSql --hive-import --hive-table test.dataHive --target-dir /tmp/sqoop$RANDOM
Please note that I am currently on host xyz and I am trying to connect to a mysql db on host abc. Following are the error I see.
ERROR: org.apache.sqoop.manager.SqlManager - Error executing statement: java.sql.SQLException: Access denied for user 'user'#'xyz.something.com' (using password: YES)
.
.
.
ERROR: org.apache.sqoop.manager.CatalogQueryManager - Failed to list columns java.sql.SQLException: Access denied for user 'user'#'xyz.something.com' (using password: YES)
.
.
.
and so on. My question is, why is my machine appending its hostname to username ('user'#'xyz.something.com')? How do I solve it?
When sqoop and mysql are on the same host, most likely the ip source is localhost, on the remote host this is not longer true and you get access denied.
Log into mysql and do this query:
mysql> select user, host from user;
+------------+---------------------+
| user | host |
+------------+---------------------+
| amon | % |
| cm | % |
| hive | % |
| hue | % |
| nav | % |
| navms | % |
| oozie | % |
| retail_dba | % |
| rman | % |
| sentry | % |
| root | 127.0.0.1 |
| root | localhost |
| root | quickstart.cloudera |
+------------+---------------------+
check if your user name user is into this table and has % (any) as hostname or xyz.something.com. It your user is not in this table you need to add it:
mysql> create user 'test'#'%' identified by 'password';
mysql> grant select privileges on *.* to 'test'#'%';
mysql> flush privileges;
Sqoop import data from mysql to hive, it will use jdbc interface which connects mysql with mysql-connect-j.
When I use mysql-connector-java-5.1.9.jar, it also has this problem. And I replace it with mysql-connector-java-5.1.38.jar, then sqoop works fine.
MySQL connections can be restricted to specific users connecting from specific hosts.
In this case I suspect that the GRANT command was applied to 'some_user#localhost' so that remote connections are blocked...
Have a look at the answers to that post to get the idea.
'user'#'xyz.something.com' this is actually the user that visit the DB.
As your sqoop host is xyz, the "user" from machine "xyz" is visiting the machine "abc", but the password is wrong (or maybe there isn't a "user" from machine "xyz" is allowed to visit "abc"), so the DB from the "abc" throw out this error and "xyz" sqoop print this message.
Hope this gonna help.
The --username user --password pass here specifies the user credentials given access to use the test database, it is not for the mysql as a whole. So modify this accordingly.