create account

Linux Absolute Beginners #1 : How to safely run mysql queries on command line by helcim

View this thread on: hive.blogpeakd.comecency.com
· @helcim · (edited)
$0.03
Linux Absolute Beginners #1 : How to safely run mysql queries on command line
First a word of warning: **This works for me, it does not have to work for you**.

Why use mysql interactively when you are interested only in one or two queries. It's much quicker to give you SQL query on command line. The problem is if you don't want to specify password interactively but would like to pass it on command line as well. It's possible but not safe so it's better to use a safer way to do it.  Before you can do it you have to use only once `mysql_config_editor` to set a variable `login_path`like this:

    mysql_config_editor set --login-path=<login_path_name> --host=<hostname> --user=<username> --password

In most cases your `<hostname>` will be `localhost` and  `<username>` will be  `root` so it can look e.g. like this 

    mysql_config_editor set --login-path=myhostalias --host=localhost --user=root --password

Then, when prompted you have to enter password for the mysql user you specified with `--user` option. After you registered your `hostalias` you can use `mysql` client without specifying password on command line.  You don't have to use `-u` and `-p` to specify user and password, you just specify `--login-path` option with the variable set before e.g like this: 


    mysql --login-path=myhostalias mydatabase -e "select body from posts where id=20;"
👍  , , , , , , ,
properties (23)
authorhelcim
permlinklinux-absolute-beginners-1-how-to-safely-run-mysql-queries-on-command-line
categorylinux
json_metadata{"tags":["linux","tips","opensource","mysql","sql"],"app":"steemit/0.1","format":"markdown"}
created2019-06-07 20:36:51
last_update2019-06-08 05:51:21
depth0
children1
last_payout2019-06-14 20:36:51
cashout_time1969-12-31 23:59:59
total_payout_value0.023 HBD
curator_payout_value0.004 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length1,291
author_reputation210,624,982,764,214
root_title"Linux Absolute Beginners #1 : How to safely run mysql queries on command line"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd0
post_id86,233,147
net_rshares52,494,646,690
author_curate_reward""
vote details (8)
@sqlguy ·
Now that's great. Thanks for sharing.
👍  
properties (23)
authorsqlguy
permlinkpsrw7k
categorylinux
json_metadata{"tags":["linux"],"app":"steemit/0.1"}
created2019-06-08 09:11:45
last_update2019-06-08 09:11:45
depth1
children0
last_payout2019-06-15 09:11:45
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length37
author_reputation7,175,710,013
root_title"Linux Absolute Beginners #1 : How to safely run mysql queries on command line"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id86,260,776
net_rshares954,719,180
author_curate_reward""
vote details (1)