Apologies for my longest question on SO ever. I'm trying to interface with a php frontend for a mysql database in ROOT (a CERN framework in C++ for high energy physics analysis). To start off with, I tried to get this php interface to play nice with wget and curl first because I'm more familiar with them. The following command works:
wget --post-data "hostname=localhost:3306&un=joeuser&pw=psswd&myquery=show_spazio_databases;" http://some.host.edu/log/log_query_matlab.php
The results are:
database1
database2
That's good. If I leave out the --post-data then I get the result:
Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'admin'#'localhost' (using password: NO) in /log/log_query_matlab.php on line 6
i'm dead! Access denied for user 'admin'#'localhost' (using password: NO)
Warning: mysql_query() [function.mysql-query]: Access denied for user 'admin'#'localhost' (using password: NO) in /log/log_query_matlab.php on line 29
Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in /log/log_query_matlab.php on line 29
I have access to the php script (read only), but the error itself isn't too important. What matters it that using ROOT, I use a function called as socket.SendRaw(message, message.Length()) (socket is a TSocket) and this gives me the same "error" as wget without the post data switch if my "message" is
"POST http://some.host.edu/log/log_query_matlab.php?hostname=localhost:3306&un=joeuser&pw=psswd&myquery=show_spazio_databases"
This may be in vain, but does someone knows a way I should format the "message" that includes something that is equivalent to the --post-data switch. Or, is there a standard way to format POST requests in a single line (I've seen multi-line stuff. Is that right?) Sorry I'm clueless!
PS. The mysql query is show databases but the space has been replaced with _spazio_, Italian for space. The author of the db and php interface requires it (and various replacements for symbols), but has anyone seen this before? Trying to troubleshoot that was terrible!
The correct "one liner" (had to be multiline) was:
POST http://some.host.edu/log/log_query_matlab.php HTTP/1.1
Host: some.host.edu
Content-Type: application/x-www-form-urlencoded
Content-Length: 73
hostname=localhost:3306&un=joeuser&pw=psswd&myquery=show databases
The end of each line has \r\n. The gap after content-length has two sets of those.
Related
This question kind of involves many things and i don't know from where to make a workaround. I found a solution, but i think it is a nasty one.
i have this LWRP that installs mysql and as the last step i update the password if it is provided and it is not defined before:
ruby_block "Changing password for root" do
block do
if !(root_password.nil? || system("\"#{installation_path}\\bin\\mysql.exe\" -u root -p#{root_password} --execute \"exit\""))
# In order to allow the service to completely start and then change the passowrd
#
sleep 30
change_pass_str = "\"#{installation_path}\\bin\\mysql.exe\" -u root --execute \"UPDATE mysql.user SET Password=PASSWORD('#{root_password}') WHERE User='root';FLUSH PRIVILEGES;\""
password_set_result = system(change_pass_str)
else
puts !password_set_result ? "Password wasn't changed since root already have a password defined. Maybe there's still data from a previous installation." : "Password has been set!"
`dir`
end
end
end
when this resource is executed in chef it prints or throws or STDOUT or i don't know how to call it, the next lines:
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: Yes)
that line is not captured if i execute the mysql call with `` (backticks), i mean, something like this:
irb(main):002:0> response = `mysql.exe -u root -pdevtest --execute \"exit\"`
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: YES)
=> ""
irb(main):003:0> puts response
=> ""
only returns "", instead of returning the error string itself.
the thing is that when i later (in the recipe cookbook that implements mysql installation and does other stuff with subversion) execute subversion resource with action :export (i think it would fail with any other action), it fails telling that it returns exit status 1, but it doesn't is the exit status that mysql throw.
if i add a dir system call (as you can see in the ruby block), subversion resource passes without any problem as the dir system call (i think) resets the exit status to 0.
The dir system call, i guess is a really nasty way to work around this, that's why i'm asking for your help, how do avoid mysql to throw (or STDOUT) that thing, or how do i catch it or reset the exit status?
A lot of things here.
First I would bet the ERROR from mysql is sent to stderr and not stdout, it is why its not captured, you may redirect it to stdout with the classic 2&>1 redirection to capture the error.
The exit status is the last command status, mysql had an error and so set its exit status to something different from 0.
All in all, you should avoid system call in chef recipe and use Mixin::ShellOut instead wich give you more control over what you run.
I have a shell script which calls the mysql command line client, it looks like this:
$ cat ms
mysql --host=titanic --user=fred --password="foobar"
It works OK:
$ ./ms
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 810
...
Now, I'd like to keep the script in a git repository, but without the user and password details. So, I thought I would have a file SECRET with: --host=titanic --user=fred --password="foobar" which I wouldn't add to the git repository, and change the ms script like this:
mysql $(cat SECRET)
Unfortunately, it doesn't work. I get this error when I run it:
$ ./ms
ERROR 1045 (28000): Access denied for user 'fred'#'example.com' (using password: YES)
I cannot understand it - when the $(cat SECRET) is evaluated/expanded it looks exactly the same as the straightforward invocation of mysql. Still, it doesn't work. The same happens if I try to do it directly in interactive shell:
$ mysql --host=titanic --user=fred --password="foobar"
works OK, but the below does not:
$ cat SECRET
--host=titanic --user=fred --password="foobar"
$ mysql $(cat SECRET)
ERROR 1045 (28000): Access denied for user 'fred'#'example.com' (using password: YES)
$ echo mysql $(cat SECRET)
mysql --host=titanic --user=fred --password="foobar"
Anybody can shed some light on what's going on here and how to fix it? Many thanks in advance.
Change the file to:
--host=titanic --user=fred --password=foobar
Quotes aren't processed on the result of command or variable substitution, only word splitting and filename expansion are done.
But a better solution would probably be to use an option file, e.g. mysecret.cnf:
[mysql]
user=fred
password=foobar
host=titanic
Then run mysql as:
mysql --defaults-file=mysecret.cnf
I am trying to learn PHP and MySQL and while I reached a chapter on MySQL I was asked to create a database using this command:
CREATE DATABASE publications;
After I typed it in the mysql console I got this error:
ERROR 1044(42000):Access denied for user ''#localhost' to database 'root'
I am already logged in to my administrator account so I think the privileges should't be a problem.I have installed with the XAMPP package.
How can this be solved?
It could be possible that you upgraded your version of EasyPHP or you did something to disable the root password. If that is the case, you should try reestablishing a password for root. Had the same problem and that's how I solved it.
Go to http://localhost/xampp/ and set the appropriate passwords (in Security tab). If you use mysql client program, make sure you call it with appropriate credentials: mysql -u <username> -p <password>. Username will mostly be root until you create some new accounts.
Then I suggest you use phpMyAdmin for experimenting with MySQL (it should be at http://localhost/phpmyadmin/ )
This is getting a little confused - let me try to answer this.
Mysqladmin is a command line client for administering your mysql database system - you normally don't need to run it once you have mysql working. The shell command line interface to the mysql server is mysql. (If you don't know how to run a shell command line, that's another problem. Also, if you're on Windows, say so, since that has its own challenges.) The arguments are:
mysql -u username -ppassword databasename
if you are running this command on the same server as mysql. Note the lack of space after the -p - that is important.
So, type the above line to invoke the command line interface to mysql. Then you can type your mysql commands. Things like show tables, desc tablename, etc., will work. That is they will work unless you have an authentication problem. But you will know you have an authentication problem because when you tried to run mysql as above, it will fail with some error, like "Access denied for user 'abc'#'localhost' (using password: YES)". This is a nice descriptive error message that points you exactly where the problem is.
Does that help?
You can go back to using xampp or anything else once you've made sure that you know the right parameters by checking with the command line. (Always check with the command line when strangeness happens - it's so much easier than trying to debug through other interfaces.)
If I run the mysql or mysqldump programs from the command prompt, I get this in Windows:ERROR 1045 (28000): Access denied for user 'ODBC'#'localhost' (using password: NO). I understand that 'ODBC' is the default user. Is there a way to change this somewhere?
I switch back and forth between Windows and Linux quite frequently and the slight difference kills me. While a simple -u root isn't a lot of typing, forgetting it the occasional time is quite frustrating!
Looks like it's hardcoded in the source code, you have to change that and rebuild it yourself. A common trick would be to create a batch/bash program with the same name as the executable (of course you have to move the executable somewhere first, even on Windows due to .bat/.exe execution order) which checks for empty arguments. If they're empty, append '-u root' to the command, otherwise bypass the arguments to the real executable
So I can connect with (obviously I replaced all the real values)
mysql -u username -p -h db.dbhostname.com dbname
But when I run Catalyt's create script I get
$ ./script/dasgift_create.pl model DB \
DBIC::Schema MyApp::Schema create=static \
components=TimeStamp \
dbi:mysql:dbname:db.dbhostname.com username p#55w0rd
DBIx::Class::Schema::Loader::make_schema_at():
DBI Connection failed:
DBI connect('dbname:db.dbhostname.com','username',...) failed:
Access denied for user 'username'#'whereiam.com' (using password: YES)
at /opt/local/lib/perl5/site_perl/5.8.9/DBIx/Class/Storage/DBI.pm line 1104
Its behaving like the db server isn't allowing connections from whereiam.com, but I can connect via the command line just fine, and tried opening the db up to connections from anywhere temporarily, still with no success. Sorry for what little information I could provide, but that's all I have presently.
I don't think mysql DSNs work that way. Try running the script as:
./script/dasgift_create.pl model DB DBIC::Schema MyApp::Schema \
create=static components=TimeStamp \
'dbi:mysql:database=dbname;host=db.dbhostname.com' \
username p#55w0rd
(the changed part being just the DSN, but I formatted it with backslash-newlines for you so you can paste it if you want).
Sorry to have wasted your time. I feel like a moron. My password had a dollar sign in it and I didn't bother to put it in quotes, so it was essentially truncating the password trying to expand an environment variable. Quoting it properly fixed the problem. Thanks again for your response hobbs, btw the original connect string works as well.