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

时间:2022-02-02 19:19:54
1. 问题描述:
在mysql控制台下创建数据库出现以下信息:
 
mysql> CREATE DATABASE python;
ERROR 1044 (42000): Access denied for user ''@'localhost' to database 'python'
2. 解决方法:
执行以下命令进入控制台:
 
mysql --user=root -p
输入root用户的密码即可进入mysql控制台:
创建数据库:
 
create database python;
显示所有数据库:
 
show databases;
如下:
 
cryhelyxx@ada:~$ 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, 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> 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.进入mysql控制台/创建数据库/使用数据库/创建表/插入记录/查看表中的内容/退出mysql控制台:
 
cryhelyxx@ada:~$ 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, 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> 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> use python;
Database changed
mysql> CREATE TABLE people(name VARCHAR(30), age INT, sex CHAR(1));
Query OK, 0 rows affected (0.58 sec)

mysql> INSERT INTO people VALUES('Cryhelyxx', 22, 'M');
Query OK, 1 row affected (0.04 sec)

mysql> SELECT * FROM people;
+-----------+------+------+
| name      | age  | sex  |
+-----------+------+------+
| Cryhelyxx |   22 | M    |
+-----------+------+------+
1 row in set (0.00 sec)

mysql> exit
Bye
cryhelyxx@ada:~$ 
4. OK, 以上方法不是最好的, 但却是简单可行的,Enjoy it!!!
 
更多解决方法及原因继续研究, 继续补充...