mysql installation

  1. To install the MySQL server, use the following command:
    $ sudo apt-get update
    $ sudo apt-get install mysql-server-5.7
    
    The installation process will download the necessary packages and then prompt you to enter a password for the MySQL root account. Choose a strong password:
  2. Once the installation process is complete, you can check the server status with the following command. It should return an output similar to the following:
    $ sudo service mysql status
    mysql.service - MySQL Community Server
      Loaded: loaded (/lib/systemd/system/mysql.service
      Active: active (running) since Tue 2016-05-10 05:
    
  3. Next, create a copy of the original configuration file:
    $ cd /etc/mysql/mysql.conf.d
    $ sudo cp mysqld.cnf mysqld.cnf.bkp
    
  4. Set MySQL to listen for a connection from network hosts. Open the configuration file /etc/mysql/mysql.conf.d/mysqld.cnf and change bind-address under the [mysqld]section to your server’s IP address:
    $ sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf
    bind-address = 10.0.2.6
    

    NOTE

    For MySQL 5.5 and 5.6, the configuration file can be found at /etc/mysql/my.cnf
  5. Optionally, you can change the default port used by the MySQL server. Find the [mysqld] section in the configuration file and change the value of the port variable as follows:
    port = 30356
    
    Make sure that the selected port is available and open under firewall.
  6. Save the changes to the configuration file and restart the MySQL server:
    $ sudo service mysql restart
    
  7. Now open a connection to the server using the MySQL client. Enter the password when prompted:
    $ mysql -u root -p
    
  8. To get a list of available commands, type \h:
    mysql> \h

How it works…

MySQL is a default database server available in Ubuntu. If you are installing the Ubuntu server, you can choose MySQL to be installed by default as part of the LAMP stack. In this recipe, we have installed the latest production release of MySQL (5.7) from the Ubuntu package repository. Ubuntu 16.04 contains MySQL 5.7, whereas Ubuntu 14.04 defaults to MySQL version 5.5.
If you prefer to use an older version on Ubuntu 16, then use following command:
$ sudo add-apt-repository ‘deb http://archive.ubuntu.com/ubuntu trusty universe’
$ sudo apt-get update
$ sudo apt-get install mysql-server-5.6
After installation, configure the MySQL server to listen for connections from external hosts. Make sure that you open your database installation to trusted networks such as your private network. Making it available on the Internet will open your database to attackers.

There’s more…

SECURING MYSQL INSTALLATION

MySQL provides a simple script to configure basic settings related to security. Execute this script before using your server in production:
$ mysql_secure_installation
This command will start a basic security check, starting with changing the root password. If you have not set a strong password for the root account, you can do it now. Other settings include disabling remote access to the root account and removing anonymous users and unused databases.
MySQL is popularly used with PHP. You can easily install PHP drivers for MySQL with the following command:
$ sudo apt-get install php7.0-mysql

See also

Comments

Popular posts from this blog

HAproxy logging

tomcat catalina coyote jasper cluster

NFS mount add in fstab _netdev instead of default | firewall-cmd --list-all