Skip to content

Instantly share code, notes, and snippets.

@dipenparmar12
Last active April 24, 2024 10:33
Show Gist options
  • Save dipenparmar12/7cbca804d56c2cc881104070c8aaa413 to your computer and use it in GitHub Desktop.
Save dipenparmar12/7cbca804d56c2cc881104070c8aaa413 to your computer and use it in GitHub Desktop.
How To Install MySQL on Linux

How To Install MySQL on Linux

Video Tutorial

Update the system packages to the latest versions:

sudo apt update && sudo apt upgrade

Installing MySql

Run the following command to install MySql;

sudo apt install mysql-server

Now confirm the installation and check MySQL version typing following command:

mysql -V

After completing installation MySQL will start automatically. Check MySQL version by typing:

sudo systemctl status mysql

The output something like below:

mysql.service - MySQL Community Server
   Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
   Active: active (running) since Wed 2018-06-20 11:30:23 PDT; 5min ago
 Main PID: 17382 (mysqld)
    Tasks: 27 (limit: 2321)
   CGroup: /system.slice/mysql.service
           -17382 /usr/sbin/mysqld --daemonize --pid-file=/run/mysqld/mysqld.pid
Start MySql Console by typing

mysql -u root -p

Setting Up MySQL

sudo mysql_secure_installation

The above command will take you to different prompts. In the first prompt, it will ask you to configure Validate Password Plugin which is used to set password validation strength and the levels are low, medium and high. You can prefer any of the strength levels you want to set. If you don’t want to set up the Validate Password Plugin just press ENTER. In the next prompts, you will be asked questions about increasing Security of MySQL. It is recommended to answer ‘Y’ for all questions asked during secure installation.

Conclusion

You have successfully learned how to install MySQL on Linux.

Create a new MySQL User Account

A user account in MySQL consists of a user name and host name parts.

Start Mysql console

sudo mysql -u root -p

To create a new MySQL user account, run the following command:

create user 'username'@'localhost' identified by 'password';

Grant Privileges (Permissions) to a MySQL User Account

GRANT ALL PRIVILEGES ON * . * TO 'username'@'localhost';

Syntax: GRANT ALL PRIVILEGES ON DbName.TableName TO 'username'@'localhost';

Display MySQL User Account Privileges

SHOW GRANTS FOR 'username'@'localhost';

Revoke Privileges from a MySQL User Account

REVOKE ALL PRIVILEGES ON database_name.* FROM 'database_user'@'localhost';

Remove an Existing MySQL User Account

DROP USER 'username'@'localhost';

Extra

FLUSH PRIVILEGES;

FLUSH PRIVILEGES Reloads the grant tables in the mysql database enabling the changes to take effect without reloading or restarting mysql service.

@anigobi
Copy link

anigobi commented Apr 24, 2024

┌──(root㉿localhost)-[/home/kali]
└─# sudo apt install mysql-server
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Package mysql-server is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source

E: Package 'mysql-server' has no installation candidate

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment