如果管理员在设置您的权限时为您创建了数据库,您就可以开始使用它。否则,您需要自己创建它:If the administrator creates your database for you when setting up your permissions, you can begin using it. Otherwise, you need to create it yourself:
mysql> CREATE DATABASE menagerie;
在 Unix 下,数据库名称是区分大小写的(不像 SQL 关键字),所以你必须始终将数据库称为 menagerie,而不是 Menagerie、MENAGERIE 或其他变体。表名也是如此。(在 Windows 下,这个限制不适用,尽管在给定查询中必须保持数据库和表的字母大小写一致。然而,由于各种原因,推荐的最佳做法是始终使用创建数据库时使用的相同字母大小写。)Under Unix, database names are case-sensitive (unlike SQL
keywords), so you must always refer to your database as
menagerie, not as
Menagerie, MENAGERIE, or
some other variant. This is also true for table names. (Under
Windows, this restriction does not apply, although you must
refer to databases and tables using the same lettercase
throughout a given query. However, for a variety of reasons, the
recommended best practice is always to use the same lettercase
that was used when the database was created.)
如果在尝试创建数据库时收到类似 ERROR 1044 (42000): Access denied for user 'micah'@'localhost' to database 'menagerie' 的错误,这意味着您的用户帐户没有执行此操作所需的权限。请与管理员讨论或参见 第 8.2 节,“访问控制和帐户管理”。If you get an error such as ERROR 1044 (42000): Access denied for user 'micah'@'localhost' to database 'menagerie' when attempting to create a database, this means that your user account does not have the necessary privileges to do so. Discuss this with the administrator or see Section 8.2, “Access Control and Account Management”.
创建数据库不会自动将其选为使用数据库;您必须显式执行此操作。要将 menagerie 设置为当前数据库,请使用以下语句:Creating a database does not select it for use; you must do that
explicitly. To make menagerie the current
database, use this statement:
mysql> USE menagerie
Database changed
您的数据库只需要创建一次,但每次开始 mysql 会话时,必须选择它以供使用。您可以通过发出如示例所示的 USE 语句来完成此操作。或者,您也可以在调用 mysql 时,在命令行中选择数据库。只需在您可能需要提供的任何连接参数之后指定其名称。例如:Your database needs to be created only once, but you must select
it for use each time you begin a mysql
session. You can do this by issuing a
USE statement as shown in the
example. Alternatively, you can select the database on the
command line when you invoke mysql. Just
specify its name after any connection parameters that you might
need to provide. For example:
$>mysql -hEnter password:host-uuser-p menagerie********
menagerie 在上面显示的命令中 不是 你的密码。如果你想在命令行中通过 -p 选项提供你的密码,你必须不留空格(例如,使用 -p,而不是 password-p )。然而,不推荐在命令行中输入密码,因为这样会使其他在你的机器上登录的用户能够窥探到你的密码。passwordmenagerie in the command just shown is
not your password. If you
want to supply your password on the command line after the
-p option, you must do so with no
intervening space (for example, as
-p, not
as password-p ).
However, putting your password on the command line is not
recommended, because doing so exposes it to snooping by other
users logged in on your machine.password
你可以随时使用 SELECT DATABASE() 查看当前选择的是哪个数据库。You can see at any time which database is currently selected
using SELECT
DATABASE().