I am writing a script to perform tasks between two MySql databases on the same server, i.e truncate tables on one db and import table rows from another db to this one.
The user who is doing the tasks has full permissions on both databases.
How do I connect to both databases from the command line?
Thanks in advance for any help.
You can use
mysqlcommand line utility with the proper parameters:Here
rootis the privileged user andyour_dbis the database which is in use by default. You can always switch between databases by typinguse another_dbcommand frommysqlconsole.Also note that you do not have to select dabase (
use db_name) in order to execute query on it. You can for example write a query something like this: