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;
Under Unix, database names are case-sensitive (unlike SQL keywords), so you must always refer to your database as 在Unix下,数据库名称区分大小写(与SQL关键字不同),因此必须始终将数据库称为menagerie
, not as Menagerie
, MENAGERIE
, or some other variant. menagerie
,而不是Menagerie
、MENAGERIE
或其他变体。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. (在Windows下,此限制不适用,尽管您必须在整个给定查询中使用相同的字母大小写引用数据库和表。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.)但是,由于各种原因,建议的最佳做法是始终使用创建数据库时使用的同一个字母大小写。)
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. 如果您在尝试创建数据库时遇到错误,如ERROR 1044 (42000): Access denied for user 'micah'@'localhost' to database 'menagerie',这意味着您的用户帐户没有执行此操作所需的权限。Discuss this with the administrator or see Section 6.2, “Access Control and Account Management”.与管理员讨论此问题,或参阅第6.2节,“访问控制和帐户管理”。
Creating a database does not select it for use; you must do that explicitly. 创建数据库时不会选择要使用的数据库;你必须明确地这样做。To make 要使menagerie
the current database, use this statement:menagerie
成为当前数据库,请使用以下语句:
mysql> USE menagerie
Database changed
Your database needs to be created only once, but you must select it for use each time you begin a mysql session. 您的数据库只需要创建一次,但每次开始mysql会话时都必须选择使用它。You can do this by issuing a 您可以通过发出一个USE
statement as shown in the example. USE
语句来实现这一点,如示例所示。Alternatively, you can select the database on the command line when you invoke mysql. 或者,您可以在调用mysql时在命令行上选择数据库。Just specify its name after any connection parameters that you might need to provide. 只需在您可能需要提供的任何连接参数之后指定其名称。For example:例如:
shell>mysql -h
Enter password:host
-uuser
-p menagerie********
刚才显示的命令中的menagerie
in the command just shown is not your password. menagerie
不是您的密码。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
). password
-p
选项之后提供密码,则必须在没有中间空格的情况下提供(例如,-p
,而不是password
-p
)。password
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.但是,不建议将密码放在命令行上,因为这样做会使登录到您机器上的其他用户窥探密码。
You can see at any time which database is currently selected using 您可以随时使用SELECT
DATABASE()
.SELECT DATABASE()
查看当前选择的数据库。