数据目录初始化并启动服务器后,执行一些简单的测试以确保它效果令人满意。本节假设您当前的位置是 MySQL 安装目录,并且它有一个 bin 子目录,其中包含此处使用的 MySQL 程序。如果情况并非如此,请相应地调整命令路径名称。After the data directory is initialized and you have started the
server, perform some simple tests to make sure that it works
satisfactorily. This section assumes that your current location is
the MySQL installation directory and that it has a
bin subdirectory containing the MySQL
programs used here. If that is not true, adjust the command path
names accordingly.
或者,将 bin 目录添加到 PATH 环境变量设置中。这使您的 shell(命令解释器)能够正确找到 MySQL 程序,以便您可以通过仅键入程序名称而不是路径名称来运行程序。请参阅第 6.2.9 节“设置环境变量”。Alternatively, add the bin directory to your
PATH environment variable setting. That enables
your shell (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 6.2.9, “Setting Environment Variables”.
使用 mysqladmin 验证服务器正在运行。以下命令提供简单的测试来检查服务器是否已启动并响应连接:Use mysqladmin to verify that the server is running. The following commands provide simple tests to check whether the server is up and responding to connections:
$>bin/mysqladmin version$>bin/mysqladmin variables
如果无法连接到服务器,请指定 -u
root 选项以 root 身份进行连接。如果您已经为 root 帐户分配了密码,则还需要在命令行上指定 -p 并在出现提示时输入密码。例如:If you cannot connect to the server, specify a -u
root option to connect as root. If you
have assigned a password for the root account
already, you'll also need to specify -p on the
command line and enter the password when prompted. For example:
$>bin/mysqladmin -u root -p versionEnter password:(enter root password here)
mysqladmin version 的输出根据您的平台和 MySQL 版本略有不同,但应该与此处显示的类似:The output from mysqladmin version varies slightly depending on your platform and version of MySQL, but should be similar to that shown here:
$> bin/mysqladmin version
mysqladmin Ver 14.12 Distrib 8.4.9, for pc-linux-gnu on i686
...
Server version 8.4.9
Protocol version 10
Connection Localhost via UNIX socket
UNIX socket /var/lib/mysql/mysql.sock
Uptime: 14 days 5 hours 5 min 21 sec
Threads: 1 Questions: 366 Slow queries: 0
Opens: 0 Flush tables: 1 Open tables: 19
Queries per second avg: 0.000
查看您还可以使用 mysqladmin,使用 --help 选项调用它。To see what else you can do with mysqladmin,
invoke it with the --help
option.
选项指定文件位置-p验证您是否可以关闭服务器(如果账号已有密码,请包含root选项):Verify that you can shut down the server (include a
-p option if the root account
has a password already):
$> bin/mysqladmin -u root shutdown
验证您是否可以再次启动服务器。为此,请使用 mysqld_safe 或调用 mysqld 直接。例如:Verify that you can start the server again. Do this by using mysqld_safe or by invoking mysqld directly. For example:
$> bin/mysqld_safe --user=mysql &
如果 mysqld_safe 失败,请参阅部分 2.9.2.1,“解决启动 MySQL 服务器的问题”。If mysqld_safe fails, see Section 2.9.2.1, “Troubleshooting Problems Starting the MySQL Server”.
运行一些简单的测试来验证您是否可以从服务器检索信息。输出应与此处显示的类似。Run some simple tests to verify that you can retrieve information from the server. The output should be similar to that shown here.
使用 mysqlshow 查看存在哪些数据库:Use mysqlshow to see what databases exist:
$> bin/mysqlshow
+--------------------+
| Databases |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
已安装数据库的列表可能有所不同,但始终至少包含 mysql 和 information_schema.The list of installed databases may vary, but always includes at
least mysql and
information_schema.
如果指定数据库名称,mysqlshow 显示数据库中的表列表:If you specify a database name, mysqlshow displays a list of the tables within the database:
$> 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 |
+---------------------------+
使用 mysql 程序从 mysql 架构中的表中选择信息:Use the mysql program to select information
from a table in the mysql schema:
$> bin/mysql -e "SELECT User, Host, plugin FROM mysql.user" mysql
+------+-----------+-----------------------+
| User | Host | plugin |
+------+-----------+-----------------------+
| root | localhost | caching_sha2_password |
+------+-----------+-----------------------+
此时,您的服务器正在运行,您可以访问它。如果您尚未为初始帐户分配密码,要加强安全性,请按照第 2.9.4 节“保护初始 MySQL 帐户”中的说明进行操作。At this point, your server is running and you can access it. To tighten security if you have not yet assigned a password to the initial account, follow the instructions in Section 2.9.4, “Securing the Initial MySQL Account”.
有关mysql、mysqladmin 和 mysqlshow,请参阅第 6.5.1 节“mysql — MySQL 命令行客户端”、第 6.5.2 节, “mysqladmin — MySQL 服务器管理程序”,以及第 6.5.6 节“mysqlshow — 显示数据库、表和列信息”。For more information about mysql, mysqladmin, and mysqlshow, see Section 6.5.1, “mysql — The MySQL Command-Line Client”, Section 6.5.2, “mysqladmin — A MySQL Server Administration Program”, and Section 6.5.6, “mysqlshow — Display Database, Table, and Column Information”.