MySQL 问题解决

问题如下:
Failed to Connect to MySQL at 127.0.0.1:3306 with user root Access denied for user 'root'@'localhost'

我的问题是terminal中可以使用管理员账号登录mysql,但是在使用workbench时,链接就会出现上面的问题

问题如图

mysql1.png

网上看了许多方法,试验了几个,发现新建一个用户解决办法最简单。

创建用户
格式:create user 'userName'@'localhost' identified by 'passward';

mysql> create user 'dfzxk'@'localhost' identified by '123456';
Query OK, 0 rows affected (0.00 sec)

给user上帝权限

mysql> grant all on *.* to dfzxk@"%" identified by "123456";
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql授权东西太多,不多说了

查看用户权限

mysql> show grants for dfzxk;
+--------------------------------------------+
| Grants for dfzxk@%                         |
+--------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'dfzxk'@'%' |
+--------------------------------------------+
1 row in set (0.00 sec)
mysql2.png

再次使用workbench,已经链接成功了。

遇到的坑

mysql> create user 'dflx'@'localhost' identified by '123456';
ERROR 1396 (HY000): Operation CREATE USER failed for 'dflx'@'localhost'

据说是已经建立了这个用户,我Ubuntu的xwindows桌面崩溃过一次,因为\目录太小的原因,我准备增大根目录的容量,把\home移动5g给它,可是现在卡在了这里。

sql语句查看一下

mysql> show database;
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 'database' at line 1
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| mysql_shiyan       |
| performance_schema |
| sys                |
| test               |
+--------------------+
6 rows in set (0.00 sec)

mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> select host,user from mysql.user;
+-----------+------------------+
| host      | user             |
+-----------+------------------+
| %         | dfzxk            |
| localhost | debian-sys-maint |
| localhost | dflx             |
| localhost | dfzxk            |
| localhost | mysql.session    |
| localhost | mysql.sys        |
| localhost | root             |
+-----------+------------------+
7 rows in set (0.00 sec)

mysql> show grants for dflx;
ERROR 1141 (42000): There is no such grant defined for user 'dflx' on host '%'

果然我的dflx用户还在,我workbench链接了一下,成功了,但是说没有授权,可是我workbench进行了,增加,查询,好像没有问题啊(嘻嘻)

mysql3.png

show databases;
use test;
show tables;
select * from user;
insert into user values('dfzxk','123456');

结果如下:


mysql0.png

学的是SQL server,对于mysql这些有些不太熟悉,但是sql语法大体通用的。

修改root密码如下


上面说的

mysql> set password for root@localhost=password("123456");
Query OK, 0 rows affected, 2 warnings (0.02 sec)
mysql> select host,user,grant_priv from user;
+-----------+------------------+------------+
| host      | user             | grant_priv |
+-----------+------------------+------------+
| localhost | root             | Y          |
| localhost | mysql.session    | N          |
| localhost | mysql.sys        | N          |
| localhost | debian-sys-maint | Y          |
| localhost | dflx             | N          |
| %         | dflx             | N          |
+-----------+------------------+------------+
6 rows in set (0.04 sec)

mysql> select host,user,grant_priv,alter_priv,password_expired from user;
+-----------+------------------+------------+------------+------------------+
| host      | user             | grant_priv | alter_priv | password_expired |
+-----------+------------------+------------+------------+------------------+
| localhost | root             | Y          | Y          | N                |
| localhost | mysql.session    | N          | N          | N                |
| localhost | mysql.sys        | N          | N          | N                |
| localhost | debian-sys-maint | Y          | Y          | N                |
| localhost | dflx             | N          | N          | N                |
| %         | dflx             | N          | Y          | N                |
+-----------+------------------+------------+------------+------------------+
6 rows in set (0.00 sec)

mysql> select host,user,grant_priv,pass_last_change from user;
ERROR 1054 (42S22): Unknown column 'pass_last_change' in 'field list'
mysql> select host,user,grant_priv,pass_last_changed from user;
ERROR 1054 (42S22): Unknown column 'pass_last_changed' in 'field list'
mysql> select host,user,grant_priv,password_last_changed from user;
+-----------+------------------+------------+-----------------------+
| host      | user             | grant_priv | password_last_changed |
+-----------+------------------+------------+-----------------------+
| localhost | root             | Y          | 2018-07-01 17:10:59   |
| localhost | mysql.session    | N          | 2018-07-01 17:11:00   |
| localhost | mysql.sys        | N          | 2018-07-01 17:11:00   |
| localhost | debian-sys-maint | Y          | 2018-07-01 17:11:01   |
| localhost | dflx             | N          | 2018-07-07 21:10:00   |
| %         | dflx             | N          | 2018-07-07 21:24:55   |
+-----------+------------------+------------+-----------------------+
6 rows in set (0.00 sec)

