1. 問(wèn)題描述:
在MySQL控制臺(tái)下創(chuàng)建數(shù)據(jù)庫(kù)出現(xiàn)以下信息:
mysql> CREATE DATABASE python;
ERROR 1044 (42000): Access denied for user ''@'localhost' to database 'python'
2. 解決方法:
執(zhí)行以下命令進(jìn)入控制臺(tái):
mysql --user=root -p
輸入root用戶的密碼即可進(jìn)入mysql控制臺(tái):
創(chuàng)建數(shù)據(jù)庫(kù):
create database python;
顯示所有數(shù)據(jù)庫(kù):
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, 以上方法不是最好的, 但卻是簡(jiǎn)單可行的,Enjoy it!!!
4、方法四:
這幾天用空密碼登錄mysql后,然后修改mysql默認(rèn)密碼,使用mysql表出現(xiàn)過(guò)這個(gè)問(wèn)題,提示:ERROR 1044 (42000): Access denied for user ''@'localhost' to database 'mysql'。網(wǎng)上找了一些方法,終于搞定了。
我用的是xampp集成的mysql,之前空密碼能登進(jìn)去phpmyadmin,但怎么也進(jìn)不去phpmyadmin的系統(tǒng)表
后來(lái)解決成功發(fā)現(xiàn)是因?yàn)閙ysql數(shù)據(jù)庫(kù)的user表里,存在用戶名為空的賬戶即匿名賬戶,導(dǎo)致登錄的時(shí)候是雖然用的是root,但實(shí)際是匿名登錄的,通過(guò)錯(cuò)誤提示里的''@'localhost'可以看出來(lái)。我用方法一解決了問(wèn)題,
方法一:
在my.ini的[mysqld]字段加入:
skip-grant-tables
重啟mysql服務(wù),這時(shí)的mysql不需要密碼即可登錄數(shù)據(jù)庫(kù)
然后進(jìn)入mysql
mysql>use mysql;
mysql>update user set password=password('新密碼') WHERE User='root';
mysql>flush privileges;
運(yùn)行之后最后去掉my.ini中的skip-grant-tables,重啟mysqld即可。
修改mysql密碼方法二:
不使用修改my.ini重啟服務(wù)的方法,通過(guò)非服務(wù)方式加skip-grant-tables運(yùn)行mysql來(lái)修改mysql密碼
停止mysql服務(wù)
打開(kāi)命令行窗口,在bin目錄下使用mysqld-nt.exe啟動(dòng),即在命令行窗口執(zhí)行: mysqld-nt --skip-grant-tables
然后另外打開(kāi)一個(gè)命令行窗口,登錄mysql,此時(shí)無(wú)需輸入mysql密碼即可進(jìn)入。
新聞熱點(diǎn)
疑難解答
圖片精選