简体   繁体   English

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

[英]How do you start a MySQL server on linux?

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? 为了使数据库具有可以查询的表和数据,我需要采取什么步骤?

I don't know about Kali, but on Ubuntu it would be 我不了解Kali,但是在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. 当然,还必须确保已安装mysql-server软件包,而不仅仅是mysql-clientmysql-common ,并且已经初始化了数据库实例。 Complete post-installation instructions can be found in the official documentation , but the short version is 完整的安装后说明可在官方文档中找到,但简称为

  1. Make sure the installer has created the mysql user account. 确保安装程序已创建mysql用户帐户。 This is the account that will "own" the server process once it starts. 这是启动服务器进程后将“拥有”服务器进程的帐户。
  2. Change to your data directory. 转到您的数据目录。 (I used the installer's default of /var/lib/mysql ; you can change this by editing my.cnf .) (我使用了安装程序的默认值/var/lib/mysql ;您可以通过编辑my.cnf来更改此设置。)
  3. As root, execute the server daemon with the --initialize switch. 以root用户--initialize使用--initialize开关执行服务器守护程序。 Check whereis to determine the correct path, then 检查whereis以确定正确的路径,然后

     $ sudo /path/to/mysqld --initialize --user=mysql 
  4. 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. 您现在可以正常启动数据库实例(使用service start ),然后登录的数据库用户 root (这是一样的系统用户root使用从上面的密码),然后再更改密码,创建一个新的数据库用户,以用户身份登录,创建用户数据库,然后开始创建表。

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. 如果官方文档任何说明与我的说明有所不同,则应忽略我并遵循官方文档中的说明。

If sudo service mysql start doesn't work for you, please try running mysqld_safe and don't kill the process. 如果sudo service mysql start对您不起作用,请尝试运行mysqld_safe ,不要杀死该进程。 Use another tab to check the status of mysql service. 使用另一个选项卡检查mysql服务的状态。 This should solve your mysqld.sock issue. 这应该可以解决您的mysqld.sock问题。

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. 希望这应该做到。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM