How to install MySQL on Ubuntu 14.04

Introduction

MySQL is an open source database management system, usually as the popular LAMP(Linux, Apache, MySQL, PHP/Python/Perl) stack Part of the installation. It uses relational databases and SQL (Structured Query Language) to manage its data.

Installing the short version is simple: update the package index, install the mysql-server package, and then run the included security and database initialization scripts.

sudo apt-get update
sudo apt-get install mysql-server
sudo mysql_secure_installation
sudo mysql_install_db

This tutorial will show you how to install MySQL version 5.5, 5.6 or 5.7 on an Ubuntu 14.04 server. If you want to know more details about these installation instructions, or if you want to install a specific version of MySQL, please continue reading.

Course Preparation

To follow this tutorial, you need:

Step 1-Install MySQL

There are two ways to install MySQL. You can use one of the versions (5.5 and 5.6) included in the default APT package repository, or you can manually add the MySQL repository to install the latest version (currently 5.7).

If you want to install a specific version of MySQL, then please follow the appropriate section below. To help you decide which version is best for you, you can read Introduction to MySQL to MySQL 5.5, and then you can read What’s new in MySQL 5.6 and What’s new in MySQL 5.7 Function.

If you are not sure, you can use the mysql-server APT package, which only installs the latest version for your Linux distribution. At the time of writing, this is 5.5, but you can update to another version at any time.

To install MySQL in this way, update the package index on the server and install the package with apt-get.

sudo apt-get update
sudo apt-get install mysql-server

During the installation process, you will be prompted to create a root password. Choose a secure password and make sure you remember it because you will need it later. Then proceed to the second step from here.

Install MySQL 5.5 or 5.6

If you want to specifically install MySQL 5.5 or 5.6, the process is still very simple. First, update the package index on the server.

sudo apt-get update

Then, to install MySQL 5.5, install the mysql-server-5.5 package.

sudo apt-get install mysql-server-5.5

To install MySQL 5.6, install the mysql-server-5.6 package.

sudo apt-get install mysql-server-5.6

For these two options, you will be prompted to create a root password during installation. Choose a safe one and make sure you remember it because you will need it later.

Install MySQL 5.7

If you want to install MySQL 5.7, you need to add the newer APT package repository Library from MySQL APT Repository Page. Click "Download" in the lower right corner, and then copy the link from Thank you, start downloading on the next page. Download the .deb package to your server.

wget http://dev.mysql.com/get/mysql-apt-config_0.6.0-1_all.deb

Next, install it using dpkg.

sudo dpkg -i mysql-apt-config_0.6.0-1_all.deb

You will see a prompt asking which MySQL product you want to configure. The highlighted MySQL Server option should be mysql-5.7. If not, press ENTER, then use the arrow keys to scroll down to mysql-5.7, and press ENTER again.

Once the option shows mysql-5.7, scroll down Apply on the main menu and press ENTER again. Now, update your package index.

sudo apt-get update

Finally, install the mysql-server package, which now contains MySQL 5.7.

sudo apt-get install mysql-server

During the installation process, you will be prompted to create a root password. Choose a safe one and make sure you remember it because you will need it later.

Step 2-Configure MySQL

First, you need to run the included security script. This will change some less secure default options such as remote root login and sample users.

sudo mysql_secure_installation

This will prompt you to enter the root password created in step 1. You can press ENTER to accept the default values for all subsequent questions, except for the question asking if you want to change the root password. You only need to set it in the first step, so you don't have to change it now.

Next, we will initialize the MySQL data directory, which is where MySQL stores its data. How to do this depends on the version of MySQL you are running. You can check your MySQL version with the following command.

mysql --version

You will see some output like this:

mysql  Ver 14.14 Distrib 5.7.11,forLinux(x86_64) using  EditLine wrapper

If you are using a MySQL version earlier than 5.7.6, you should initialize the data directory by running mysql_install_db.

sudo mysql_install_db

**Note: **In MySQL 5.6, you may receive an error named Fatal Error: Cannot find my-default.cnf. If you do, please copy the configuration file /usr/share/my.cnf to the desired location of mysql_install_db, and then rerun it.

sudo cp /etc/mysql/my.cnf /usr/share/mysql/my-default.cnf
sudo mysql_install_db

This is due to some changes in MySQL 5.6 and a small bug in the APT package.

Since MySQL 5.7.6, the mysql_install_db command has been deprecated. If you are using version 5.7.6 or higher, you should use mysqld --initialize.

However, if you installed version 5.7 from the Debian distribution, as in the first step, the data directory has been initialized automatically, so you don't need to do anything. If you try to run this command, you will see the following error:

