MySql: does a database exist?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • HockeyFan
    New Member
    • Dec 2005
    • 2

    #1

    MySql: does a database exist?

    I know how to do this in SQL Server, but need the equivalent query to determine if a database exists in MySql.

    In SQL Server, the query is:
    Select 1 From Information_Sch ema.Schemata
    Where Catalog_Name='w hatevermydataba seisnamed'

    I'm not that familiar with MySQL, but betting the statement is different.
  • Niheel
    Recognized Expert Moderator Top Contributor
    • Jul 2005
    • 2433

    #2
    Can you explain the query in english. I don't understand Information_Sch ema.Schemata. Is that the name of a table? Is Catalog_Name, the column?
    niheel @ bytes

    Comment

    • HockeyFan
      New Member
      • Dec 2005
      • 2

      #3
      Information_Sch ema.Schemata is actually a view
      Information_Sch ema is the owner and Schemata is the view
      Catalog_name is the database name
      This is a canned view in SQLserver.

      It is the following code:
      Code:
      select
      	db.name						as CATALOG_NAME
      	,USER_NAME()				as SCHEMA_NAME
      	,USER_NAME()				as SCHEMA_OWNER
      	,convert(sysname, NULL)		as DEFAULT_CHARACTER_SET_CATALOG
      	,convert(sysname, NULL)		as DEFAULT_CHARACTER_SET_SCHEMA
      	,a_cha.name					as DEFAULT_CHARACTER_SET_NAME
      FROM
      	master.dbo.sysdatabases 		db,
      	master.dbo.syscharsets		a_cha --charset/1001, not sortorder.
      WHERE
      	a_cha.type = 1001 --- type is charset
      	AND a_cha.id = convert(tinyint, DatabasePropertyEx(db.name, 'sqlcharset'))

      Comment

      Working...