>mysql 中没有数据库

>mysql 中没有数据库

在我将我的 ubuntu 从 14.4 升级到 Digital Ocean 上的 16.4 后,当我运行命令 show databases 时,我的数据库没有显示;它只显示以下内容:information_schema test

如果我去 /var/lib/mysql,我的数据库文件就在那里。

我不确定 /etc/mysql/my.cnf 文件是否有什么问题,我是否需要向其中添加信息,目前它看起来像这样:

#
# The MySQL database server configuration file.
#
# You can copy this to one of:
# - "/etc/mysql/my.cnf" to set global options,
# - "~/.my.cnf" to set user-specific options.
# 
# One can use all long options that the program supports.
# Run program with --help to get a list of available options and with
# --print-defaults to see which it would actually understand and use.
#
# For explanations see
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html

#
# * IMPORTANT: Additional settings that can override those from this file!
#   The files must end with '.cnf', otherwise they'll be ignored.
#

!includedir /etc/mysql/conf.d/
!includedir /etc/mysql/mysql.conf.d/

如果我运行下一个命令,我会得到这个输出

mysql> SHOW DATABASES;
+--------------------+
| Database           |
+--------------------+
| information_schema |
+--------------------+
1 row in set (0.00 sec)

mysql> SELECT USER(),CURRENT_USER();
+----------------+----------------+
| USER()         | CURRENT_USER() |
+----------------+----------------+
| root@localhost | root@localhost |
+----------------+----------------+
1 row in set (0.00 sec)

mysql> SHOW GRANTS;
+--------------------------------------------------------------+
| Grants for root@localhost                                    |
+--------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'root'@'localhost'                     |
| GRANT PROXY ON ''@'' TO 'root'@'localhost' WITH GRANT OPTION |
+--------------------------------------------------------------+
2 rows in set (0.00 sec)

答案1

好的,问题出在用户 root 权限上,我只需停止 MySQL 服务器,然后使用以下命令重新启动它:

sudo /usr/sbin/mysqld --skip-grant-tables --skip-networking &

之后我使用mysql客户

shell> mysql

然后我授予 root 用户所有权限

GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION;
FLUSH PRIVILEGES;

之后,我停止服务器并正常重新启动它,现在当我调用SHOW DATABASES;它时列出了我所有的数据库,并且我可以创建新的数据库。

感谢大家的帮助。

相关内容