PHP MySQL used command not allowed - php

I'm trying to use the LOAD DATA LOCAL INFILE command in MySQL, but I keep getting an error in PHP/Joomla stating: The used command is not allowed with this MySQL version
I've spent quite a while Googling around, but the only suggestions I've seen involve adding local-infile = 1 to my my.cnf file (which I've already done, in [client], [mysql], and [mysqld]).
Additionally, if I connect from my Apache server to the MySQL server from the command line (so not using PHP), I can run LOAD DATA LOCAL without issue (so it can't be a permissions thing).
I've also checked php.ini, and sure enough, mysqli.allow_local_infile is set to 'On'.
Am I missing something here?
Do you have to do something special in Joomla to make this work correctly?

I just answered a similar question here, maybe it can help:
After going from MySQL 5.0 to 5.5 I found out that I suddenly have to enable LOCAL INFILE specifically when creating the connection in PHP.
Using mysql:
mysql_connect(server,user,code,false,128); // 128 enables LOCAL INFILE
mysql_select_db(database);
Using mysqli:
$conn = mysqli_init();
mysqli_options($conn, MYSQLI_OPT_LOCAL_INFILE, true);
mysqli_real_connect($conn,server,user,code,database);

I ran into the same problem, in my case it was the Joomla user lacking privileges that root has; giving the full privileges to the J user solved it, but then my component is for distribution so I changed to using standard .sql file and parsing / creating them manually. Hope this helps.

Related

Why am I getting so many error messages in phpmyadmin localhost?

I just set up XAMPP and, when I start the Apache localhost, it displays all of these errors when I search "localhost/phpmyadmin"
I am very new to this (just downloaded XAMPP) and I watched this tutorial: https://www.youtube.com/watch?v=hqfIksHKPPg on setting it up (I didn't install phpmyadmin since it was already installed with XAMPP)
I edited the notepad text files as stated in the video, but instead of a login, I get all of the error messages shown in the above picture...
I also opened config.inc.php and edited the line:
['Servers'][$i]['(MySQL root password)'] = '';$cfg
so it matched MySQL root password
Even if you have a suggestion to fix one of the errors, please still comment
Also, if you need any more information please let me know
You're getting several error messages because you have several problems :)
Cannot connect: invalid settings
Some setting is incorrect, most likely something in your config.inc.php is misspelled or incorrectly copied and pasted. Specifically, if the line ['Servers'][$i]['(MySQL root password)'] = '';$cfg is actually how it appears in your configuration, that is clearly the problem as the line should actually be $cfg['Servers'][$i]['password'] = 'green'; except with you password instead of 'green'...except that only applies if your auth_type is 'config', otherwise the 'password' line isn't used at all (since you're prompted for the password at log in). I'm not sure what XAMPP does here for auth_type, but I don't think you should have had to edit the configuration file at all, since you used the XAMPP installer which should have configured everything.
The server requested authentication method unknown to the client [sha256_password]
This appears to be a bit of a version mismatch in your installed files. Access denied after setting user's password with SHA256 in phpMyAdmin goes in to more detail, but this most often occurs when you've got MySQL 8 and PHP older than 7.4. Normally, I'd suggest upgrading your PHP version — but you're using the packaged XAMPP, which certainly wouldn't ship with conflicting MySQL and PHP versions, so something is odd here. Please confirm for us your MySQL and PHP versions. You didn't happen to have an existing MySQL or PHP installation before you installed XAMPP, did you?
Connection for controluser as defined in your configuration failed
This is probably related to the MySQL 8/PHP 7.4 conflict. There is an administrative user (called the controluser) that phpMyAdmin can use to manage some extra features, ordinarily you wouldn't need it to access phpMyAdmin (only to access those additional features), but it seems XAMPP has configured this for you. Since the authentication fails, you get an additional message that the controluser was not able to connect.
You could bypass this by commenting out the configuration lines referencing controluser and controlpass, although again the XAMPP package should have this all configured so I don't recommend that at this point.
The other messages are basically echoes of the previous messages; you get an additional protocol notification because the controluser is trying the same sha256 connection type that the main user was, and then finally phpMyAdmin is telling you that MySQL rejected the connection.
If this is a fresh XAMPP install, I'd suggest reinstalling, because something got a bit confused. I'd also suggest making sure that you don't have any other conflicting software running — XAMPP is a package of all the included parts, so you don't want to install or run your own Apache or MySQL instance which would interfere with the packaged kit.

connect to SQL Anywhere by TCP/IP

I'm new in sql anywhere, currently I'm trying to connect using PHP.
This is what I've got so far:
$conn = sqlanywhere_connect ( "UID=usr;PWD=pass;ENG=serv;DBN=bd_name;COMMLINKS=TCPIP{HOST=10.1.1.189:2638}" );
SQL Anywhere is installed on another machine, where I can't run apache, website is running on localhost (xampp). This is only for test, when website would be ready I will connect to correct db.
This is error I've got:
Warning: sqlanywhere_connect(): The SQLAnywhere client libraries could not be loaded. Please ensure that dbcapi.dll can be found in your PATH environment variable. in C:\xampp\htdocs\core\cache\includes\elements\modsnippet\25.include.cache.php on line 21
I haven't got dbcapi.dll file, but I'm not sure I should have it.
In documentation I couldnt find this file (SQL Anywhere 10 which I've got), but for SQL Anywhere 11 I could find pages where was info about this file.
To use sqlanywhere_connect I've download SQL Anywhere module for curren ver. of PHP onto my machine and I've add it to php.ini file.
What should I do? Should I download missing file? Would it be enough or I could get more errors asking for other files?
I had a similar problem and the solution proposed here:
https://groups.google.com/forum/#!msg/sql-anywhere-web-development/zK9Tf-X3cYk/GAoqK2DnB9EJ
worked for me.
Specifically, my xampp + php needed the 32 bit dbcapi.dll but when I installed SQL Anywhere 12 I neglected to check the box to install the 32 bit version as well. Re-installing, chossing "modify" and installing the 32 bit SQL Anywhere 12 got "php test.php" working.
I would down load the missing file and go from there you are using xamp which is pre-built to talk to mySQl I doubt there is any extra .dll in the Instillation to connect with SQLAnywhere

PHP 5.4 old auth on shared server, fixing without editing the mysql server

I just upgraded my developement box's PHP to the latest version, 5.4.5. This developement machine connects to a remote MySQL server, residing on a shared server that I lease from a hosting company.
Trying to connect to my remote MySQL server using simple mysql_connect('myserver.com', 'user', 'password') results in the following error:
Warning: mysql_connect(): mysqlnd cannot connect to MySQL 4.1+ using the old insecure authentication. Please use an administration tool to reset your password with the command SET PASSWORD = PASSWORD('your_existing_password'). This will store a new, and more secure, hash value in mysql.user. If this user is used in other scripts executed by PHP 5.2 or earlier you might need to remove the old-passwords flag from your my.cnf file in file.php on line 2
Simply, as advised, just executing:
SET PASSWORD = PASSWORD('my-password');
wouldn't change anything.
The same applies when executing
SET SESSION old_passwords=FALSE;
After a bit of searching, I realized that I needed quite deep access to the MySQL server to be able to fix this problem, which I do not have. Trying to execute this query:
UPDATE mysql.user SET Password=PASSWORD('my-password')
WHERE User='my_user' AND Host='my-server';
FLUSH PRIVILEGES;
Simply gives me the following error:
1142 - UPDATE command denied to user 'u0112918'#'www10.aname.net' for table 'user'
Requests to have the company execute the query for me has, so far, been unsuccessfull. So my question is if there's any way to fix this on the client side, without involving the MySQL server?
Hm, try executing the following query through a tool other then PhpMyAdmin, such as Mysql Workbench or through a shell:
SET SESSION old_passwords=0;
SET PASSWORD = PASSWORD('passwordString');
You should be allowed to change your own password without DML Rights on user-table.
Edit: since it did not resolve the issue - when "read_only" is enabled for the database then you need super rights to change (even your own) password ( http://dev.mysql.com/doc/refman/5.5/en/set-password.html )

Wordpress installation - php and mysql are not talking to each other to access database?

I'm trying to get a wordpress local install working on my Mac.
I've recently set up a database, username and password using the MySQL client as per the instructions in the wordpress codex. That part is ok.
When I go to the local site on my computer I'm prompted by wordpress to set up the wp-config.php file. Putting in the same details that definitely work with the MySQL client returns an error.
Manually updating these details in the 'wp-config-sample.php' file and renaming it as 'wp-config.php' also doesn't work - I'm now greeted with a big bold message: "Error establishing a database connection".
From what I can gather, php and mysql are not communicating with each other properly.
I've changed the apache 2 configuration file found in 'etc/apache2/httpd.conf' and uncommented the line which loads the php5 module: LoadModule php5_module libexec/apache2/libphp5.so
and restarted the apache server. This has still not fixed my problem. I'm stuck on what to do next... help appreciated please!
It's been fixed now.
php was looking in the wrong place for the mysql.sock file, and couldn't communicate with the mysql database, meaning wordpress couldn't be set up.
On the command line I typed
ps aux | grep mysql
to bring up as much info about mysql that I could. From this I saw that the mysql socket on my computer is being used at /tmp/mysql.sock
Meanwhile, in the "wp-config.php" file, I changed the line define('WP_DEBUG', false); to define('WP_DEBUG', true); and refreshed my web browser that was showing my localhost setup. This now said a lot more info than "Error establishing a database connection" - infact I could see that the mysql.sock was not configured correctly at all.
Creating a 'phpinfo.php' file with just the single line of code <?php phpinfo(); ?> was the pivotal turning point for me.
Putting that 'phpinfo.php' file in my localhost directory and then viewing it from my web browser not only definitely confirmed that the mysql.sock file was not configured properly, but it also showed where the configurations were being loaded from on my machine: '/private/etc/php.ini'
The next thing I did was open up the 'php.ini' file in a text editor and doing a quick find and replace to update the correct location of mysql.sock.
Finally, a restart of the local apache server needed to be done to fully update all the new settings that I'd been fiddling about with.
sudo apachectl restart
Now everything works fine!
The Error-Message "Error establishing a database connection" indicates clearly, that the php-script can not establish the connection. This can have one of the following reasons:
Your host in the wp-config.php is not correct.
The mysql-server does not listen on that host
The user you set up in the mysql has no privileges to connect the way you are trying
The firewall blocks the access of the php-script to your mysql-host
Try to connect the database with the same settings of your wordpress using Sequel Pro (or any other GUI to connect a mysql database). If the connection works, the problem 2. and 3. isn't your problem.
Look in your firewall-log to make sure 4. is also not your problem.
If all problems are excluded (even 1. after a final check), try to run something like phpMyAdmin to connect your database, to make sure your php-installation has the needed drivers.

Confusing PDO-only problem : Can't connect through socket/Access denied/Can't connect to server (shared host)

So the problem changed from what it was, i'll leave the original question below to prevent bad reviews on answers like I had after someone editing his question I answered :
So I am working on a (really lame) shared hosting which has PDO installed, but it doesn't work.
With default parameters
<?php
try {
$dbh = new PDO('mysql:host=localhost;dbname=THE_DB_NAME', 'THE_USER', 'THE_PASSWORD');
echo 'Connected to database';
}
catch(PDOException $e)
{
echo $e->getMessage();
}
?>
it throws this message :
SQLSTATE[HY000] [2002] Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
With a simple mysql_connect, it works.
And the socket path seems correct (both phpinfo and this query :
show variables like 'socket';
confirm.
Localhost redirects to 10.103.0.14 (this data comes from mysql_get_host_info() and in phpMyAdmin)
In the PDO, if i replace localhost by 127.0.0.1 i will get
SQLSTATE[HY000] [2003] Can't connect to MySQL server on '127.0.0.1' (111)
And if i replace localhost by 10.103.0.14 :
Access denied for user 'USER_NAME'#'10.103.0.14' (using password: YES
Both IP adress (127.0.0.1 and 10.103.0.14) work with mysql_connect.
So apparently the problem comes from the PDO connection.
Does somebody knows where this could come from, or/and any way to fix it ?
Some server datas :
The PHP Version : 5.2.10
You can see the server's phpinfo : http://web.lerelaisinternet.com/abcd.php?v=5
No command line possible.
(i know it should be the tech suport's job, but they're reaaaaaly slow)
Thanks
Previous question :
How to find the mysql.sock on a shared host (tricky way needed...)
So today's problem is : The PDO connection doesn't work on a shared host, and it's supposed to (it's installed on the server).
Just a basic PDO connection :
<?php
try {
$dbh = new PDO('mysql:host=localhost;dbname=THE_DB_NAME', 'THE_USER', 'THE_PASSWORD');
echo 'Connected to database';
}
catch(PDOException $e)
{
echo $e->getMessage();
}
?>
throws this message :
SQLSTATE[HY000] [2002] Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
A regular mysql connection :
mysql_connect("localhost", "THE_USER", "THE_PWD") or die(mysql_error());
mysql_select_db("24DLJLRR1") or die(mysql_error());;
echo 'Connected to database <br/>';
works fine.
So apparently it cannot find the .sock.
I think specifying the correct address should work, i tried some "classic" mysql path that I found on internet, without success.
The phpinfo says it is at this adress (/var/lib/mysql/mysql.sock)
(The PHP Version is 5.2.10)
You can see the server's phpinfo : http://web.lerelaisinternet.com/abcd.php?v=5
So i am trying to figure out where the hell it is !!!
I tried to look in the phpMyAdmin interface, but i couldn't find the info, plus it seems that phpMyAdmin connects to a different server (it has a different IP adress, and trying to connect to it with php gives a "Wrong password" error). The mysql_connect also connects to this adress, i think it redirects to a different server with some internal password/login.
Well if you have any idea of how to obtain this info (the provider's technical support is "fixing the problem"... it's been 1 month...).
Also maybe the problem comes from somewhere else, but the same stuff works on other shared hosts...
The need of PDO is because I use the Symfony framework with Doctrine for this website, and the Doctrine plugin needs PDO... I don't want to redo the website from scratch !
Thanks for your help !
This was already marked as answered, but not really solved (without changing databases).
So, just in case someone like me also experiences this problem...
The easiest way to fix this is to first get the socket path (either by looking in the php.ini file or by using: phpmyadmin or the console (or construct it in mysql or mysqli)
...to run the following query (anything but PDO):
show variables like 'socket'; //as mentioned by symcbean
THEN, in the PDO connection string, change it to use the socket instead of a hostname:
$dbc = new
PDO("mysql:unix_socket=/var/run/mysqld/mysqld.sock;dbname=$DBName",
$User, $Password, array(PDO::ATTR_PERSISTENT => true)); // using
persistent connections
This worked for me.
FWIW, I had this issue and changed my host from 'localhost' to '127.0.0.1'.
I have no clue why localhost wasn't working, but that did the trick.
Odd thing is, we have tons of servers and it works on almost every one using 'localhost'
Is your server running with SeLinux enabled (enforcing)? If it is, try running as root:
# setsebool -P httpd_can_network_connect on
Can you try 127.0.0.1 as the server name instead of localhost?
IIRC, with some mySQL drivers / adapters, this decides whether the socket is used for establishing the connection or not.
Using the connection which works, run the query:
show variables like 'socket';
(this behaves just like a select statement)...and you'll get the path of the running socket.
Then check the file permissions.
I had the problem that production version worked just fine and a test version wasn't able to connect PDO :/
both versions was located at same servers, test in a sub directory.
The fix was replacing in DSN the localhost for ip.
'mysql:host=localhost;dbname=db'
became
'mysql:host=127.0.0.1;dbname=db'
try:
exec('`which mysql_config` --socket');
this should show you the configured socket.
I found the reason for the strange behaviour. If bind-address is different to 127.0.0.1 or 0.0.0.0 (all addresses) PDO can't connect to 127.0.0.1.
For what it's worth, I found this page after having the exact same issue. I am on a server running Apache & PHP only - MySQL is installed on another machine. I tried both the DNS name of the server and its IP and confirmed I could ping it. A PHP app on the same machine is talking to the database fine, using old syntax mysql_connect( ). But PDO from the CLI was throwing this error.
The solution for me was to check my DSN. Any typo in the DSN itself is ignored silently, and PDO assumes you mean localhost. My issue was I had "name=" instead of "dbname=" in the DSN.
The Issue In the Mysql configuration It you need to disable the option of skip-networking
in my.conf configuration file this should work fine
reference
http://www.wolfcms.org/forum/post7098.html#p7098
I just solved a similar issue. My guess is you probably replaced your mysql_connect() statement with the PDO equivalent. Don't forget you still have lots of other code dependent on that old connection statement. Try keeping the mysql_connect in place while writing in the PDO code.
What worked for me was specifying the port number like so:
mysql:hostname;port=3306;dbname=dbname;
This got it to work when connecting to a local database. Now I'm working on getting it to work with a remote db.
My problem may be different to the OP, but I thought it was worth posting. I did a software upgrade on a VM, then rebooted and got the OP's error message. It turned out to be an out-of-memory problem preventing mysql from starting. Deleting a few large files made the problem go away.
One year later, I found a solution for this issue : using a SQLite database. PDO worked fine, but not with MySQL
** EDIT ** as everyone is downvoting this: This solved my issue (I'm the OP). I was using Doctrine, so switching RDBMS was easy and quick. Also the website was some a home made CMS, with very few trafic, so SQLite was fine.
I know it's not a real "Answer" to the problem, but if someone is in the same context: a crappy shared hosting which you can't change with this weird PDO-MySQL bug AND is using doctrine. This IS a solution. I can delete this answer, but if I had thought of this at the time of the OP, I would have saved a lot of time.

Categories