GUI tools exist that perform most of the tasks described in this section, including:GUI工具可以执行本节中描述的大部分任务,包括:
MySQL Installer: Used to install and upgrade MySQL products.:用于安装和升级MySQL产品。
MySQL Workbench: Manages the MySQL server and edits SQL statements.:管理MySQL服务器并编辑SQL语句。
If necessary, initialize the data directory and create the MySQL grant tables. Windows installation operations performed by MySQL Installer initialize the data directory automatically. 如有必要,初始化数据目录并创建MySQL授权表。MySQL安装程序执行的Windows安装操作会自动初始化数据目录。For installation from a ZIP Archive package, initialize the data directory as described at Section 2.10.1, “Initializing the Data Directory”.要从ZIP Archive软件包进行安装,请按照第2.10.1节,“初始化数据目录”中的说明初始化数据目录。
Regarding passwords, if you installed MySQL using the MySQL Installer, you may have already assigned a password to the initial 关于密码,如果您使用MySQL安装程序安装MySQL,您可能已经为初始root
account. (See Section 2.3.3, “MySQL Installer for Windows”.) root
帐户分配了密码。(请参阅第2.3.3节,“适用于Windows的MySQL安装程序”。)Otherwise, use the password-assignment procedure given in Section 2.10.4, “Securing the Initial MySQL Account”.否则,请使用第2.10.4节,“保护初始MySQL帐户”中给出的密码分配程序。
Before assigning a password, you might want to try running some client programs to make sure that you can connect to the server and that it is operating properly. 在分配密码之前,您可能需要尝试运行一些客户端程序,以确保您可以连接到服务器,并且服务器运行正常。Make sure that the server is running (see Section 2.3.4.5, “Starting the Server for the First Time”). 确保服务器正在运行(请参阅第2.3.4.5节,“首次启动服务器”)。You can also set up a MySQL service that runs automatically when Windows starts (see Section 2.3.4.8, “Starting MySQL as a Windows Service”).您还可以设置一个MySQL服务,该服务在Windows启动时自动运行(请参阅第2.3.4.8节,“将MySQL作为Windows服务启动”)。
These instructions assume that your current location is the MySQL installation directory and that it has a 这些说明假设您的当前位置是MySQL安装目录,并且它有一个包含此处使用的MySQL程序的bin
subdirectory containing the MySQL programs used here. If that is not true, adjust the command path names accordingly.bin
子目录。如果不是这样,请相应地调整命令路径名称。
If you installed MySQL using MySQL Installer (see Section 2.3.3, “MySQL Installer for Windows”), the default installation directory is 如果您使用MySQL安装程序安装MySQL(请参阅第2.3.3节,“适用于Windows的MySQL安装程序”),则默认安装目录为C:\Program Files\MySQL\MySQL Server 8.0
:C:\Program Files\MySQL\MySQL Server 8.0
:
C:\> cd "C:\Program Files\MySQL\MySQL Server 8.0"
A common installation location for installation from a ZIP archive is 从ZIP档案进行安装的常见安装位置是C:\mysql
:C:\mysql
:
C:\> cd C:\mysql
Alternatively, add the 或者,将bin
directory to your PATH
environment variable setting. bin
目录添加到PATH环境变量设置中。That enables your command interpreter to find MySQL programs properly, so that you can run a program by typing only its name, not its path name. See Section 2.3.4.7, “Customizing the PATH for MySQL Tools”.这使您的命令解释器能够正确地找到MySQL程序,这样您就可以通过只键入程序名称而不是路径名称来运行程序。请参阅第2.3.4.7节,“自定义MySQL工具的路径”。
With the server running, issue the following commands to verify that you can retrieve information from the server. The output should be similar to that shown here.在服务器运行的情况下,发出以下命令以验证是否可以从服务器检索信息。输出应该与此处显示的类似。
Use mysqlshow to see what databases exist:使用mysqlshow查看存在哪些数据库:
C:\> bin\mysqlshow
+--------------------+
| Databases |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
The list of installed databases may vary, but always includes at least 已安装数据库的列表可能有所不同,但始终至少包括mysql
and information_schema
.mysql
和information_schema
。
The preceding command (and commands for other MySQL programs such as mysql) may not work if the correct MySQL account does not exist. 如果不存在正确的MySQL帐户,则前面的命令(以及其他MySQL程序(如mysql)的命令)可能不起作用。For example, the program may fail with an error, or you may not be able to view all databases. 例如,程序可能会因错误而失败,或者您可能无法查看所有数据库。If you install MySQL using MySQL Installer, the 如果使用MySQL安装程序安装MySQL,则会使用您提供的密码自动创建root
user is created automatically with the password you supplied. root
用户。In this case, you should use the 在这种情况下,您应该使用-u root
and -p
options. -u root
和-p
选项。(You must use those options if you have already secured the initial MySQL accounts.) (如果您已经保护了初始MySQL帐户,则必须使用这些选项。)With 使用-p
, the client program prompts for the root
password. For example:-p
,客户端程序会提示输入root
密码。例如
C:\>bin\mysqlshow -u root -p
Enter password:(enter root password here)
+--------------------+ | Databases | +--------------------+ | information_schema | | mysql | | performance_schema | | sys | +--------------------+
If you specify a database name, mysqlshow displays a list of the tables within the database:如果指定数据库名称,mysqlshow将显示数据库中表的列表:
C:\> bin\mysqlshow mysql
Database: mysql
+---------------------------+
| Tables |
+---------------------------+
| columns_priv |
| component |
| db |
| default_roles |
| engine_cost |
| func |
| general_log |
| global_grants |
| gtid_executed |
| help_category |
| help_keyword |
| help_relation |
| help_topic |
| innodb_index_stats |
| innodb_table_stats |
| ndb_binlog_index |
| password_history |
| plugin |
| procs_priv |
| proxies_priv |
| role_edges |
| server_cost |
| servers |
| slave_master_info |
| slave_relay_log_info |
| slave_worker_info |
| slow_log |
| tables_priv |
| time_zone |
| time_zone_leap_second |
| time_zone_name |
| time_zone_transition |
| time_zone_transition_type |
| user |
+---------------------------+
Use the mysql program to select information from a table in the 使用mysql程序从mysql
database:mysql
数据库中的表中选择信息:
C:\> bin\mysql -e "SELECT User, Host, plugin FROM mysql.user" mysql
+------+-----------+-----------------------+
| User | Host | plugin |
+------+-----------+-----------------------+
| root | localhost | caching_sha2_password |
+------+-----------+-----------------------+
For more information about mysql and mysqlshow, see Section 4.5.1, “mysql — The MySQL Command-Line Client”, and Section 4.5.7, “mysqlshow — Display Database, Table, and Column Information”.有关mysql和mysqlshow的更多信息,请参阅第4.5.1节,“mysql-mysql命令行客户端”和第4.5.7节,“mysqlshow-显示数据库、表和列信息”。