Search This Blog

Saturday, November 7, 2020

Install MySQL on Ubuntu (18.04)

Type below commands in your terminals. 

First five commands are NOT required if you don't have any earlier version of mysql in your system. 

sudo apt-get remove --purge mysql*

sudo apt-get purge mysql*

sudo apt-get autoremove

sudo apt-get autoclean

sudo apt-get remove dbconfig-mysql

sudo apt-get dist-upgrade

sudo apt-get install mysql-server


This will install mysql without prompting for a password.

Use the cat command to view the default password.

sudo cat /etc/mysql/debian.cnf

======= the sample output will be========

# Automatically generated for Debian scripts. DO NOT TOUCH!

[client]

host     = localhost

user     = debian-sys-maint

password = it3vqmn8mXIBBama

socket   = /var/run/mysqld/mysqld.sock

[mysql_upgrade]

host     = localhost

user     = debian-sys-maint

password = it3vqmn8mXIBBama

socket   = /var/run/mysqld/mysqld.sock

==================


mysql -udebian-sys-maint -p

Log in with the default password as given in above file. In this example password is it3vqmn8mXIBBama (copy and paste this password after above command)


You will enter into mysql teriminal.
Change password.  ( In this example i am setting the password to root for user root)

UPDATE mysql.user SET authentication_string=PASSWORD('root'), PLUGIN='mysql_native_password' WHERE USER='root';

Exit from the mysql terminal (type exit)

exit

Restart the service 
/etc/init.d/mysql restart

Try to login with user root  (Type the password as root)
mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.32-0ubuntu0.18.04.1 (Ubuntu)

Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.03 sec)

mysql> create database test;
Query OK, 1 row affected (0.41 sec)

mysql> use test;
Database changed
mysql> 

Try to perform some basic queries as given in this file.
(If you are a beginner in SQL)


No comments: