【问题标题】:Access denied to mysql database as root in rails app在rails应用程序中以root身份访问mysql数据库被拒绝
【发布时间】:2017-06-07 16:20:19
【问题描述】:

我正在使用 mysql 运行 rails 应用程序。 我的电脑以非正统的方式关闭,现在当我尝试运行rails s 时,我得到Access denied for user 'root'@'localhost' (using password: NO)

我的 database.yml 文件看起来像:

default: &default
  adapter: mysql2
  encoding: utf8
  pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
  username: root
  password:
  socket: /tmp/mysql.sock

development:
  <<: *default
  database: or_deco__site_development

当我尝试使用mysql start 以root 身份启动mysql 服务器时,我得到了这个跟踪:

 ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (61 "Connection refused")

when I try mysqld --user=mysql as why suggested on mysql website I get this trace:

2017-06-07 18:10:54 140735296021248 [Note] mysqld (mysqld 10.1.19-MariaDB) starting as process 1462 ...
2017-06-07 18:10:54 140735296021248 [Warning] Setting lower_case_table_names=2 because file system for /usr/local/var/mysql/ is case insensitive
2017-06-07 18:10:54 140735296021248 [Warning] One can only use the --user switch if running as root

2017-06-07 18:10:54 140735296021248 [Note] InnoDB: Using mutexes to ref count buffer pool pages
2017-06-07 18:10:54 140735296021248 [Note] InnoDB: The InnoDB memory heap is disabled
2017-06-07 18:10:54 140735296021248 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2017-06-07 18:10:54 140735296021248 [Note] InnoDB: GCC builtin __atomic_thread_fence() is used for memory barrier
2017-06-07 18:10:54 140735296021248 [Note] InnoDB: Compressed tables use zlib 1.2.5
2017-06-07 18:10:54 140735296021248 [Note] InnoDB: Using SSE crc32 instructions
2017-06-07 18:10:54 140735296021248 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2017-06-07 18:10:54 140735296021248 [Note] InnoDB: Completed initialization of buffer pool
2017-06-07 18:10:55 140735296021248 [Note] InnoDB: Highest supported file format is Barracuda.
2017-06-07 18:10:55 7fff7d53a300  InnoDB: Operating system error number 13 in a file operation.
InnoDB: The error means mysqld does not have the access rights to
InnoDB: the directory.
2017-06-07 18:10:55 140735296021248 [ERROR] InnoDB: Could not find a valid tablespace file for 'mysql/gtid_slave_pos'. See http://dev.mysql.com/doc/refman/5.6/en/innodb-troubleshooting-datadict.html for how to resolve the issue.
2017-06-07 18:10:55 140735296021248 [ERROR] InnoDB: Tablespace open failed for '"mysql"."gtid_slave_pos"', ignored.
2017-06-07 18:10:55 7fff7d53a300  InnoDB: Operating system error number 13 in a file operation.
InnoDB: The error means mysqld does not have the access rights to
InnoDB: the directory.
2017-06-07 18:10:55 140735296021248 [ERROR] InnoDB: Could not find a valid tablespace file for 'mysql/innodb_index_stats'. See http://dev.mysql.com/doc/refman/5.6/en/innodb-troubleshooting-datadict.html for how to resolve the issue.
2017-06-07 18:10:55 140735296021248 [ERROR] InnoDB: Tablespace open failed for '"mysql"."innodb_index_stats"', ignored.
2017-06-07 18:10:55 7fff7d53a300  InnoDB: Operating system error number 13 in a file operation.
InnoDB: The error means mysqld does not have the access rights to
InnoDB: the directory.
2017-06-07 18:10:55 140735296021248 [ERROR] InnoDB: Could not find a valid tablespace file for 'mysql/innodb_table_stats'. See http://dev.mysql.com/doc/refman/5.6/en/innodb-troubleshooting-datadict.html for how to resolve the issue.
2017-06-07 18:10:55 140735296021248 [ERROR] InnoDB: Tablespace open failed for '"mysql"."innodb_table_stats"', ignored.
2017-06-07 18:10:55 7fff7d53a300  InnoDB: Operating system error number 13 in a file operation.
InnoDB: The error means mysqld does not have the access rights to
InnoDB: the directory.
2017-06-07 18:10:55 140735296021248 [ERROR] InnoDB: Could not find a valid tablespace file for 'or_deco__site_development/active_admin_comments'. See http://dev.mysql.com/doc/refman/5.6/en/innodb-troubleshooting-datadict.html for how to resolve the issue.
2017-06-07 18:10:55 140735296021248 [ERROR] InnoDB: Tablespace open failed for '"or_deco__site_development"."active_admin_comments"', ignored.
2017-06-07 18:10:55 7fff7d53a300  InnoDB: Operating system error number 13 in a file operation.
InnoDB: The error means mysqld does not have the access rights to
InnoDB: the directory.
2017-06-07 18:10:55 140735296021248 [ERROR] InnoDB: Could not find a valid tablespace file for 'or_deco__site_development/administrators'. See http://dev.mysql.com/doc/refman/5.6/en/innodb-troubleshooting-datadict.html for how to resolve the issue.
2017-06-07 18:10:55 140735296021248 [ERROR] InnoDB: Tablespace open failed for '"or_deco__site_development"."administrators"', ignored.
2017-06-07 18:10:55 7fff7d53a300  InnoDB: Operating system error number 13 in a file operation.
InnoDB: The error means mysqld does not have the access rights to
InnoDB: the directory.
2017-06-07 18:10:55 140735296021248 [ERROR] InnoDB: Could not find a valid tablespace file for 'or_deco__site_development/ar_internal_metadata'. See http://dev.mysql.com/doc/refman/5.6/en/innodb-troubleshooting-datadict.html for how to resolve the issue.
2017-06-07 18:10:55 140735296021248 [ERROR] InnoDB: Tablespace open failed for '"or_deco__site_development"."ar_internal_metadata"', ignored.
2017-06-07 18:10:55 7fff7d53a300  InnoDB: Operating system error number 13 in a file operation.
InnoDB: The error means mysqld does not have the access rights to
InnoDB: the directory.
2017-06-07 18:10:55 140735296021248 [ERROR] InnoDB: Could not find a valid tablespace file for 'or_deco__site_development/carousels'. See http://dev.mysql.com/doc/refman/5.6/en/innodb-troubleshooting-datadict.html for how to resolve the issue.
2017-06-07 18:10:55 140735296021248 [ERROR] InnoDB: Tablespace open failed for '"or_deco__site_development"."carousels"', ignored.
2017-06-07 18:10:55 7fff7d53a300  InnoDB: Operating system error number 13 in a file operation.
InnoDB: The error means mysqld does not have the access rights to
InnoDB: the directory.
2017-06-07 18:10:55 140735296021248 [ERROR] InnoDB: Could not find a valid tablespace file for 'or_deco__site_development/contacts'. See http://dev.mysql.com/doc/refman/5.6/en/innodb-troubleshooting-datadict.html for how to resolve the issue.
2017-06-07 18:10:55 140735296021248 [ERROR] InnoDB: Tablespace open failed for '"or_deco__site_development"."contacts"', ignored.
2017-06-07 18:10:55 7fff7d53a300  InnoDB: Operating system error number 13 in a file operation.
InnoDB: The error means mysqld does not have the access rights to
InnoDB: the directory.
2017-06-07 18:10:55 140735296021248 [ERROR] InnoDB: Could not find a valid tablespace file for 'or_deco__site_development/headers'. See http://dev.mysql.com/doc/refman/5.6/en/innodb-troubleshooting-datadict.html for how to resolve the issue.
2017-06-07 18:10:55 140735296021248 [ERROR] InnoDB: Tablespace open failed for '"or_deco__site_development"."headers"', ignored.
2017-06-07 18:10:55 7fff7d53a300  InnoDB: Operating system error number 13 in a file operation.
InnoDB: The error means mysqld does not have the access rights to
InnoDB: the directory.
2017-06-07 18:10:55 140735296021248 [ERROR] InnoDB: Could not find a valid tablespace file for 'or_deco__site_development/images'. See http://dev.mysql.com/doc/refman/5.6/en/innodb-troubleshooting-datadict.html for how to resolve the issue.
2017-06-07 18:10:55 140735296021248 [ERROR] InnoDB: Tablespace open failed for '"or_deco__site_development"."images"', ignored.
2017-06-07 18:10:55 7fff7d53a300  InnoDB: Operating system error number 13 in a file operation.
InnoDB: The error means mysqld does not have the access rights to
InnoDB: the directory.
2017-06-07 18:10:55 140735296021248 [ERROR] InnoDB: Could not find a valid tablespace file for 'or_deco__site_development/schema_migrations'. See http://dev.mysql.com/doc/refman/5.6/en/innodb-troubleshooting-datadict.html for how to resolve the issue.
2017-06-07 18:10:55 140735296021248 [ERROR] InnoDB: Tablespace open failed for '"or_deco__site_development"."schema_migrations"', ignored.
2017-06-07 18:10:55 7fff7d53a300  InnoDB: Operating system error number 13 in a file operation.
InnoDB: The error means mysqld does not have the access rights to
InnoDB: the directory.
2017-06-07 18:10:55 140735296021248 [ERROR] InnoDB: Could not find a valid tablespace file for 'or_deco__site_development/sections'. See http://dev.mysql.com/doc/refman/5.6/en/innodb-troubleshooting-datadict.html for how to resolve the issue.
2017-06-07 18:10:55 140735296021248 [ERROR] InnoDB: Tablespace open failed for '"or_deco__site_development"."sections"', ignored.
2017-06-07 18:10:55 140735296021248 [Note] InnoDB: 128 rollback segment(s) are active.
2017-06-07 18:10:55 140735296021248 [Note] InnoDB: Waiting for purge to start
2017-06-07 18:10:55 4959924224 [ERROR] InnoDB: Failed to find tablespace for table '"mysql"."innodb_table_stats"' in the cache. Attempting to load the tablespace with space id 1.
2017-06-07 18:10:55 127a27000  InnoDB: Operating system error number 13 in a file operation.
InnoDB: The error means mysqld does not have the access rights to
InnoDB: the directory.
2017-06-07 18:10:55 4959924224 [ERROR] InnoDB: Could not find a valid tablespace file for 'mysql/innodb_table_stats'. See http://dev.mysql.com/doc/refman/5.6/en/innodb-troubleshooting-datadict.html for how to resolve the issue.
2017-06-07 18:10:55 4959924224 [ERROR] InnoDB: Failed to find tablespace for table '"mysql"."innodb_index_stats"' in the cache. Attempting to load the tablespace with space id 2.
2017-06-07 18:10:55 127a27000  InnoDB: Operating system error number 13 in a file operation.
InnoDB: The error means mysqld does not have the access rights to
InnoDB: the directory.
2017-06-07 18:10:55 4959924224 [ERROR] InnoDB: Could not find a valid tablespace file for 'mysql/innodb_index_stats'. See http://dev.mysql.com/doc/refman/5.6/en/innodb-troubleshooting-datadict.html for how to resolve the issue.
2017-06-07 18:10:55 4959924224 [ERROR] InnoDB: Failed to find tablespace for table '"or_deco__site_development"."images"' in the cache. Attempting to load the tablespace with space id 27.
2017-06-07 18:10:55 127a27000  InnoDB: Operating system error number 13 in a file operation.
InnoDB: The error means mysqld does not have the access rights to
InnoDB: the directory.
2017-06-07 18:10:55 4959924224 [ERROR] InnoDB: Could not find a valid tablespace file for 'or_deco__site_development/images'. See http://dev.mysql.com/doc/refman/5.6/en/innodb-troubleshooting-datadict.html for how to resolve the issue.
2017-06-07 18:10:55 4959924224 [ERROR] InnoDB: Failed to find tablespace for table '"or_deco__site_development"."carousels"' in the cache. Attempting to load the tablespace with space id 13.
2017-06-07 18:10:55 127a27000  InnoDB: Operating system error number 13 in a file operation.
InnoDB: The error means mysqld does not have the access rights to
InnoDB: the directory.
2017-06-07 18:10:55 4959924224 [ERROR] InnoDB: Could not find a valid tablespace file for 'or_deco__site_development/carousels'. See http://dev.mysql.com/doc/refman/5.6/en/innodb-troubleshooting-datadict.html for how to resolve the issue.
2017-06-07 18:10:55 4959924224 [ERROR] InnoDB: Failed to find tablespace for table '"or_deco__site_development"."schema_migrations"' in the cache. Attempting to load the tablespace with space id 4.
2017-06-07 18:10:55 127a27000  InnoDB: Operating system error number 13 in a file operation.
InnoDB: The error means mysqld does not have the access rights to
InnoDB: the directory.
2017-06-07 18:10:55 4959924224 [ERROR] InnoDB: Could not find a valid tablespace file for 'or_deco__site_development/schema_migrations'. See http://dev.mysql.com/doc/refman/5.6/en/innodb-troubleshooting-datadict.html for how to resolve the issue.
2017-06-07 18:10:55 140735296021248 [Note] InnoDB:  Percona XtraDB (http://www.percona.com) 5.6.32-79.0 started; log sequence number 2135725
2017-06-07 18:10:55 4961533952 [Note] InnoDB: Dumping buffer pool(s) not yet started
2017-06-07 18:10:55 140735296021248 [Note] Plugin 'FEEDBACK' is disabled.
2017-06-07 18:10:55 140735296021248 [ERROR] Could not open mysql.plugin table. Some plugins may be not loaded
2017-06-07 18:10:55 140735296021248 [ERROR] Can't open and lock privilege tables: Table 'mysql.servers' doesn't exist
2017-06-07 18:10:55 140735296021248 [Note] Server socket created on IP: '::'.
2017-06-07 18:10:55 140735296021248 [ERROR] Can't start server : Bind on unix socket: Address already in use
2017-06-07 18:10:55 140735296021248 [ERROR] Do you already have another mysqld server running on socket: /tmp/mysql.sock ?
2017-06-07 18:10:55 140735296021248 [ERROR] Aborting

我应该怎么做才能解决这个问题?

编辑

环顾四周,我尝试了很多东西:

1) 我试图停止所有正在运行的 mysql 进程 我仍然有一个无法杀死的进程,因为 pid 一直在变化

