如何使用 Bash 脚本检查 MySQL 中的列是否存在。
我想编写一个 if 语句并创建该列(如果该列不存在)。例如:
col="thecolumn"
if [[ !col ]]; then
db="use myDB; alter table myTable add column name varchar(30) not null;"
mysql -u root -p123456aB "$db"
fi
最佳答案
所有的表结构信息都在information_schema中,可以查询。
https://dev.mysql.com/doc/refman/5.0/en/information-schema.html
关于mysql - 如何检查MySQL中的列是否存在?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32011715/