0

I'm using some bash code which I got off another post on here

#!/bin/sh

users=$(mysql --user=user --password=password --database=$db -h _IP ADDRESS) -s --       execute="select$ users from db limit 1;"|cut -f1)

echo "$users"

The database is DB and the table is users basically I want to be able to get a user count from the table but when I run the script I get

ERROR 1049 (42000): Unknown database 'execute=select users from db limit 1;'

any idea what i'm doing wrong or a better way of doing it? if I do

select * form users;

on the mysql server itself it returns 12 rows in set (0.00 sec) 12 being the number of users, so I just want my script to query the user table on database DB and return the number of rows ie 12.

3 Answers 3

1
users_count=$(
    mysql --user user_name --password=password  -h x.x.x.x <<EOF | tail -n 1
    select count(1) from mysql.user;
EOF
)
Sign up to request clarification or add additional context in comments.

Comments

0

it seems that the order of your params is wrong...

MYSQL is telling you that 'execute=select users from db limit 1;' is in the position of the database parameter.

Try something like this:

mysql --user user_name --password=password -e 'select users from db_schema.table limit 1;'

Comments

0

Simply try this:

mysql -u username --password=password -h hostname database_name -e 'select count(1) from table limit 1;'

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.