How To Install MySQL server and client on Ubuntu?

Step 1 — Installing MySQL


To install it, update the package index on your server if you’ve not done so recently:
$sudo apt update

Then install the mysql-server package:
$ sudo apt install mysql-server

Ensure that the server is running using the systemctl start command:
$ sudo systemctl start mysql.service

$ mysql
mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password by 'Rajesh$123sa332';
mysql> exit

Step 2 — Configuring MySQL – NOT WORKING WITH LATEST


For fresh installations of MySQL, you’ll want to run the DBMS’s included security script. This script changes some of the less secure default options for things like remote root logins and sample users.

Run the security script with sudo:
$ sudo mysql_secure_installation

Step 3 — Creating a Dedicated MySQL User and Granting Privileges


$ mysql -u root -p

$ CREATE USER 'sammy'@'localhost' IDENTIFIED BY 'DevOpsSchool$123';
$ GRANT ALL PRIVILEGES ON *.* TO 'sammy'@'localhost' WITH GRANT OPTION;
$ FLUSH PRIVILEGES;
$ exit
$ mysql -u sammy -p

# OPTIONAL Only for Reference
$ CREATE USER 'sammy'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';
$ ALTER USER 'sammy'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';
$ GRANT CREATE, ALTER, DROP, INSERT, UPDATE, DELETE, SELECT, REFERENCES, RELOAD on *.* TO 'sammy'@'localhost' WITH GRANT OPTION;

Rajesh Kumar
Follow me
Latest posts by Rajesh Kumar (see all)
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x