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.
Related
Can I pass this string
mysql2://user1:rXbNgLjBHrdxYT#localhost/onebody?socket=/opt/bitnami/mysql/tmp/mysql.sock
to the mysql command inside bash, to make a connection?
If so, how...
Not literally. mysql CLI takes several options into which the string needs to be split (see man mysql).
Assuming "onebody" is the DB name, I guess it is:
mysql --protocol=socket --socket=/opt/bitnami/mysql/tmp/mysql.sock --database=onebody --user=user1 --password=rXbNgLjBHrdxYT.
If you omit the password value following the --password or -p option
on the command line, mysql prompts for one.
Specifying a password on the command line should be considered insecure. See Section 6.1.2.1, “End-User Guidelines for Password Security”. You can use an option file to avoid giving the password on the command line.
This question already has answers here:
How to provide password to a command that prompts for one in bash?
(8 answers)
Closed 8 years ago.
I am trying to execute a shell script to login to mysql as root and execute some commands, and in order to avoid putting the root's password in the command line, I am using heredoc format as shown below.
However, mysql prompts me for the password despite the fact that I am giving it the right password.
Exactly the same syntax works perfect on some other hosts but not here.
Why?
mysql#myhost:MySQL> mysql -uroot -p -s -P3306 -e 'SELECT NOW();' <<EOF
> MyPassword
> EOF
Enter password: <---- why does it require manual password entry in here?
2014-12-23 14:57:25
Assuming you use a BASH or KSH command line interface:
read -s pwd;mysql -uroot --password=${pwd} -s -P3306 -e 'SELECT NOW();'
For the read command, you should use the -s option because, as it happens with using heredoc, this solution would also display the password as it is being typed, if you wouldn't use said option.
This solution works because the mysql client obfuscates the password so it does not show in the output from process-listing commands, like ps. Run this:
read -s pwd;mysql -uroot --password=${pwd} -s -P3306
Then, if you open an additional command line interface and execute ps, you will see that it does not show the password, but and obfuscated version of it, in the process list.
This was a famous bug of the mysql client, back in the day, but was fixed in 2002.
Using read -s to put the password in a variable has the added benefit of not showing the password in the command-line interface's history.
I've heard that directly inputting your password on the command line is a bad idea, because anyone could see the "secret" in
mysql -u root -psecret
by browsing history.
I have a password for my MySQL database stored in a text file with limited read permissions, and was wondering if it is safe to access it in the following way:
mysql -u root -p$(cat ~/.mysql_pass)
Browsing history, I see the command printed, not the literal value. So it seems like it's working the way I want it to.
I'm sure there are better ways of handling passwords, I would just like to know whether or not this one is leaving my password completely out in the open.
You've suggested using the following:
mysql -u root -p$(cat ~/.mysql_pass)
However, the subcommand will be expanded before mysql is executed and so even if this isn't available in the command history, it's entirely possible for someone to view the process list just after invocation and see your password.
I think a better approach is to use a mysql client options file and have the mysql command read the password from the options file.
Just type mysql -u root -p and you'll get a prompt to enter your password and it won't be stored in the history.
I'm having some serious trouble with a freshly installed copy of mySQL server under Ubuntu 10.10. I installed with apt and supplied a password at that time. Installation went fine, but the server is behaving very strangely.
First, to test the database, I created a php file with
mysql_connect("localhost", "root", "myPassword") or die(mysql_error());
where myPassword is the one I entered when it asked, during installation. That gave me an access denied error. I tried to shell into the mySQL server to pursue a solution I read about. The normal syntax didn't work, and to get anything but "access denied", I had to do
mysql -u root password myPassword
However, instead of a mysql shell, it just spits out a list of parameters and variables. So at this point, I'm stumped; I haven't worked with mySQL through a command line in a couple of years, but none of this behavior is familiar, and I can't find a way to interact with the server.
Any help would be appreciated.
The mysql command-line parameter for supplying a password is -p, not password. You should also leave out spaces. For example:
mysql -uroot -pmyPassword
If you don't want to risk your password being exposed...
mysql -uroot -p
...will prompt you for your password and hide the characters as you type them.
If you have apparmor installed (this is default) it can cause problems when you go outside the narrowly-defined defaults set up by ubuntu.
The things that mysql is allowed to touch is defined here: /etc/apparmor.d/abstractions/mysql
If you've put your socket file elsewhere, you would get an access-denied message.
To look at things more closely, run your mysql client like so:
strace -e file mysql <blah blah>
This will print out any system-level file operations on stderr. You can then see exactly which operation is causing the permissions error. If you don't see an issue, you might use -e network instead, to see network operations.
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.)