Issue
I want to create a new database access user, but I need to pass the entire command on the same line:
mysql -u root; CREATE USER 'test' @ '%' IDENTIFIED BY '123456'; GRANT ALL PRIVILEGES ON *. * TO 'test' @ '%'; FLUSH PRIVILEGES;
How do I make it work?
Solution
You can use the echo command like:
echo "CREATE USER 'test' @ '%' IDENTIFIED BY '123456'; GRANT ALL PRIVILEGES ON *. * TO 'test' @ '%'; FLUSH PRIVILEGES; " | mysql -u root
Or use the -e
option:
mysql -u root -e "CREATE USER 'test' @ '%' IDENTIFIED BY '123456'; GRANT ALL PRIVILEGES ON *. * TO 'test' @ '%'; FLUSH PRIVILEGES;"
Answered By - Bernd Buffen