我是 MySQL 领域的新手,所以请耐心等待。
我刚刚完成将 11.10 升级到 12.04。
一切似乎都没有任何问题,我所有的软件和设置都运行良好。除了 MySQL。
当我尝试:
sudo start mysql
Run Code Online (Sandbox Code Playgroud)
我收到一个错误:
start: Job failed to start
Run Code Online (Sandbox Code Playgroud)
我在哪里可以诊断出问题所在?并且(希望如此) - 如何解决?
(如果这很重要,我在这里禁用了自动启动以下建议)
更新 1:
两个输出:
cat /var/log/mysql.err
cat /var/log/mysql.log
Run Code Online (Sandbox Code Playgroud)
是空的。
的输出dmesg | grep mysql
:
[ 1401.785141] type=1400 audit(1335619832.181:25): apparmor="STATUS" operation="profile_replace" name="/usr/sbin/mysqld" pid=16165 comm="apparmor_parser"
[ 1401.791089] init: Failed to spawn mysql main process: unable to execute: No such file or directory
Run Code Online (Sandbox Code Playgroud)
更新 2:
正如下面的 AWinter 所指出的 - 似乎 MySQL 在升级后会自动消失,必须重新安装。
And*_*ter 48
检查是否卸载了 mysql-server-5.1 软件包,升级后似乎它可能仍然存在。我遇到了同样的错误,不得不清除 MySQL 服务器 5.1 和 5.5,然后重新安装。
为了安全起见,首先备份您的 /var/lib/mysql/ 目录。
sudo cp -R /var/lib/mysql/ ~/mysql
Run Code Online (Sandbox Code Playgroud)
接下来清除 MySQL(这将删除 php5-mysql 和 phpmyadmin 以及许多其他库,因此准备在此之后重新安装一些项目。
sudo apt-get purge mysql-server-5.1 mysql-common
Run Code Online (Sandbox Code Playgroud)
删除文件夹 /etc/mysql/ 及其内容
sudo rm /etc/mysql/ -R
Run Code Online (Sandbox Code Playgroud)
接下来检查您的旧数据库文件是否仍在 /var/lib/mysql/ 中,如果它们不在,则将它们复制回文件夹中,然后 chown root:root
(仅当文件不再存在时才运行这些)
sudo mkdir /var/lib/mysql/
sudo chown root:root /var/lib/mysql/ -R
sudo cd ~/mysql/
sudo cp * /var/lib/mysql/ -R
Run Code Online (Sandbox Code Playgroud)
接下来安装mysql服务器
sudo apt-get install mysql-server
Run Code Online (Sandbox Code Playgroud)
最后重新安装任何丢失的软件包,如 phpmyadmin 和 php5-mysql。
小智 12
我遇到了同样的问题,对我来说,InnoDB 日志文件的大小与 mysql 预期的不同,并且在升级过程中无声无息地失败了。
我有一个自定义配置文件,该文件在升级到 12.04 时被删除,该文件将日志文件大小设置为默认配置以外的大小。
您必须删除文件:/var/lib/mysql/ib_logfile*
文件消失后,mysql 现在可以启动并创建默认大小的新日志文件。
Ian*_*non 10
大多数错误将通过以详细的非守护程序模式启动服务器并观察输出来显示:
sudo mysqld --verbose
Run Code Online (Sandbox Code Playgroud)
小智 7
我遇到了同样的问题,但上面的答案都没有帮助我。所以作为最后的希望,我尝试释放一些磁盘空间。我只是从 /var/log 中删除了不必要的日志文件,从而释放了一些 2.5G 空间。然后MySQL正常启动。
这有时会发生,虽然有几个不同的问题可能会导致 mysql 无法启动,但我将在这里写一些我所知道的最常见的问题:
注意 - 因为解释最常见的问题,我假设您已经尝试删除和安装,或者简单地重新安装 mysql 服务,如下所示:
安装 -sudo apt-get install mysql-server mysql-client
删除 -sudo apt-get remove mysql-server mysql-client
清除(删除文件 + 配置) -sudo apt-get purge mysql-server mysql-client
重新安装 -sudo apt-get install --reinstall mysql-server mysql-client
my.cnf
文件不在默认目录中。它应该(默认情况下)位于/etc/my.cnf
或 中/etc/mysql/my.cnf
。
mysql 数据文件所在的硬盘空间不足。如果数据库变得太大并占用了 100% 的硬盘驱动器,则服务将失败。
升级后检查my.cnf
文件是否在正确的位置。根据您升级的方式或从哪个版本升级,它可能在/etc/my.cnf
或/etc/mysql/my.cnf
如前所述。还要记住,文件也可以命名mysql.conf
,而不仅仅是my.cnf
. 如果您从mysql.com下载了二进制文件,就会发生这种情况。
Doing a dmesg
to see what the mysql service is is throwing as an error message helps since it gives the loading error. It might also say why this is happening. If you type dmesg
alone in the terminal it will show you the world. What we want is the info about mysql so do something like this: dmesg | grep mysql
this will throw you any lines that contain mysql in them.
Check that the my.cnf
or mysql.conf
file is correct. In 12.04 MySQL is version 5.5, in 11.10 it is version 5.1. It might have some changes in the conf file (Haven't actually checked that) and it might sound silly but it sure can give you some trouble.
Errors related to socket problems normally are the fault of the my.cnf
or mysql.conf
file pointing to the wrong place, they error will normally show as:
Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock'
The other source of this problem is related to the mysql
file in /etc/init.d
that it is pointing at the wrong folder because it might be using an older script than the one needed for the actual mysql on the system (It might not have updated correctly, did not overwrite the config file, etc..). So just edit any of this two files and see if they are pointing somewhere else and then simply do a sudo service mysql restart
to check if it works.
To have a better look at the error specific outputs of mysql do the following:
cat /var/log/mysql.err
- Will show you the mysql errors. I would make it like this cat /var/log/mysql.err | less
if you happen to see too much information fly by since less
will help you scroll your way through the output of cat
.
Same goes for cat /var/log/mysql.log
If you see the error there maybe putting it in the question or as a comment will help answer this faster.
If you are suffering from connection problems and the service it is actually running, try to see if the Firewall of the server is allowing connections through the 3306 port (Incoming connections). Afterwards check if the router (If it applies) has not blocked port 3306. Basically do a network test to see where the problem related to the port assigned to mysql is originated from.
If all is good, to test if the mysql service is running type service mysql status
As a last resort. If you happen to be running mysql but you can not login try the following:
Stop the MySQL Server:
sudo /etc/init.d/mysql stop
or sudo service mysql stop
Start the mysqld
service manually with manual configuration
sudo mysqld --skip-grant-tables &
(记住添加 & 否则你将不得不打开另一个终端。& 将进程发送到后台,你可以使用同一个终端终止)。
以ROOT身份登录mysql数据库
mysql -u root mysql
输入以下内容,用您的新密码替换MyPASSWORD
UPDATE user SET Password=PASSWORD('MyPASSWORD') WHERE User='root';
FLUSH PRIVILEGES;
EXIT;
这应该足以再次以 root 身份登录到您的 Mysql 服务。希望能帮助到你。