I have a bash file db_reset
drop database foo;
create database foo;
And I am trying to run this script:
prompt> mysql -uroot -p < db_reset
the password is requested every time
prompt> mysql -uroot -p < db_reset
Enter password:
And I want to skip this step. Password is empty. I've tried with solutions like
prompt> mysql -uroot -p"" < db_reset
Enter password:
but the result is always the same. Can someone help me?
If you don't want to supply a password, just omit (leave off) the -p option
:~$ mysql -u root
N.B. A blank password is not secure. If this was my database, there's no way that there would be root account, or any account, without a password or other secure authentication mechanism. (MySQL shouldn't even allow connections without authentication.)
Related
I'm using MySQL 5.0 and I created a new user in my database:
create user 'johann'#'localhost' identified by 'johann22';
grant select on jewellery.customers to 'johann'#'localhost';
Now I'd like to connect as that new user but every time a quit MySQL, the command directly prompt me the password of 'root'
I have already tried to connect with root then connect to as the new user using this code:
-u johann -p johann22;
but it says that I have a syntax error.
-u johann -p johann22; is not an SQL command you can run in the mysql client. Those are command-line options for the mysql client.
So you would run this in your shell (not in the mysql client):
mysql -u johann -pjohann22
Also notice that you must NOT have a space between -p and the password. If you have a space, the -p means to prompt you for a password, then the word following the space (johann22) is the name of the database.
I am trying to figure out what the mysql -u root -p command does.
I have googled the command but I can't find any good results.
mysql -u root -p means, that you trying to connect to MySQL shell with parameters - -u parameter specified MySQL user name.
-u, --user=name User for login if not current user.
In your case it's root user.
-p, --password[=name]
Password to use when connecting to server. If password is
not given it's asked from the tty.
You can type mysql --help from the command line for more information about all available parameters.
Good luck.
It logs you into mysql as the root user. After -p (Immediately after it incidentally, no spaces) you would include the password.
`mysql -u root -p`
Its initiate a connection of MySQL.
-u means that we are going to connect with a username root
-p means that we will enter username's password
Check man mysql
Your command tries to connect to MySQL on localhost with user "root" and asking for a password
I've just downloaded MySql using this tutorial after installing it before.
I've thought that it would solve my problems but, whenever I try to login into MySql via the terminal I'm prompted to enter the password though I've already logged in with the following command:
mysql -u user -p password
Here is what happening:
$> mysql -u user -p MYPASSWORD
Enter password:
And after I insert my password again...
$> mysql -u user -p MYPASSWORD
Enter password:
ERROR 1049 (42000): Unknown database 'MYPASSWORD'
I'd like to know if there's a solution to this weird problem.
The command is:
mysql -u user -ppassword
So in your case:
mysql -u user -p123456
By adding a space between -p and your password, you're actually setting the database to use, which is why you get the error unknown database.
The other solution would be:
mysql -u user -p
In that case, your password will be asked by the terminal. It is a bit more secure as your password does not stay in plain text in your terminal history. But if your password is 123456, I guess you're not too concerned by security ... ;)
Under normal circumstances, I would use:
mysql -uroot -p
Enter password:
you can try it.... ;)
I am following this tutorial: http://dev.mysql.com/doc/refman/5.7/en/connecting-disconnecting.html
However when I run MySql command line client I automatically get asked for a password when I enter it I get connected automatically to a localhost database, how do I access other database's using something like the following as shown in the tutorial example?
shell> mysql -h host -u user -p
Enter password: ********
shell> mysql nameofdatabase -uusername -ppassword
You can put a space in between -u username but not between the -p and password.
There are multiple ways to access mysql on the command line. If you wish to connect to another database server, you need to add -h <hostname> to your mysql command. Without this, mysql assumes you want to connect to the local mysql server.
If you mean that you want to connect to another database on a host, just specify that database at the end of your command line.
$ mysql -u username -ppassword second_database
Note, there is NO space between -p and password. If -p is followed by a space, mysql will prompt you to enter a password interactively. Which you can do, if that is what you want.
$ mysql -u username -p third_database
Enter password: *********
Another way to connect would be to create a file in your home directory named .my.cnf. This file should contain the following:
[client]
user=username
password=yourpassword
If you have any special characters in your password, you will need to quote it. Having this file allows you to not need to enter any username or password on your command line:
$ mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
....
mysql>
I installed mysql on ubuntu server and did not specify password. When I do
mysql -u root -p
it prompts for password and without providing any input I just hit enter and it works.
Now I need to perform some operation on the database using cron job. My cron job does not work because mysql prompts for a password. I tried doing
mysql -u root -p'' my_database
but that did not work either.
Any suggestion?
Go like this mysql -u root --password="" dbname
Try not asking mysql to prompt for the password, 'mysql -u myuser'. I would suggest you create an account with only the required privileges to do this. Also limit its access to localhost. Put a password on root.
I installed mysql on ubuntu server and did not specify password. When
I do
mysql -u root -p
-p brings up the password prompt. If you do not have a password, then you do not want to do that.
Just write:
mysql -u root
For the love of god, get a password on that account!
For passing the password in the command use -p$PASSWORD. In the following example, user/password is root/root:
mysql -proot -D my-db -u root -h 127.0.0.1 -e "select * from my_table"
IMPORTANT: notice that there is no space between -p and the password in -proot
Check MySQL Documentation for how to reset your password, since I found no way to enter a password either. You could use the following: http://dev.mysql.com/doc/mysql-windows-excerpt/5.0/en/resetting-permissions-windows.html
Which states that you have to create a file with the following query:
UPDATE mysql.user SET Password=PASSWORD('MyNewPass') WHERE User='root';
FLUSH PRIVILEGES;
And then start up mysqld service with the --init-file parameter (see the documentation for more information about this). This should reset your root password.
Why don't you specify a password for root? For security reasons and your script would work.
Mysql's "root" account should have a password; otherwise anyone with an account on your machine has full access to the database.
Set a password (e.g. with SET PASSWORD)
Add the password to ~/.my.cnf
If you want more sane authentication options, I recommend Postgres.