栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

mysql ERROR 1044 (42000): Access denied for user ‘‘@‘localhost‘ to database

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

mysql ERROR 1044 (42000): Access denied for user ‘‘@‘localhost‘ to database

1. 問題描述:

在MySQL控制台下建立資料庫出現以下資訊:

mysql> CREATE DATAbase python; 
ERROR 1044 (42000): Access denied for user ‘‘@‘localhost‘ to database ‘python‘

2. 解決方案:

執行以下命令進入控制台:(在MySQL bin檔案下)

mysql --user=root -p

輸入root使用者的密碼即可進入mysql控制台:

建立資料庫:

create database python;

顯示所有資料庫:

show databases;

如下:

www.linuxidc.com @www.linuxidc.com:~$ mysql --user=root -p 
Enter password: 
Welcome to the MySQL monitor. Commands end with ; or g. 
Your MySQL connection id is 4 
Server version: 5.6.17 MySQL Community Server (GPL)

Copyright (c) 2000, 2014,Oracleand/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> create database python; 
Query OK, 1 row affected (0.00 sec)

mysql> show databases; 
+--------------------+ 
| Database | 
+--------------------+ 
| information_schema | 
| mysql | 
| performance_schema | 
| python | 
| test | 
+--------------------+ 
5 rows in set (0.02 sec)

mysql>

3. OK, 以上方法不是最好的, 但卻是簡單可行的,Enjoy it!!!

4、方法四:

這幾天用空密碼登入mysql後,然後修改mysql預設密碼,使用mysql表出現過這個問題,提示:ERROR 1044 (42000): Access denied for user ‘‘@‘localhost‘ to database ‘mysql‘。網上找了一些方法,終於搞定了。

我用的是xampp整合的mysql,之前空密碼能登進去phpmyadmin,但怎麼也進不去phpmyadmin的系統資料表

後來解決成功發現是因為mysql資料庫的user表裡,存在使用者名稱為空白的賬戶即匿名賬戶,導致登入的時候是雖然用的是root,但實際是匿名登入的,通過錯誤提示裡的‘‘@‘localhost‘可以看出來。我用方法一解決了問題,

方法一:
在my.ini的[mysqld]欄位加入:

skip-grant-tables

重啟mysql服務,這時的mysql不要求輸入密碼即可登入資料庫
然後進入mysql

mysql>use mysql;
mysql>update user set password=password(‘新密碼‘) WHERe User=‘root‘; 
mysql>flush privileges;

運行之後最後去掉my.ini中的skip-grant-tables,重啟mysqld即可。

修改mysql密碼方法二:
不使用修改my.ini重啟服務的方法,通過非服務方式加skip-grant-tables運行mysql來修改mysql密碼
停止mysql服務
開啟命令列視窗,在bin目錄下使用mysqld-nt.exe啟動,即在命令列視窗執行: mysqld-nt --skip-grant-tables
然後另外開啟一個命令列視窗,登入mysql,此時無需輸入mysql密碼即可進入。
按以上方法修改好密碼後,關閉命令列運行mysql的那個視窗,此時即關閉了mysql,如果發現mysql仍在啟動並執行話可以結束掉對應進程來關閉。
啟動mysql服務。

linux下的處理方法:

mysql> use mysqlERROR 1044 (42000): Access denied for user ‘root‘@‘localhost‘ to database ‘mysql‘mysql> exitBye[[email protected] ~]# service mysqld stop Stopping mysqld:[ OK ][[email protected] ~]# mysqld_safe --user=mysql --skip-grant-tables --skip-networking &  [[email protected] ~]# mysql -u root -p -hlocalhostEnter password:  mysql> use mysql mysql> SELECT host,user,password,Grant_priv,Super_priv FROM mysql.user; mysql> UPDATE mysql.user SET Grant_priv=‘Y‘, Super_priv=‘Y‘ WHERe User=‘root‘; mysql> FLUSH PRIVILEGES; mysql> GRANT ALL ON *.* TO ‘root‘@‘localhost‘; mysql> GRANT ALL ON *.* TO ‘root‘@‘cn.cn.cn.cn‘; mysql> GRANT ALL ON *.* TO ‘root‘@‘245.245.245.245‘; mysql> GRANT ALL ON *.* TO ‘root‘@‘127.0.0.1‘; mysql> FLUSH PRIVILEGES;  mysql> quitBye[[email protected] ~]# service mysqld start  restart Linux/OS

Related Article:MySql 執行計畫

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/741038.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号