How To Install the Latest MySQL on Debian 9

Introduction

MySQL is a prominent open source database management system used to store and retrieve data for a wide variety of popular applications. MySQL is the M in the LAMP stack, a commonly used set of open source software that also includes Linux, the Apache web server, and the PHP programming language.

In Debian 9, MariaDB, a community fork of the MySQL project, is packaged as the default MySQL variant. While, MariaDB works well in most cases, if you need features found only in Oracle's MySQL, you can install and use packages from a repository maintained by the MySQL developers.

To install the latest version of MySQL, we'll add this repository, install the MySQL software itself, secure the install, and finally we'll test that MySQL is running and responding to commands.

Prerequisites

Before starting this tutorial, you will need:

Step 1 — Adding the MySQL Software Repository

The MySQL developers provide a .deb package that handles configuring and installing the official MySQL software repositories. Once the repositories are set up, we'll be able to use Ubuntu's standard aptcommand to install the software. We'll download this .deb file with wget and then install it with the dpkgcommand.

First, load the MySQL download page in your web browser. Find the Download button in the lower-right corner and click through to the next page. This page will prompt you to log in or sign up for an Oracle web account. We can skip that and instead look for the link that says No thanks, just start my download. Right-click the link and select Copy Link Address (this option may be worded differently, depending on your browser).

Now we're going to download the file. On your server, move to a directory you can write to. Download the file using wget, remembering to paste the address you just copied in place of the highlighted portion below:

cd /tmp
wget https://dev.mysql.com/get/mysql-apt-config_0.8.10-1_all.deb

The file should now be downloaded in our current directory. List the files to make sure:

ls

You should see the filename listed:

Outputmysql-apt-config_0.8.10-1_all.deb
. . .

Now we're ready to install:

sudo dpkg -i mysql-apt-config*

dpkg is used to install, remove, and inspect .deb software packages. The -i flag indicates that we'd like to install from the specified file.

During the installation, you'll be presented with a configuration screen where you can specify which version of MySQL you'd prefer, along with an option to install repositories for other MySQL-related tools. The defaults will add the repository information for the latest stable version of MySQL and nothing else. This is what we want, so use the down arrow to navigate to the Ok menu option and hit ENTER.

The package will now finish adding the repository. Refresh your apt package cache to make the new software packages available:

sudo apt update

Now that we've added the MySQL repositories, we're ready to install the actual MySQL server software. If you ever need to update the configuration of these repositories, just run sudo dpkg-reconfigure mysql-apt-config, select new options, and then sudo apt-get update to refresh your package cache.

Step 2 — Installing MySQL

Having added the repository and with our package cache freshly updated, we can now use apt to install the latest MySQL server package:

sudo apt install mysql-server

apt will look at all available mysql-server packages and determine that the MySQL provided package is the newest and best candidate. It will then calculate package dependencies and ask you to approve the installation. Type y then ENTER. The software will install.

You will be asked to set a root password during the configuration phase of the installation. Choose and confirm a secure password to continue. Next, a prompt will appear asking for you to select a default authentication plugin. Read the display to understand the choices. If you are not sure, choosing Use Strong Password Encryption is safer.

MySQL should be installed and running now. Let's check using systemctl:

sudo systemctl status mysql

Output● mysql.service - MySQL Community Server
   Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
   Active: active (running) since Wed 2018-09-05 15:58:21 UTC; 30s ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
 Main PID: 12805 (mysqld)
   Status: "SERVER_OPERATING"
   CGroup: /system.slice/mysql.service
           └─12805 /usr/sbin/mysqld

Sep 05 15:58:15 mysql1 systemd[1]: Starting MySQL Community Server...
Sep 05 15:58:21 mysql1 systemd[1]: Started MySQL Community Server.

The Active: active (running) line means MySQL is installed and running. Now we'll make the installation a little more secure.

Step 3 — Securing MySQL

MySQL comes with a command we can use to perform a few security-related updates on our new install. Let's run it now:

mysql_secure_installation

This will ask you for the MySQL root password that you set during installation. Type it in and press ENTER. Now we'll answer a series of yes or no prompts. Let's go through them:

First, we are asked about the validate password plugin, a plugin that can automatically enforce certain password strength rules for your MySQL users. Enabling this is a decision you'll need to make based on your individual security needs. Type y and ENTER to enable it, or just hit ENTER to skip it. If enabled, you will also be prompted to choose a level from 0–2 for how strict the password validation will be. Choose a number and hit ENTER to continue.

Next you'll be asked if you want to change the root password. Since we just created the password when we installed MySQL, we can safely skip this. Hit ENTER to continue without updating the password.

