在Debian Jessie中安装MySQL(8)

在Debian Jessie中安装MySQL(8)

我是 Linux 新手,新安装了 Debian Jessie (8) 操作系统,需要使用 MySQL。主机名是,

hostname -f

它打印,debian8

当我在终端中输入时,

sudo dpkg --get-selections | grep mysql

我得到输出,

libdbd-mysql-perl               install
libmysqlclient18:amd64              install
mysql-client-5.5                install
mysql-common                    install
mysql-server                    install
mysql-server-5.5                install
mysql-server-core-5.5               install
php5-mysql                  install

当我在终端中输入时,

sudo apt-cache show mysql

输出是,

N: Unable to locate package mysql
E: No packages found
chaklader@debian8:/home/cx-components$ 

当我在终端中输入时,

locate mysql

输出是,

/usr/lib/libreoffice/program/libmysqllo.so
/usr/share/bash-completion/completions/mysql
/usr/share/bash-completion/completions/mysqladmin
/usr/share/nmap/nselib/mysql.lua
/usr/share/nmap/nselib/data/mysql-cis.audit
/usr/share/nmap/scripts/mysql-audit.nse
/usr/share/nmap/scripts/mysql-brute.nse
/usr/share/nmap/scripts/mysql-databases.nse
/usr/share/nmap/scripts/mysql-dump-hashes.nse
/usr/share/nmap/scripts/mysql-empty-password.nse
/usr/share/nmap/scripts/mysql-enum.nse
/usr/share/nmap/scripts/mysql-info.nse
/usr/share/nmap/scripts/mysql-query.nse
/usr/share/nmap/scripts/mysql-users.nse
/usr/share/nmap/scripts/mysql-variables.nse
/usr/share/nmap/scripts/mysql-vuln-cve2012-2122.nse

当我在终端中输入时, which mysql

没有输出。

当我在终端中输入时,

mysql -u root -p

输出是,

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

MySQL 是否安装在操作系统中,如果没有安装如何安装?

更新:

正如所建议的,MySQL 服务器没有启动。因此,我使用以下命令启动服务器,

sudo /etc/init.d/mysql start

输出如下:

[....] Starting mysql (via systemctl): mysql.service
Job for mysql.service failed. See 'systemctl status mysql.service' and 'journalctl -xn' for details.
 failed!

建议查找相关命令的更详细信息,这是错误的。

我输入终端,

sudo systemctl status mysql.service

我得到提供的输出,

● mysql.service - LSB: Start and stop the mysql database server daemon
   Loaded: loaded (/etc/init.d/mysql)
   Active: failed (Result: exit-code) since Sun 2017-12-17 21:10:21 +06; 1min 10s ago
  Process: 28321 ExecStart=/etc/init.d/mysql start (code=exited, status=1/FAILURE)

Dec 17 21:09:50 debian8 systemd[1]: Starting LSB: Start and stop the mysql .....
Dec 17 21:10:21 debian8 /etc/init.d/mysql[29152]: 0 processes alive and '/usr...
Dec 17 21:10:21 debian8 /etc/init.d/mysql[29152]: [61B blob data]
Dec 17 21:10:21 debian8 /etc/init.d/mysql[29152]: error: 'Can't connect to lo...
Dec 17 21:10:21 debian8 /etc/init.d/mysql[29152]: Check that mysqld is runnin...
Dec 17 21:10:21 debian8 /etc/init.d/mysql[29152]: 
Dec 17 21:10:21 debian8 mysql[28321]: Starting MySQL database server: mysql...d!
Dec 17 21:10:21 debian8 systemd[1]: mysql.service: control process exited, ...=1
Dec 17 21:10:21 debian8 systemd[1]: Failed to start LSB: Start and stop the...n.
Dec 17 21:10:21 debian8 systemd[1]: Unit mysql.service entered failed state.
Hint: Some lines were ellipsized, use -l to show in full.

其次,我输入下面提供的命令journalctl

sudo journalctl -xn

输出是,

