Is it possible to execute a database insert from the CentOS command-line?
Normally if you wanted to execute a MySQL command you would just open up the MySQL command-line, but I'm trying to execute the command via Windows command-line.
Just got this got this code working on the Windows command-line, but also need a port of it for CentOS:
echo INSERT INTO InsertTableName (Column001, Column002) VALUES('Value001', 'Value002'); | mysql -u InsertUserName -pInsertPassword InsertDatabaseName
Que开发者_Go百科stion, feedback, request -- just comment, thanks!!
System Setup:
* MySQL: 5.1.53-community MySQL Community Server (GPL)
* CentOS: 5.5 (64-bit)
You just need to quote the insert statement:
echo "INSERT INTO InsertTableName (Column001, Column002) VALUES('Value001', 'Value002');" | mysql -u InsertUserName -pInsertPassword InsertDatabaseName
You can also do it this way (as from the mysql man page; I tested this):
mysql -u InsertUserName -pInsertPassword InsertDatabaseName -e "INSERT INTO InsertTableName (Column001, Column002) VALUES('Value001', 'Value002');"
精彩评论