ps aux |grep mysql

davidgeismar    19342   0.0  0.0  2432772    532 s000  R+    7:00PM   0:00.00 grep --color=auto --exclude-dir=.bzr --exclude-dir=CVS --exclude-dir=.git --exclude-dir=.hg --exclude-dir=.svn mysql

2) 我还尝试在 /tmp 中创建 mysql.sock 文件,因为我最初的错误消息是:ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (61 "Connection refused") 没有更多的成功

3)我尝试通过自制软件多次卸载和重新安装mysql

4) 我还检查了cd /usr/local/Cellar/mysql/5.7.18_1/ 的权利,我得到了这个:

-rw-r--r--   1 _mysql  _mysql  17987 Mar 18 08:56 COPYING
-rw-r--r--   1 _mysql  _mysql   1234 Jun  9 18:27 INSTALL_RECEIPT.json
-rw-r--r--   1 _mysql  _mysql   2478 Mar 18 08:56 README
drwxr-xr-x  42 _mysql  _mysql   1428 Jun  9 18:27 bin
drwxr-xr-x   2 _mysql  _mysql     68 Jun  9 18:51 data
-rw-r--r--   1 _mysql  _mysql    543 Jun  9 18:27 homebrew.mxcl.mysql.plist
drwxr-xr-x   3 _mysql  _mysql    102 Mar 18 08:56 include
drwxr-xr-x   9 _mysql  _mysql    306 Mar 18 08:56 lib
drwxr-xr-x   3 _mysql  _mysql    102 Mar 18 08:56 scripts
drwxr-xr-x   6 _mysql  _mysql    204 Mar 18 08:56 share
drwxr-xr-x   6 _mysql  _mysql    204 Jun  9 18:27 support-files

