MySQL是如何创建并选择数据库的
admin
2023-05-23 03:43:06
0

本文主要给大家介绍MySQL是如何创建并选择数据库的,文章内容都是笔者用心摘选和编辑的,具有一定的针对性,对大家的参考意义还是比较大的,下面跟笔者一起了解下MySQL是如何创建并选择数据库的吧。

3.3.1 Creating and Selecting a Database

3.3.1 创建 选择数据库

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 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.)

在Unix下,数据库名称是区分大小写的(不像SQL关键字),所以你必须总是指到你的数据库 menagerie,而不是 Menagerie,MENAGERIE或一些其他变种。表名也是如此。(windows 下,大小写不敏感,你最好使用与建表或者建库时相同的拼写。)

Note

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 6.2, “The MySQL Access Privilege System”.

注意

如果您收到 ERROR 1044 (42000): Access denied for user 'micah'@'localhost' to database 'menagerie',这意味着您的用户帐户没有锁必须的权限。请与管理员讨论,或参见第6.2节“MySQL访问特权系统”。

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. 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 会话时都必须选择它。您可以通过发出USE如示例中所示的语句来执行此操作 。或者,您可以在调用mysql时在命令行中选择数据库。只需在您可能需要提供的任何连接参数之后指定其名称。例如:


shell> mysql -h host -u user -p menagerie
Enter password: ********

Important

menagerie 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 -pmypassword, not as -p mypassword). 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.

重要

在刚刚的命令中 menagerie不是你的密码。如果要在-p选项之后的命令行中提供密码 ,你必须在-p选项后不插入空格马上输入(例如, -pmypassword 不是-p mypassword)。但是,不建议将密码放在命令行上,因为这样做会使其被登录到您的计算机上的其他用户窥探。

Note

You can see at any time which database is currently selected using SELECT DATABASE().

看完以上关于MySQL是如何创建并选择数据库的,很多读者朋友肯定多少有一定的了解,如需获取更多的行业知识信息 ,可以持续关注我们的行业资讯栏目的。

相关内容

热门资讯

电脑pin什么意思 电脑pin... 电脑pin是使用比较多的一种身份识别技术,即随机生成但是可验证的一组身份验证识别序列。它在windo...
小鸭洗衣迷你脱水桷电机响不转怎... 1、洗衣机在洗衣服时,如果电机有嗡嗡声但不转,就有可能是启动电容器的问题。如果电机没有一点声音,就可...
油烟机电机不转的原因 油烟机是常见的厨房电器之一,一般用于排除厨房的烟雾和异味,对保持厨房环境干净卫生非常重要。但是偶尔出...
油烟机一直滴滴响打不开怎么回事 油烟机一直滴滴响打不开的原因有几种:1、油烟机的烟雾感应器出现故障,误识油烟为起火的烟雾导致滴滴响打...
打印机共享怎么连接第二台电脑 如今,打印机已经成为我们工作和生活中不可或缺的设备之一。而打印机共享则是在一个办公环境中非常常见的操...
男子忌日宴疑因幻听行凶致2死1... 8月4日,山东聊城“疑因幻听行凶致邻居2死1伤”案伤者刘现为向@百姓关注 记者还原事发经过。
韩国检察官“只手遮天”的时代结... 韩国政府今天召开由总统李在明主持的国务会议,通过《刑事诉讼法》修正案,全面废除检察官直接侦查及补充侦...
天津发文推进带薪休假落地:摒弃... 澎湃新闻记者 钟煜豪“摒弃‘爱岗敬业不能休’的错误认识,清理‘攀比内卷不愿休’的职场环境,消除‘业绩...
摩洛哥非法移民讲述:为何突然越... 亚辛(Yassine)今年24岁,来自摩洛哥北部城市得土安。7月30日,天气晴朗,最高温度30摄氏度...
原创 成... 深夜,手机屏幕的光映着很多人的脸。只要轻轻一点,就能看到大量成人内容,免费、方便、不用露脸——看起来...