问题描述
今天在Ubuntu14.04下安装mysql时遇到了问题。
一开始,我尝试输入以下命令:
mysql -u root -p
然后得到如下信息:
The program mysql can be found on the following packages:
mysql-client-core-5.5
mariadb-client-core-5.5
mysql-client-core-5.6
percona-xtrabd-cluster-client-5.5
我鬼使神差地选择了5.6的安装包,输入了
sudo apt-get install mysql-client-core-5.6
安装完毕后我又一次尝试连接mysql,得到如下错误信息:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock'
我尝试输入mysqld,得到以下提示:
The program mysql can be found on the following packages:
mysql-server-core-5.5
mariadb-server-core-5.5
mysql-server-core-5.6
percona-xtrabd-cluster-server-5.5
对应的我选择了mysql-server-core-5.6
连接时还是得到上面的错误。
查阅资料后,我按照别人的方法依次输入以下命令:
sudo apt-get clean && sudo apt-get update
sudo apt-get install mysql-server mysql-client
结果得到了如下信息
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:
The following packages have unmet dependencies:
mysql-server : Depends: mysql-server-5.5 but it is not going to be installed
E: Unable to correct problems, you have held broken packages.
解决方法:
经过查阅终于找到了问题的解决方法。版本依赖问题,MySQL客户端5.5和MySQL服务器5.5是目前Ubuntu 14.04匹配地“最好”版本。
方法一:
移除5.6,安装5.5
sudo apt-get purge mysql-client-core-5.6
sudo apt-get autoremove
sudo apt-get autoclean
sudo apt-get install mysql-client-core-5.5
sudo apt-get install mysql-server
方法二:
使用aptitude,其实也是移除5.6版本,安装了5.5版本。未安装aptitude的话先安装aptitude
sudo apt-get install aptitude
然后输入
sudo aptitude install mysql-server