首先我
debian@osboxes:~/Desktop$ mysql -u root -p
Command 'mysql' not found, but can be installed with:
sudo apt install mysql-client-core-8.0 # version 8.0.18-0ubuntu0.19.10.1, or
sudo apt install mariadb-client-core-10.3 # version 1:10.3.20-0ubuntu0.19.10.1
然后我安装了
debian@osboxes:~/Desktop$ sudo apt install mysql-client-core-8.0
现在我明白了
debian@osboxes:~/Desktop$ mysql -u root -p
Enter password:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
所以现在我检查
debian@osboxes:~/Desktop$ sudo service mysql status
Unit mysql.service could not be found.
然后我
debian@osboxes:~/Desktop$ ps aux | grep mysql
debian 4379 0.0 0.0 8896 916 pts/0 S+ 14:38 0:00 grep --color=auto mysql
所以看起来 mysql 服务正在运行。但是当我尝试登录时
debian@osboxes:~/Desktop$ mysql -u root -p
Enter password:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
debian@osboxes:~/Desktop$
我也试过了。
debian@osboxes:~/Desktop$ systemctl restart mysql
Failed to restart mysql.service: Unit mysql.service not found.
debian@osboxes:~/Desktop$ sudo dpkg -l | grep -E 'mysql'
ii libmysqlclient21:amd64 8.0.18-0ubuntu0.19.10.1 amd64 MySQL database client library
ii mysql-client-core-8.0 8.0.18-0ubuntu0.19.10.1 amd64 MySQL database core client binaries
ii mysql-common 5.8+1.0.5ubuntu2 all MySQL database common files, e.g. /etc/mysql/my.cnf
debian@osboxes:~/Desktop$
上周我问过一个问题mysql 在重启后无法启动所以我知道我在有问题的这台机器上安装了mysql。但我仍然遇到问题,所以尝试了
debian@osboxes:~/Desktop$ sudo apt-get install mysql-server
E: Could not get lock /var/lib/dpkg/lock-frontend. It is held by process 4531 (unattended-upgr) - open (11: Resource temporarily unavailable)
N: Be aware that removing the lock file is not a solution and may break your system.
E: Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend), is another process using it?
我也检查了
debian@osboxes:~/Desktop$ systemctl -a | grep -iE 'mysql'
没有输出。我也
debian@osboxes:~/Desktop$ sudo netstat -tap | grep mysql
sudo: netstat: command not found
然后我
debian@osboxes:~/Desktop$ sudo apt-get install net-tools
debian@osboxes:~/Desktop$ sudo netstat -tap | grep mysql
无输出。
现在根据下面的评论我做了
debian@osboxes:~/Desktop$ sudo rm /var/lib/dpkg/lock
debian@osboxes:~/Desktop$ sudo dpkg --configure -a
debian@osboxes:~/Desktop$ sudo systemctl restart mysql.service
Failed to restart mysql.service: Unit mysql.service not found.
现在尝试
debian@osboxes:~/Desktop$ sudo rm /var/cache/apt/archives/lock
现在我重新启动然后
debian@osboxes:~/Desktop$ ps aux | grep mysql
debian 2403 0.0 0.0 8896 844 pts/0 S+ 15:10 0:00 grep --color=auto mysql
debian@osboxes:~/Desktop$ mysql -u root -p
Enter password:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
它正在获取我上周尝试过的 root 密码。我不明白我应该检查什么。我无法登录。我现在应该检查什么?我在 Ubuntu 19.10 上
答案1
此外mysql 客户端你还需要安装mysql 服务器。
我添加了以下信息Ubuntu mysql
安装
要安装 MySQL,请从终端提示符运行以下命令:
sudo apt install mysql-server
安装完成后,MySQL 服务器应自动启动。您可以从终端提示符运行以下命令来检查 MySQL 服务器是否正在运行:
sudo netstat -tap | grep mysql
运行此命令时,您应该看到以下行或类似内容:
tcp 0 0 localhost:mysql *:* LISTEN 2556/mysqld
如果服务器没有正常运行,您可以输入以下命令来启动它:
sudo systemctl restart mysql.service
配置
您可以编辑该/etc/mysql/my.cnf
文件来配置基本设置 - 日志文件、端口号等。例如,要配置 MySQL 以监听来自网络主机的连接,请将 bind-address 指令更改为服务器的 IP 地址:
bind-address = 192.168.0.5
192.168.0.5
用适当的地址替换。
对 MySQL 守护进程进行更改后/etc/mysql/my.cnf
需要重新启动:
sudo systemctl restart mysql.service