2016- 03- 07 T20:11:15.998193Z 0[ERROR]--initialize specified but the data directory has files in it. Aborting.

Step 3-Test MySQL

No matter how you install it, MySQL should already start running automatically. To test it, check its status.

service mysql status

You will see the following output (with a different PID).

mysql start/running, process 2689

If MySQL is not running, you can start it with sudo service mysql start.

For other checks, you can try to connect to the database using the mysqladmin tool, which is a client that allows you to run administrative commands. For example, this command means to connect to MySQL as root (-u root), prompt for a password (-p), and return the version.

mysqladmin -p -u root version

You should see output similar to this:

mysqladmin  Ver 8.42 Distrib 5.5.47,for debian-linux-gnu on x86_64
Copyright(c)2000,2015, 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.
​
Server version      5.5.47-0ubuntu0.14.04.1
Protocol version    10
Connection      Localhost via UNIX socket
UNIX socket     /var/run/mysqld/mysqld.sock
Uptime:4 min 15 sec
​
Threads:1  Questions:602  Slow queries:0  Opens:189  Flush tables:1  Open tables:41  Queries per second avg:2.360

This means that MySQL is up and running.

in conclusion

You have now installed the basic MySQL settings on the server. Here are a few examples of next steps you can take:

For more Ubuntu tutorials, please go to [Tencent Cloud + Community] (https://cloud.tencent.com/developer?from=10680) to learn more.


Reference: "How To Install MySQL on Ubuntu 14.04"

Recommended Posts

How to install MySQL on Ubuntu 20.04
How to install MySQL on Ubuntu 20.04
How to install MySQL on Ubuntu 14.04
How to install MySQL on Ubuntu 18.04 (linux)
How to install the latest MySQL on Ubuntu 18.04
How to install MySQL on CentOS 8
How to install Ruby on Ubuntu 20.04
How to install Memcached on Ubuntu 20.04
How to install Java on Ubuntu 20.04
How to install VirtualBox on Ubuntu 20.04
How to install Elasticsearch on Ubuntu 20.04
How to install Protobuf 3 on Ubuntu
How to install Nginx on Ubuntu 20.04
How to install Apache on Ubuntu 20.04
How to install Git on Ubuntu 20.04
How to install Node.js on Ubuntu 16.04
How to install Vagrant on Ubuntu 20.04
How to install Bacula-Web on Ubuntu 14.04
How to install PostgreSQL on Ubuntu 16.04
How to install Git on Ubuntu 20.04
How to install Anaconda3 on Ubuntu 18.04
How to install mysql in Ubuntu 14.04
How to install Memcached on Ubuntu 18.04
How to install Jenkins on Ubuntu 16.04
How to install MemSQL on Ubuntu 14.04
How to install Go on Ubuntu 20.04
How to install MongoDB on Ubuntu 16.04
How to install Mailpile on Ubuntu 14.04
How to install PrestaShop on Ubuntu 16.04
How to install Skype on Ubuntu 20.04
How to install Jenkins on Ubuntu 20.04
How to install Python 3.8 on Ubuntu 18.04
How to install KVM on Ubuntu 20.04
How to install opencv3.0.0 on ubuntu14.04
How to install Anaconda on Ubuntu 20.04
How to install Prometheus on Ubuntu 16.04
How to install Apache on Ubuntu 20.04
How to install R on Ubuntu 20.04
How to install Moodle on Ubuntu 16.04
How to install Solr 5.2.1 on Ubuntu 14.04
How to install Teamviewer on Ubuntu 16.04
How to install MariaDB on Ubuntu 20.04
How to install Nginx on Ubuntu 20.04
How to install Mono on Ubuntu 20.04
How to install Go on Ubuntu 20.04
How to install Zoom on Ubuntu 20.04
How to install mysql in Ubuntu 14.04
How to install OpenCV on Ubuntu 20.04
How to install Spotify on Ubuntu 20.04
How to install Go 1.6 on Ubuntu 16.04
How to install Go on Ubuntu 18.04
How to install PostgreSQL on Ubuntu 20.04
How to install VLC on Ubuntu 18.04
How to install TeamViewer on Ubuntu 20.04
How to install Webmin on Ubuntu 20.04
Install mysql on Ubuntu 14.04
How to install Docker Compose on Ubuntu 18.04
How to install Ubuntu on Raspberry Pi
How to install Bacula Server on Ubuntu 14.04
How to install Ubuntu 19.10 on Raspberry Pi 4
How to install Apache Kafka on Ubuntu 18.04