mysql 建庫報匿名用戶權限錯誤

報錯信息:

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

系統環境:

  • Centos 7.5
  • Mysql Server version: 5.6.48

分析原因:匿名用戶('')權限報錯

問題描述:

安裝好mysql後,root用戶賬戶登錄mysql,創建一個新數據庫時,提示報錯,如下:

[root@localhost mysql]# mysql -uroot
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.6.48 MySQL Community Server (GPL)

Copyright (c) 2000, 2019, 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> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
+--------------------+
1 row in set (0.00 sec)

mysql> create database meitu charset=utf8;
ERROR 1044 (42000): Access denied for user ''@'localhost' to database 'meitu'

解決方法:

1. 在/etc/my.cnf的[mysqld]字段下加入:skip-grant-tables , 如下截圖

mysql 建庫報匿名用戶權限錯誤

2. 再重啓mysqld服務

[maaiqiang@localhost ~]$ systemctl restart mysqld

這時的mysql不需要密碼即可登錄數據庫

3. 登錄進入mysql,執行以下命令

mysql > use mysql;
mysql > delete from user where USER='';
mysql > flush privileges;
mysql > exit;

4. 再刪除/etc/my.ini中的skip-grant-tables,重啓mysqld服務即可正常建庫了。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章