select * from schemata where schema_name='databasename';
如果是5以上 sELECT table_name, table_type, engine FROM information_schema.tables WHERE table_schema = 'zz' and table_name='tt'
showtables这个命令可以显示所有的数据库,然后可以比较一下有没有想要的数据库的名字
select * from information_schema.SCHEMATA; 网上说还有一个设么 mysql——select -db这个函数可以判断
CREATE [TEMPORARY] TABLE [IF NOT EXISTS] tbl_name [(create_definition,...)] [table_options] [select_statement]
看那个 “IF NOT EXISTS”
当然你需要有创建表的权限,否则怎样都报错 Top 5 楼faisun(暖阳)回复于 2006-03-31 13:05:42 得分 10if(!@mySQL_db_select($dbname)){ //建立数据库
}但是我测试发现失败 mysql> mySQL_db_select(); ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'mySQL_db_select()' at line 1 mysql> mySQL_db_select(aa); ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'mySQL_db_select(aa)' at line 1 mysql> mySQL_db_select("aa"); ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'mySQL_db_select("aa")' at line 1
SELECT * FROM information_schema.SCHEMATA where SCHEMA_NAME='aa';
select * from information_schema.schemata where schema_name='dbname'; 在程序中判断有没有数据返回就可以判断数据库是否存在。
sELECT table_name, table_type, engine
FROM information_schema.tables
WHERE table_schema = 'zz' and table_name='tt'
网上说还有一个设么 mysql——select -db这个函数可以判断
[(create_definition,...)]
[table_options] [select_statement]
看那个 “IF NOT EXISTS”
当然你需要有创建表的权限,否则怎样都报错
Top
5 楼faisun(暖阳)回复于 2006-03-31 13:05:42 得分 10if(!@mySQL_db_select($dbname)){
//建立数据库
}但是我测试发现失败
mysql> mySQL_db_select();
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'mySQL_db_select()' at line 1
mysql> mySQL_db_select(aa);
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'mySQL_db_select(aa)' at line 1
mysql> mySQL_db_select("aa");
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'mySQL_db_select("aa")' at line 1
在程序中判断有没有数据返回就可以判断数据库是否存在。