如何在控制台中访问 mysql

如何在控制台中访问 mysql

我使用 xampp 单独安装了 mysql 并成功运行了所有服务,但是当我尝试使用 mysql-client 登录到 mysql 服务器时出现以下错误。

user@user-pc:~$ sudo /opt/lampp/lampp startmysql 
XAMPP: Starting MySQL...already running.
user@user-pc:~$ mysql -h localhost -u root -p 
Enter password:  
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

我该如何修复这个错误

答案1

我只需将 /opt/lampp/etc/my.cnf 文件替换为 /etc/mysql/my.cnf 即可解决上述问题

1)首先将 /etc/mysql/my.cnf 备份到某个地方,以防出现问题

user@user:~$ cp /etc/mysql/my.cnf ~/Desktop/

2)然后将 /etc/mysql/my.cnf 文件复制到 /etc/mysql/

user@user:~$ sudo cp /opt/lampp/etc/my.cnf /etc/mysql/

3)重启计算机

4)启动lampp服务器

user@user:~$ sudo /opt/lampp/lampp start

5)然后 mysql-client 将在控制台中启动,并且不会出现任何错误

user@user:~$ mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.6.24 Source distribution

Copyright (c) 2000, 2015, 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>

我在 Ubuntu 14.04 中完成了此操作

相关内容