The rest of the prompts can be answered yes. You will be asked about removing the anonymous MySQL user, disallowing remote root login, removing the test database, and reloading privilege tables to ensure the previous changes take effect properly. These are all a good idea. Type y and hit ENTER for each.

The script will exit after all the prompts are answered. Now our MySQL installation is reasonably secured. Let's test it again by running a client that connects to the server and returns some information.

Step 4 – Testing MySQL

mysqladmin is a command line administrative client for MySQL. We'll use it to connect to the server and output some version and status information:

mysqladmin -u root -p version

The -u root portion tells mysqladmin to log in as the MySQL root user, -p instructs the client to ask for a password, and version is the actual command we want to run.

The output will let us know what version of the MySQL server is running, its uptime, and some other status information:

Outputmysqladmin  Ver 8.0.12 for Linux on x86_64 (MySQL Community Server - GPL)
Copyright (c) 2000, 2018, 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      8.0.12
Protocol version    10
Connection      Localhost via UNIX socket
UNIX socket     /var/run/mysqld/mysqld.sock
Uptime:         6 min 42 sec

Threads: 2  Questions: 12  Slow queries: 0  Opens: 123  Flush tables: 2  Open tables: 99  Queries per second avg: 0.029

If you received similar output, congrats! You've successfully installed the latest MySQL server and secured it.

Conclusion

You've now completed a basic install of the latest version of MySQL, which should work for many popular applications.

?著作權歸作者所有,轉載或內容合作請聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市宇葱,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌磷斧,老刑警劉巖动分,帶你破解...
    沈念sama閱讀 216,544評論 6 501
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件毅糟,死亡現(xiàn)場離奇詭異,居然都是意外死亡澜公,警方通過查閱死者的電腦和手機姆另,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,430評論 3 392
  • 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來坟乾,“玉大人迹辐,你說我怎么就攤上這事∩趼拢” “怎么了明吩?”我有些...
    開封第一講書人閱讀 162,764評論 0 353
  • 文/不壞的土叔 我叫張陵,是天一觀的道長殷费。 經常有香客問我印荔,道長,這世上最難降的妖魔是什么详羡? 我笑而不...
    開封第一講書人閱讀 58,193評論 1 292
  • 正文 為了忘掉前任仍律,我火速辦了婚禮,結果婚禮上实柠,老公的妹妹穿的比我還像新娘水泉。我一直安慰自己,他們只是感情好窒盐,可當我...
    茶點故事閱讀 67,216評論 6 388
  • 文/花漫 我一把揭開白布草则。 她就那樣靜靜地躺著,像睡著了一般蟹漓。 火紅的嫁衣襯著肌膚如雪炕横。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 51,182評論 1 299
  • 那天牧牢,我揣著相機與錄音看锉,去河邊找鬼。 笑死塔鳍,一個胖子當著我的面吹牛伯铣,可吹牛的內容都是我干的。 我是一名探鬼主播轮纫,決...
    沈念sama閱讀 40,063評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼腔寡,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了掌唾?” 一聲冷哼從身側響起放前,我...
    開封第一講書人閱讀 38,917評論 0 274
  • 序言:老撾萬榮一對情侶失蹤忿磅,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后凭语,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體葱她,經...
    沈念sama閱讀 45,329評論 1 310
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內容為張勛視角 年9月15日...
    茶點故事閱讀 37,543評論 2 332
  • 正文 我和宋清朗相戀三年似扔,在試婚紗的時候發(fā)現(xiàn)自己被綠了吨些。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 39,722評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡炒辉,死狀恐怖豪墅,靈堂內的尸體忽然破棺而出,到底是詐尸還是另有隱情黔寇,我是刑警寧澤偶器,帶...
    沈念sama閱讀 35,425評論 5 343
  • 正文 年R本政府宣布,位于F島的核電站缝裤,受9級特大地震影響屏轰,放射性物質發(fā)生泄漏。R本人自食惡果不足惜倘是,卻給世界環(huán)境...
    茶點故事閱讀 41,019評論 3 326
  • 文/蒙蒙 一亭枷、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧搀崭,春花似錦、人聲如沸猾编。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,671評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽答倡。三九已至轰传,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間瘪撇,已是汗流浹背获茬。 一陣腳步聲響...
    開封第一講書人閱讀 32,825評論 1 269
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留倔既,地道東北人恕曲。 一個月前我還...
    沈念sama閱讀 47,729評論 2 368
  • 正文 我出身青樓,卻偏偏與公主長得像渤涌,于是被迫代替她去往敵國和親佩谣。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當晚...
    茶點故事閱讀 44,614評論 2 353

推薦閱讀更多精彩內容