Reputation: 12594
when i use following command in my shellscript to use the mysql,
mysql -uUserName -pPassWord DBName
i get the following warning
Warning: Using a password on the command line interface can be insecure.
my shellscript is running this command in loop to insert some data in my table, so it is giving warning continuosly on screen, that makes the output totally clumsy, so what should i do to stop printing this warning from mysql
Upvotes: 2
Views: 4904
Reputation: 4433
If your MySQL client/server version is a 5.6.x a way to avoid the WARNING message are using the mysql_config_editor tools:
mysql_config_editor set --login-path=local --host=localhost --user=UserName --password
Then you can use in your shell script:
mysql --login-path=local DBName
instead of:
mysql -uUserName -pPassWord DBName
Upvotes: 4
Reputation: 124714
You can put your mysql
connection info in ~/.my.cnf
, like this:
[client]
database=dbsite
user=dbuser
password=dbpass
host=dbhost
Then you can call mysql
without any parameters, it will take username, password, and all other details from ~/.my.cnf
.
However, use strict permissions for this file:
chmod 0600 ~/.my.cnf
If you don't want to pollute your ~/.my.cnf
file, you can create a file somewhere else, for example /path/to/my.cnf.dbname
, and call mysql
like this:
mysql --defaults-file=/path/to/my.cnf.dbname
Once again, make sure to set strict permissions for this file:
chmod 0600 /path/to/my.cnf.dbname
UPDATE
A common pitfall is to set host
incorrectly. This setting must match the setting in the mysql.user
table of your user. You can confirm your user account by running this query as the database admin:
select Host, User from mysql.user;
Alternatively, you can find the hostnames used in the server's configuration files, for example:
grep -r host /etc/mysql
However, the right path depends on your system. (This is from a standard Debian install.)
Upvotes: 2
Reputation: 416
mysql -u <UserName> -p <PassWord> then press enter.
Note: if a password set then only provide the password otherwise leave it blank.
And then run a command "mysql> use <databasename>;
Upvotes: -1