mysql ERROR 1044 (42000): Access denied for user ''@'localhost' to database
1. 問題描述:
在MySQL控制臺下創(chuàng)建數(shù)據(jù)庫出現(xiàn)以下信息:
mysql> CREATE DATABASE python;
ERROR 1044 (42000): Access denied for user ''@'localhost' to database 'python'
2. 解決方法:
執(zhí)行以下命令進(jìn)入控制臺:
mysql --user=root -p
輸入root用戶的密碼即可進(jìn)入mysql控制臺:
創(chuàng)建數(shù)據(jù)庫:
create database python;
顯示所有數(shù)據(jù)庫:
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默認(rèn)密碼,使用mysql表出現(xiàn)過這個(gè)問題,提示:ERROR 1044 (42000): Access denied for user ''@'localhost' to database 'mysql'。網(wǎng)上找了一些方法,終于搞定了。
我用的是xampp集成的mysql,之前空密碼能登進(jìn)去phpmyadmin,但怎么也進(jìn)不去phpmyadmin的系統(tǒng)表
后來解決成功發(fā)現(xiàn)是因?yàn)閙ysql數(shù)據(jù)庫的user表里,存在用戶名為空的賬戶即匿名賬戶,導(dǎo)致登錄的時(shí)候是雖然用的是root,但實(shí)際是匿名登錄的,通過錯(cuò)誤提示里的''@'localhost'可以看出來。我用方法一解決了問題,
方法一:
在my.ini的[mysqld]字段加入:
skip-grant-tables
重啟mysql服務(wù),這時(shí)的mysql不需要密碼即可登錄數(shù)據(jù)庫
然后進(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ù)的方法,通過非服務(wù)方式加skip-grant-tables運(yùn)行mysql來修改mysql密碼
停止mysql服務(wù)
打開命令行窗口,在bin目錄下使用mysqld-nt.exe啟動,即在命令行窗口執(zhí)行: mysqld-nt --skip-grant-tables
然后另外打開一個(gè)命令行窗口,登錄mysql,此時(shí)無需輸入mysql密碼即可進(jìn)入。
按以上方法修改好密碼后,關(guān)閉命令行運(yùn)行mysql的那個(gè)窗口,此時(shí)即關(guān)閉了mysql,如果發(fā)現(xiàn)mysql仍在運(yùn)行的話可以結(jié)束掉對應(yīng)進(jìn)程來關(guān)閉。
啟動mysql服務(wù)。
linux下的處理方法:
mysql> use mysql ERROR 1044 (42000): Access denied for user 'root'@'localhost' to database 'mysql' mysql> exit Bye [root@testtest ~]# service mysqld stop Stopping mysqld: [ OK ] [root@testtest ~]# mysqld_safe --user=mysql --skip-grant-tables --skip-networking & [root@testtest ~]# mysql -u root -p -hlocalhost Enter 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> quit Bye [root@testtest ~]# service mysqld start restart Linux/OS
相關(guān)文章
mysql數(shù)據(jù)庫基礎(chǔ)知識點(diǎn)與操作小結(jié)
這篇文章主要介紹了mysql數(shù)據(jù)庫基礎(chǔ)知識點(diǎn)與操作,總結(jié)分析了mysql數(shù)據(jù)庫修改數(shù)據(jù)表、增刪改查及數(shù)據(jù)庫函數(shù)基本功能,需要的朋友可以參考下2020-01-01MySQL?數(shù)據(jù)庫聚合查詢和聯(lián)合查詢操作
這篇文章主要介紹了MySQL?數(shù)據(jù)庫聚合查詢和聯(lián)合查詢操作,需要的朋友可以參考下2021-12-12Windows10系統(tǒng)下Mysql8.0.13忘記root密碼的操作方法
這篇文章主要給大家介紹了關(guān)于Windows10系統(tǒng)下Mysql8.0.13忘記root密碼的操作方法,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2021-01-01Mysql 切換數(shù)據(jù)存儲目錄的實(shí)現(xiàn)方法
這篇文章主要介紹了Mysql 切換數(shù)據(jù)存儲目錄的實(shí)現(xiàn)方法的相關(guān)資料,需要的朋友可以參考下2017-07-07CentOS 7中升級MySQL 5.7.23的坑與解決方法
我們在安裝升級的時(shí)候會遇到一些問題,不過可能每個(gè)人遇到的問題不一樣,多找找才能解決問題喲,下面這篇文章主要給大家介紹了關(guān)于在CentOS 7中升級MySQL 5.7.23遇到的一個(gè)坑與解決方法,需要的朋友可以參考下2018-10-10