I'm working on a python script to setup servers quickly and it basically has a list of commands I want to execute on the linux commandline.
I can install all the software I need but not sure how to create a mysql user solely via command line? I can I can go into the mysql shell and do it but is there a way to do it solely from the linux shell(once the user is created I can do all the database setup remotely with a python script)?
You do it with the same query you'd use in the client, but execute it on the command line with the -e
flag:
mysql -uroot -prootpw -e "GRANT ALL PRIVILEGES ON dbname.* TO username@hostname IDENTIFIED BY 'userpassword'"
Or pipe in the command
echo "GRANT ALL PRIVILEGES ON dbname.* TO username@hostname IDENTIFIED BY 'userpassword'" | mysql -uroot -prootpw
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With