mysql> set password for root@localhost=password("123456");
Query OK, 0 rows affected, 2 warnings (0.02 sec)


我Ubuntu的xwindows桌面崩溃过一次,因为\目录太小的原因,
当时安装系统时看网上教程一大推说,给根目录10g就行了,swap是内存二倍,
感觉这个建议很坑啊,网上一大推抱怨这个\目录10g的,可是给根目录增加容量
不容易啊!我准备增大根目录的容量,把\home移动5g给它,可是现在卡在了这里。

我整理了半天垃圾,现在还是这个情况,如果\目录剩余太小了,会发生很可怕的问题。

dfzxk@satan-master:~$ df -h
文件系统 容量 已用 可用 已用% 挂载点
udev 1.9G 0 1.9G 0% /dev
tmpfs 382M 41M 342M 11% /run
/dev/sda8 9.4G 7.0G 2.0G 79% /
/dev/sda9 47G 13G 32G 30% /usr
tmpfs 1.9G 65M 1.8G 4% /dev/shm
tmpfs 5.0M 4.0K 5.0M 1% /run/lock
tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup
/dev/sda10 22G 1.4G 19G 7% /home
/dev/sda1 196M 29M 168M 15% /boot/efi
tmpfs 382M 40K 382M 1% /run/user/1003

参考文章:
[mysql Access denied for user root@localhost错误解决方法总结](http://www.111cn.net/database/mysql/44142.htm)

[MYSQL登录错误:mysqladmin: connect to server at 'localhost' failed](http://blog.csdn.net/j3smile/article/details/14134879)


[Failed to connect to mysql at 127.0.0.1:3306 with user root access denied for user 'root'@'localhost'(using password:YES)](https://stackoverflow.com/questions/25777943/failed-to-connect-to-mysql-at-127-0-0-13306-with-user-root-access-denied-for-us)
[
解决database - Failed to connect to mysql at 127.0.0.1:3306 with user root access denied for user 'root'@'localhost'](http://www.111cn.net/database/mysql/44142.htm)

[MySQL添加用户、删除用户与授权](http://www.cnblogs.com/wanghetao/p/3806888.html)

教您如何查看MySQL用户权限 [教您如何查看MySQL用户权限](http://www.cnblogs.com/cnteam/articles/4272460.html)


windows下出现问题

Microsoft Windows [版本 10.0.16299.125]
(c) 2017 Microsoft Corporation。保留所有权利。

C:\WINDOWS\system32>cd C:\mysql-5.7.20-winx64\mysql-5.7.20-winx64\bin

C:\mysql-5.7.20-winx64\mysql-5.7.20-winx64\bin>mysqld.exe

C:\mysql-5.7.20-winx64\mysql-5.7.20-winx64\bin>mysql
ERROR 1045 (28000): Access denied for user 'ODBC'@'localhost' (using password: NO)

C:\mysql-5.7.20-winx64\mysql-5.7.20-winx64\bin>mysql -u -p
ERROR 1045 (28000): Access denied for user '-p'@'localhost' (using password: NO)

C:\mysql-5.7.20-winx64\mysql-5.7.20-winx64\bin>mysql -u root
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.7.20 MySQL Community Server (GPL)

Copyright (c) 2000, 2017, 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>

![mysql启动.jpg](https://upload-images.jianshu.io/upload_images/4976516-c5b0fc5406569a0e.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 159,015评论 4 362
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 67,262评论 1 292
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 108,727评论 0 243
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 43,986评论 0 205
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 52,363评论 3 287
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 40,610评论 1 219
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 31,871评论 2 312
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 30,582评论 0 198
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 34,297评论 1 242
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 30,551评论 2 246
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 32,053评论 1 260
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 28,385评论 2 253
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 33,035评论 3 236
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 26,079评论 0 8
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 26,841评论 0 195
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 35,648评论 2 274
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 35,550评论 2 270

推荐阅读更多精彩内容