一切似乎都归 mysql 所有,这应该是我阅读的正确权限...

我真的不知道下一步该做什么。

【问题讨论】:

    标签: mysql ruby-on-rails root


    【解决方案1】:

    拒绝用户“root”@“localhost”访问(使用密码:否)

    您应该在与 root 用户名

    关联的 database.yml 文件中提供 DB 的密码
    default: &default
      adapter: mysql2
      encoding: utf8
      pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
      username: root
      password: Your_DB_Password_Here
      socket: /tmp/mysql.sock
    
    development:
      <<: *default
      database: or_deco__site_development
    

    更新:

    您应该为 root 用户设置密码并在 database.yml 中使用该密码。请尝试以下方法设置密码。

    $ mysql -u root -p
    
    mysql> SET PASSWORD FOR 'root'@'localhost' = 'your_password_here'
    

    【讨论】:

    • 我明白,但我没有为数据库定义任何密码
    • @DavidGeismar 你确定吗?在安装 mysql 时,它会要求为 root 设置密码。你设置为空吗?
    • 我没有设置任何密码
    • 我试过了,但是在 $ mysql -u root -p 之后,我得到 ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (61 “连接被拒绝”)
    • @DavidGeismar 尝试从文件中删除socket: /tmp/mysql.sock
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-25
    • 1970-01-01
    • 2015-12-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多