开发者

Is it possible to execute a database insert from the CentOS command-line?

开发者 https://www.devze.com 2023-02-15 02:15 出处:网络
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.

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');"
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号