In this article, We are going to Perform How to install MySQL 5.7 on Ubuntu 18.04 LTS using command line.
MySQL is the world’s most popular open source relational database management system. It is widely used with web server like apache2,Nginx,IIS,etc.
MySQL has client/Server architecture , supports InnoDB storage engine,can be installed on various operating system like Ubuntu,Debian,CentOS,Windows.,etc.
#1: Add MySQL APT Repository in Ubuntu
Ubuntu comes with default package repositories. So,if we want to add/install latest repositories then we have to add/install package repositories.
Below are commands to add/download latest MySQL APT repository using command line,
sudo wget https://dev.mysql.com/get/mysql-apt-config_0.8.15-1_all.deb
https://dev.mysql.com/get/mysql-apt-config_0.8.15-1_all.deb Resolving dev.mysql.com (dev.mysql.com)... 184.108.40.206 Connecting to dev.mysql.com (dev.mysql.com)|220.127.116.11|:443... connected. HTTP request sent, awaiting response... 302 Found Location: https://repo.mysql.com//mysql-apt-config_0.8.15-1_all.deb [following] --2020-04-24 10:43:27-- https://repo.mysql.com//mysql-apt-config_0.8.15-1_all.deb Resolving repo.mysql.com (repo.mysql.com)... 18.104.22.168 Connecting to repo.mysql.com (repo.mysql.com)|22.214.171.124|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 35532 (35K) [application/x-debian-package] Saving to: ‘mysql-apt-config_0.8.15-1_all.deb’ mysql-apt-config_0.8.15-1_all.deb 100%[=====================================================================================>] 34.70K --.-KB/s in 0.01s 2020-04-24 10:43:27 (2.71 MB/s) - ‘mysql-apt-config_0.8.15-1_all.deb’ saved [35532/35532]
then, below command is to install above downloaded apt repository,
sudo dpkg -i mysql-apt-config_0.8.15-1_all.deb
when we run above command like below prompt will open, By default it shows MySQL 8.0
Click on First Option and Select MySQL 5.7 and Press Tab Button
Press Tab Button and Enter
#2: Update MySQL Repository
Update apt repository
sudo apt-get update
#3: Install MySQL 5.7 on Ubuntu 18.04 LTS
Install MySQL 5.7 using below commands,
sudo apt-get install mysql-server
Now, Installation process will prompt default password for root user and again same password.
#4: Secure MySQL Installation
MySQL Server comes with a script mysql_secure_installation this can do multiple security related operations,
Run the below script on command prompt, asks below options.
mysql_secure_installation Securing the MySQL server deployment. Enter password for user root: Would you like to setup VALIDATE PASSWORD plugin? Press y|Y for Yes, any other key for No: No Change the password for root ? ((Press y|Y for Yes, any other key for No) : No Remove anonymous users? (Press y|Y for Yes, any other key for No) : y Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y Success. All done!
#5: Login to MySQL
Now, Login to MySQL 5.7 Server using below command and use password to login entered during installation.
mysql -u root -p
Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 4 Server version: 5.7.29 MySQL Community Server (GPL) 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.
Now, We have successfully covered install MySQL 5.7 on Ubuntu 18.04 LTS.
#6: Create MySQL Remote User
First, Login to MySQL Server with root user using command line, Below is command is to create user , here i am creating user “fosstechnix“.
mysql> CREATE USER 'fosstechnix'@'%' IDENTIFIED BY '[email protected]';
Next, assign the privileges to database with below command , here i am assigning all databases privileges to user fosstechnix,
If you want to assign privileges to specific database replace ” .” with database name.
mysql> GRANT ALL PRIVILEGES ON * . * TO 'fosstechnix'@'%';
if you want to allow “fosstechnix” user to give privileges to other user.
mysql> GRANT ALL PRIVILEGES ON *.* TO 'fosstechnix'@'%' WITH GRANT OPTION;
To take effect reload the privileges using below command,
mysql> FLUSH PRIVILEGES;
#7: How to Enable MySQL Remote Access in Ubuntu
By default, In MySQL database server remote access is disabled for security reason.
To enable remote connections of MySQL Server, we have to change bind-address in MySQL configuration file.
Open the /etc/mysql/mysql.conf.d/mysqld.cnf file
sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf
Below the [mysqld] section find the Line,
[mysqld] bind-address = 127.0.0.1
And replace it to
bind-address = 0.0.0.0
Restart the MySQL Server to take effect.
sudo systemctl restart mysql.service
#8: Start/Restart/Stop MySQL Server Using Command Line
Below are commands to start/restart/stop MySQL 5.7 on Ubuntu 16.04
sudo systemctl start mysql.service sudo systemctl restart mysql.service sudo systemctl stop mysql.service
In this article, We have performed ,How to Install MySQL 5.7 on Ubuntu 18.04 LTS System, creating new user and enabled remote access.