如何在linux上启动MySQL服务器?

时间:2021-10-06 07:16:47

Pretty simple question here. I just want a SQL database on my version of Kali linux so I can practice SQL.

非常简单的问题。我只是想在我的Kali linux版本上有一个SQL数据库,这样我就可以练习SQL了。

I opened the command line and entered tried to start mysql and get an error.

我打开命令行,输入试图启动mysql并得到一个错误。

> mysql -u root
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock'

I also made sure it was already installed using apt-get.

我还确保它已经使用apt-get安装。

What are the steps I need to take to be able to make a database with tables and data that I can query?

我需要采取哪些步骤以使数据库具有可以查询的表和数据?

2 个解决方案

#1


3  

I don't know about Kali, but on Ubuntu it would be

我不知道卡莉是怎么回事,但在Ubuntu上肯定是这样

$ sudo service mysql start

Once that command returns, the mysqld service has started, so you can use the mysql client to connect to it.

一旦该命令返回,mysqld服务就启动了,因此您可以使用mysql客户端来连接它。

Of course, you also have to make sure you have the mysql-server package installed, not just mysql-client and mysql-common, and that you've initialized the database instance. Complete post-installation instructions can be found in the official documentation, but the short version is

当然,您还必须确保安装了mysql-server包,而不仅仅是mysql-client和mysql-common,并且您已经初始化了数据库实例。完整的安装后指令可以在官方文档中找到,但简短的版本是

  1. Make sure the installer has created the mysql user account. This is the account that will "own" the server process once it starts.
  2. 确保安装程序已经创建了mysql用户帐户。一旦服务器进程启动,这个帐户将“拥有”它。
  3. Change to your data directory. (I used the installer's default of /var/lib/mysql; you can change this by editing my.cnf.)
  4. 更改为您的数据目录。(我使用了安装程序默认的/var/lib/mysql;您可以通过编辑my.cnf来更改它。
  5. As root, execute the server daemon with the --initialize switch. Check whereis to determine the correct path, then

    作为根,使用-initialize开关执行服务器守护进程。那么,检查一下哪里是正确的路径

    $ sudo /path/to/mysqld --initialize --user=mysql
    
  6. This command will twiddle itself for a while, then display an automatically-generated password and exit. Once the command returns, the database instance has been initialized and the system tables created. You can now start the database instance normally (using service start), then log in as the database user root (which is not the same as the system user root) using the password from above, then change your password, create a new database user, log in as that user, create a user database, and start creating tables.

    该命令将自己旋转一段时间,然后显示自动生成的密码并退出。一旦命令返回,数据库实例就被初始化,系统表也被创建。您现在可以正常启动数据库实例(使用服务开始),然后以数据库登录用户根(根)不一样的系统用户使用密码,然后改变你的密码,创建一个新的数据库用户,登录的用户,创建一个用户数据库,并开始创建表。

Again, the official documentation is the place to look for this; if any of the instructions in the official documentation differ from my instructions, you should ignore me and follow the official documentation's instructions.

同样,官方文件是寻找这一点的地方;如果官方文件中的任何说明与我的指示不同,您应该忽略我并遵循官方文件的说明。

#2


1  

If sudo service mysql start doesn't work for you, please try running mysqld_safe and don't kill the process. Use another tab to check the status of mysql service. This should solve your mysqld.sock issue.

如果sudo服务mysql start对您不起作用,请尝试运行mysqld_safe,不要终止进程。使用另一个选项卡检查mysql服务的状态。这应该可以解决mysqld。袜子的问题。

If it doesn't work out, then please edit your my.cnf file and add the following:

如果不成功,请编辑您的my.cnf文件并添加以下内容:

socket=/var/lib/mysql/mysql.sock

And the permissions,

和权限,

sudo chmod -R 755 /var/lib/mysql/

Hopefully, this should do it.

希望这个可以做到。

#1


3  

I don't know about Kali, but on Ubuntu it would be

我不知道卡莉是怎么回事,但在Ubuntu上肯定是这样

$ sudo service mysql start

Once that command returns, the mysqld service has started, so you can use the mysql client to connect to it.

一旦该命令返回,mysqld服务就启动了,因此您可以使用mysql客户端来连接它。

Of course, you also have to make sure you have the mysql-server package installed, not just mysql-client and mysql-common, and that you've initialized the database instance. Complete post-installation instructions can be found in the official documentation, but the short version is

当然,您还必须确保安装了mysql-server包,而不仅仅是mysql-client和mysql-common,并且您已经初始化了数据库实例。完整的安装后指令可以在官方文档中找到,但简短的版本是

  1. Make sure the installer has created the mysql user account. This is the account that will "own" the server process once it starts.
  2. 确保安装程序已经创建了mysql用户帐户。一旦服务器进程启动,这个帐户将“拥有”它。
  3. Change to your data directory. (I used the installer's default of /var/lib/mysql; you can change this by editing my.cnf.)
  4. 更改为您的数据目录。(我使用了安装程序默认的/var/lib/mysql;您可以通过编辑my.cnf来更改它。
  5. As root, execute the server daemon with the --initialize switch. Check whereis to determine the correct path, then

    作为根,使用-initialize开关执行服务器守护进程。那么,检查一下哪里是正确的路径

    $ sudo /path/to/mysqld --initialize --user=mysql
    
  6. This command will twiddle itself for a while, then display an automatically-generated password and exit. Once the command returns, the database instance has been initialized and the system tables created. You can now start the database instance normally (using service start), then log in as the database user root (which is not the same as the system user root) using the password from above, then change your password, create a new database user, log in as that user, create a user database, and start creating tables.

    该命令将自己旋转一段时间,然后显示自动生成的密码并退出。一旦命令返回,数据库实例就被初始化,系统表也被创建。您现在可以正常启动数据库实例(使用服务开始),然后以数据库登录用户根(根)不一样的系统用户使用密码,然后改变你的密码,创建一个新的数据库用户,登录的用户,创建一个用户数据库,并开始创建表。

Again, the official documentation is the place to look for this; if any of the instructions in the official documentation differ from my instructions, you should ignore me and follow the official documentation's instructions.

同样,官方文件是寻找这一点的地方;如果官方文件中的任何说明与我的指示不同,您应该忽略我并遵循官方文件的说明。

#2


1  

If sudo service mysql start doesn't work for you, please try running mysqld_safe and don't kill the process. Use another tab to check the status of mysql service. This should solve your mysqld.sock issue.

如果sudo服务mysql start对您不起作用,请尝试运行mysqld_safe,不要终止进程。使用另一个选项卡检查mysql服务的状态。这应该可以解决mysqld。袜子的问题。

If it doesn't work out, then please edit your my.cnf file and add the following:

如果不成功,请编辑您的my.cnf文件并添加以下内容:

socket=/var/lib/mysql/mysql.sock

And the permissions,

和权限,

sudo chmod -R 755 /var/lib/mysql/

Hopefully, this should do it.

希望这个可以做到。