mysql - 缺少数据库

标签 mysql debian

当我使用 usr/sbin/mysqld --skip-grant-tables --user=mysql & (debian 7) 启动 mysql 服务器并登录到 mysql 时,显示数据库查询结果是这样的:

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| UDA                |
| guikuzi            |
| hotel_guregas      |
| merkaklub          |
| mysql              |
| performance_schema |
| phpmyadmin         |
| superlinea         |
| test               |
+--------------------+
10 rows in set (0.00 sec)

这是一个信息:

mysql> SHOW VARIABLES WHERE Variable_Name LIKE "%dir";
+---------------------------+----------------------------+
| Variable_name             | Value                      |
+---------------------------+----------------------------+
| basedir                   | /usr                       |
| character_sets_dir        | /usr/share/mysql/charsets/ |
| datadir                   | /var/lib/mysql/            |
| innodb_data_home_dir      |                            |
| innodb_log_group_home_dir | ./                         |
| lc_messages_dir           | /usr/share/mysql/          |
| plugin_dir                | /usr/lib/mysql/plugin/     |
| slave_load_tmpdir         | /tmp                       |
| tmpdir                    | /tmp                       |
+---------------------------+----------------------------+
9 rows in set (0.00 sec)

之后,如果我停止这个 mysql 服务器并通过/etc/init.d/mysql start 启动,我会得到以下结果:

# /etc/init.d/mysql start                                                                                                    3 ↵
[ ok ] Starting mysql (via systemctl): mysql.service.
[root@debian:~]
# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 47
Server version: 5.5.35-0+wheezy1 (Debian)

Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| test               |
+--------------------+
2 rows in set (0.01 sec)

mysql> SHOW VARIABLES WHERE Variable_Name LIKE "%dir";
+---------------------------+----------------------------+
| Variable_name             | Value                      |
+---------------------------+----------------------------+
| basedir                   | /usr                       |
| character_sets_dir        | /usr/share/mysql/charsets/ |
| datadir                   | /var/lib/mysql/            |
| innodb_data_home_dir      |                            |
| innodb_log_group_home_dir | ./                         |
| lc_messages_dir           | /usr/share/mysql/          |
| plugin_dir                | /usr/lib/mysql/plugin/     |
| slave_load_tmpdir         | /tmp                       |
| tmpdir                    | /tmp                       |
+---------------------------+----------------------------+

发生了什么事?我启动了安全模式,因为我必须重置 root 密码,但它也不起作用。现在我的服务器处于安全模式并且它正在工作,但我认为这不是最好的方法

有什么帮助或线索吗?

提前致谢

最佳答案

根据您的帖子,很明显,在第一个实例中,您启动 MySQL 服务器时没有打开其权限系统(--skip-grant-tables)。此选项关闭MySQL的内部权限系统,该系统允许任何人不受限制地访问所有数据库。因此,当您通过客户端连接到数据库服务器时,您绕过了任何权限检查,并且可以看到所有数据库。

--skip-grant-tables This option causes the server to start without using the privilege system at all, which gives anyone with access to the server unrestricted access to all databases. "

参见related MySQL docs了解更多信息。

在第二个实例中,您正常启动MySQL,权限系统已打开,这意味着连接用户可以执行基于其身份允许的操作。

The MySQL privilege system ensures that all users may perform only the operations permitted to them. As a user, when you connect to a MySQL server, your identity is determined by the host from which you connect and the user name you specify. When you issue requests after connecting, the system grants privileges according to your identity and what you want to do.

查看更多信息related MySQL docs .

另外,请查看 this post 的答案如何查看哪个用户已通过当前 MySQL session 的身份验证。

更简单,只需键入“\s”即可在MySQL客户端提示符中查看基本状态信息。例如:

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 38
Server version: 5.5.35-0ubuntu0.13.10.2 (Ubuntu)

Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> \s
--------------
mysql  Ver 14.14 Distrib 5.5.35, for debian-linux-gnu (x86_64) using readline 6.2

Connection id:          37
Current database:
Current user:           ubuntu@localhost
(...)

希望以上内容对您有所帮助。我试图向您展示如何解决此类情况的基本提示!

关于mysql - 缺少数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22323660/

相关文章:

docker - 如何在Docker中的Jessie上安装RabbitMQ-server?

repository - 如何信任 apt 存储库 : Debian apt-get update error public key is not available: NO_PUBKEY <id>

mysql - HIVE如何限制组中的条目数

mysql - 未使用 SELECT 查询显示所有选定字段 - MySQL

mysql - 根据日期间隔用记录填充MYSQL表

debian - 如何恢复 ufw 命令?

python - 须藤 pip 列表: OpenSSL issue

mysql - 优化前 N 个查询

page=-1 时 PHP 分页 SQL 语法错误

php - Docker PHP7 CLI Debian Buster如何安装软件包php-imagick?