我遇到问题,因为当我使用mysql -u=root
命令行登录mysql时,它会给我一个错误ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
但是当我尝试使用sudo mysql -u=root
时,我设法转到mysql提示mysql>
问题是当我尝试使用命令create database dbname
创建数据库时出现错误ERROR 1044 (42000): Access denied for user ''@'localhost' to database 'dbname'
补充信息:
mysql> select user();
+--------------------+
| user() |
+--------------------+
| =root@localhost |
+--------------------+
1 row in set (0.00 sec)
答案 0 :(得分:4)
创建数据库以root身份登录MySQL,如下所示:
sudo mysql -h localhost -u root -p
答案 1 :(得分:1)
尝试连接
sudo mysql -u root