Jmaurier Jmaurier - 1 year ago 59
SQL Question

How do you start a SQL server on linux?

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

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

> 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.

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

Answer Source

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

$ sudo service mysql start

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

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

  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. Change to your data directory. (I used the installer's default of /var/lib/mysql; you can change this by editing my.cnf.)
  3. As root, execute the server daemon with the --initialize switch. Check whereis to determine the correct path, then

    $ 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.

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download