Jackie
Jackie

Reputation: 129

How to install mysql on linux machine

How to install mysql on Linux machine ?

  1. I tried with 'sudo apt-get install mysql-server' , but it resulted into E: Unable to locate package mysql-server.

  2. Downloaded mysql-server_5.7.18-1ubuntu16.10_amd64.deb-bundle.tar , how do i install it ???

  3. After successful installation, other machines should be able to access to this DB. How to do that ? Any server concept ?

Could you please help me here ?

Upvotes: 0

Views: 2776

Answers (4)

mary_zach
mary_zach

Reputation: 61

Noob here, who needed something similar.

  1. Check https://www.digitalocean.com/community/tutorials/how-to-install-the-latest-mysql-on-debian-10 This solved the "Unable to locate package mysql-server" bit for me.

  2. The link also explains how to directly install the package on CLI using wget, instead of downloading a package.

  3. Check if port 3306 (or whichever port your MySQL server is configured to) on the machine that MySQL is installed on, is open and listening. You could check this from a remote machine using nc -vz <ip address of mysql server> <port number> or even using telnet.

Create a user on mysql, and grant suitable permissions: mysql> CREATE USER 'newuser'@'%' IDENTIFIED BY 'password'; mysql> GRANT ALL PRIVILEGES ON * . * TO 'newuser'@'%'; (The % symbol implies that users from any IP can access this database)

You might need to configure mysql-connector on the remote machine, if you're using python to connect to this database. Here's a simple check to see if you're connected:

import mysql.connector
from mysql.connector import Error

try:
    connection = mysql.connector.connect(host='YOUR_MYSQL_IP_ADDRESS',
                                        port = 3306,
                                         database='YOUR_DB_NAME',
                                         user='YOUR_USERNAME',
                                         password='YOUR_PASSWORD',
                                         charset = 'utf8mb4',
                                         )
    if connection.is_connected():
        db_Info = connection.get_server_info()
        print("Connected to MySQL Server version ", db_Info)
        cursor = connection.cursor()
        cursor.execute("select database();")
        record = cursor.fetchone()
        print("You're connected to database: ", record)

except Error as e:
    print("Error while connecting to MySQL", e)

finally:
    if connection.is_connected():
        cursor.close()
        connection.close()
        print("MySQL connection is closed")

Else, if you're just looking to connect to your mysql server remotely using the terminal, you might have to install mysql-client first. After this, you could: mysql -h <YOUR_MYSQL_IP_ADDRESS> -u <YOUR_USERNAME> -p <YOUR_PASSWORD> <YOUR_DB_NAME>

Upvotes: 0

Mukesh Bhati
Mukesh Bhati

Reputation: 634

sudo apt-get update
sudo apt-get install mysql-server
sudo ufw allow mysql
systemctl start mysql
sudo /usr/bin/mysql -u root -p
use mysql;
update user set authentication_string=password('set_new_password') where user='root';
sudo mysql -u root -p
enter your new password

booom done!

Upvotes: 0

Vivek Sharma
Vivek Sharma

Reputation: 11

After downloading the tarball, unpack it with the following command:

shell> tar -xvf mysql-server_5.7.18-1ubuntu16.10_amd64.deb-bundle.tar

Note: The exact file name can differ (version).

You may need to install the libaio library if it is not already present on your system:

shell> sudo apt-get install libaio1

Preconfigure the MySQL server package with the following command:

shell> sudo dpkg-preconfigure mysql-community-server_5.7.18.deb

Please check the following reference for more details

https://dev.mysql.com/doc/refman/5.7/en/linux-installation-debian.html

Upvotes: 1

CPR
CPR

Reputation: 773

You need to enable the "Universe" repository on your machine and then do an apt-get update before installing. Follow this guide if you're unsure.https://help.ubuntu.com/community/Repositories/CommandLine#Adding_the_Universe_and_Multiverse_Repositories

Upvotes: 0

Related Questions