php - 使用正确的语法并以受限制的匿名用户身份登录时,MYSQL 出现错误

标签 php mysql database

我在互联网上进行了搜索,并向工作中的几个人询问了如何解决这个问题,但我准备放弃......我在我的笔记本电脑上安装了 mySQL,但我无法以用户身份登录。

Raymunds-MacBook-Pro:~ raymundsinlao$ /usr/local/mysql/bin/mysql 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2149
Server version: 5.6.13 MySQL Community Server (GPL)

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> -u root -p;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '-u root -p' at line 1
mysql> 

当我尝试登录时,它告诉我语法错误。我尝试了很多不同的可能方法,但都行不通。

我的另一个问题是我是匿名用户,因此我无法访问除了 information_schema 和 test 之外的任何数据库。

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| test               |
+--------------------+
2 rows in set (0.00 sec)
mysql> use mysql;
ERROR 1044 (42000): Access denied for user ''@'localhost' to database 'mysql'
mysql>

在过去的 2 天里,我尝试了数十种不同的方法,并为此花费了 8 个多小时。请帮帮我!

最佳答案

您正在分隔 /usr/local/mysql/bin/mysql-u root -p,但它们都属于命令行,所以应该看起来像这样:

/usr/local/mysql/bin/mysql -u root -p

事实上,您只需使用 /usr/local/mysql/bin/mysql 即可登录,这意味着您已经以 root 身份登录,只是该用户没有密码,并且您肯定需要为该帐户设置密码(登录后):

use mysql;
update user set password=PASSWORD('NEWPASSWORD') where User='root';

关于php - 使用正确的语法并以受限制的匿名用户身份登录时,MYSQL 出现错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17961778/

相关文章:

mysql - 关于选择查询的问题

PHP 用户级 session 持久化

php - 在 PHP 中大量添加带小数点的数字

用于转换和格式化日期的 MySQL 语法错误

php - 从 Wordpress 外部检索 Wordpress 附件

php - 将字符串转换为数组表数据php

mysql - 为什么 MySQL Workbench 会为 View 生成占位符表?

postgreSQL 数据库全局唯一业务键

php - Google MAPS API V3 --> 如何显示存储在我的 MYSQL 表中的所有多边形?

数组查找中的 PHP 未定义索引