-- Logs begin at Sun 2017-12-17 10:33:35 +06, end at Sun 2017-12-17 21:12:02 +06
Dec 17 21:10:21 debian8 mysql[28321]: Starting MySQL database server: mysqld . .
Dec 17 21:10:21 debian8 systemd[1]: mysql.service: control process exited, code=
Dec 17 21:10:21 debian8 systemd[1]: Failed to start LSB: Start and stop the mysq
-- Subject: Unit mysql.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- Unit mysql.service has failed.
-- 
-- The result is failed.
Dec 17 21:10:21 debian8 systemd[1]: Unit mysql.service entered failed state.
Dec 17 21:10:21 debian8 sudo[28307]: pam_unix(sudo:session): session closed for 
Dec 17 21:11:32 debian8 sudo[29437]: chaklader : TTY=pts/0 ; PWD=/home/chaklader
Dec 17 21:11:32 debian8 sudo[29437]: pam_unix(sudo:session): session opened for 
Dec 17 21:11:32 debian8 sudo[29437]: pam_unix(sudo:session): session closed for 
Dec 17 21:12:02 debian8 sudo[29539]: chaklader : TTY=pts/0 ; PWD=/home/chaklader
Dec 17 21:12:02 debian8 sudo[29539]: pam_unix(sudo:session): session opened for 
lines 1-18/18 (END)

所以,基本上,首先要做的就是正确运行 MySQL 服务器。

我也尝试过运行服务器,

sudo systemctl start mysql.serivce

提供的输出,

Failed to start mysql.serivce.service: Unit mysql.serivce.service failed to load: No such file or directory.

为此我需要采取哪些步骤?

Note:

正如评论中所问,在我执行命令时,

sudo systemctl status mysql.service -l

我得到的输出是这样的

● mysql.service - LSB: Start and stop the mysql database server daemon
   Loaded: loaded (/etc/init.d/mysql)
   Active: failed (Result: exit-code) since Sun 2017-12-17 21:10:21 +06; 14min ago
  Process: 28321 ExecStart=/etc/init.d/mysql start (code=exited, status=1/FAILURE)

Dec 17 21:09:50 debian8 systemd[1]: Starting LSB: Start and stop the mysql database server daemon...
Dec 17 21:10:21 debian8 /etc/init.d/mysql[29152]: 0 processes alive and '/usr/bin/mysqladmin --defaults-file=/etc/mysql/debian.cnf ping' resulted in
Dec 17 21:10:21 debian8 /etc/init.d/mysql[29152]: [61B blob data]
Dec 17 21:10:21 debian8 /etc/init.d/mysql[29152]: error: 'Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)'
Dec 17 21:10:21 debian8 /etc/init.d/mysql[29152]: Check that mysqld is running and that the socket: '/var/run/mysqld/mysqld.sock' exists!
Dec 17 21:10:21 debian8 /etc/init.d/mysql[29152]: 
Dec 17 21:10:21 debian8 mysql[28321]: Starting MySQL database server: mysqld . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . failed!
Dec 17 21:10:21 debian8 systemd[1]: mysql.service: control process exited, code=exited status=1
Dec 17 21:10:21 debian8 systemd[1]: Failed to start LSB: Start and stop the mysql database server daemon.
Dec 17 21:10:21 debian8 systemd[1]: Unit mysql.service entered failed state.

我主要需要做的是使用以下命令迁移数据库,

/home/cx-components/cx-admin/app/console doctrine:migrations:migrate

我得到的输出是这样的

                    Application Migrations                    

  [PDOException]                                                             
  SQLSTATE[HY000] [2003] Can't connect to MySQL server on '127.0.0.1' (111)  

doctrine:migrations:migrate [--write-sql] [--dry-run] [--query-time] [--configuration[="..."]] [--db-configuration[="..."]] [--db="..."] [--em="..."] [version]

这里有什么问题呢?

正如评论中提到的,我更正了拼写错误并再次运行命令, sudo systemctl start mysql.service

输出在这里,

Job for mysql.service failed. See 'systemctl status mysql.service' and 'journalctl -xn' for details.

答案1

根据 的输出sudo dpkg --get-selections | grep mysql,安装 MySQL(客户端工具和服务器)。

运行时收到的错误消息mysql表明 MySQL 服务未运行。你可以这样开始:

sudo service mysql start
# or: sudo systemctl start mysql

相关内容