Issue
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?
Solution
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
- Make sure the installer has created the
mysql
user account. This is the account that will "own" the server process once it starts. - Change to your data directory. (I used the installer's default of
/var/lib/mysql
; you can change this by editingmy.cnf
.) As root, execute the server daemon with the
--initialize
switch. Checkwhereis
to determine the correct path, then$ sudo /path/to/mysqld --initialize --user=mysql
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 userroot
(which is not the same as the system userroot
) 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.
Answered By - Darwin von Corax Answer Checked By - Robin (WPSolving Admin)