How to install MySQL database on Debian 9 system

How to install MySQL database on Debian 9 system

Preface

Seeing the title, everyone should be thinking, how to install MySQL on Debian 9? Isn't that a simple thing? Wouldn't it be OK to just sudo apt install mysql-server ?

Unexpectedly, I encountered several problems that I had never encountered before, which wasted a lot of time.

It turns out that in Debian 9, MySQL has been replaced by MariaDB, so there are some differences from the traditional installation of MySQL.

Installation Method

First of all, we can still install it with sudo apt install mysql-server , but what is installed is still MariaDB, so it is better to use sudo apt install mariadb-server .

After installing it, I found that it was different from the traditional one because the blue interface for setting a password did not pop up. I mistakenly thought that I could log in directly with an empty password. I tried mysql -uroot -p directly and found ERROR 1698 (28000): Access denied for user 'root'@'localhost' . Isn't the default password empty? Check /etc/mysql/debian.cnf and you will see that the default password is indeed empty.

The first reaction is to execute mysqld_safe skip-grant-tables , then use mysql; and then update user set password=PASSWORD('mysql') where User='root'; ;. This does solve the problem, but after restarting I inexplicably found that I couldn't log in again.

After a while, I found that the default password of MaraiDB is indeed empty, but I can only log in with the root user

Note: The user here refers to the root user of the Linux system. That is to say, after you enter the root terminal with sudo su, you can log in normally, but ordinary users cannot log in. (To distinguish them, I capitalized the first letter of the Root terminal and lowered the first letter of the mysql root user)

I think we understand now, so we can't just use the root user for convenience. The correct way should be like this:

First, install the database using sudo apt install mariadb-server .

Then sudo su switch to the root terminal, log in to the database through mariadb -uroot -p , if the default password is not empty, you can view '/etc/mysql/debian.cnf'.

What you need to do now is to create a new user: create user 'admin'@'localhost' identified by 'mysql' .

Then set permissions for the new user: grant all on *.* to 'admin'@'localhost' .

OK, we have set up another convenient "Root" user, but changed its name to admin.

PS: I found that in the Root terminal, no matter what password I entered, I could connect to the database normally... dizzy.

Summarize

The above is the full content of this article. I hope that the content of this article will have certain reference learning value for your study or work. If you have any questions, you can leave a message to communicate. Thank you for your support for 123WORDPRESS.COM.

You may also be interested in:
  • How to completely uninstall MySQL in Debian
  • How to configure mysql on debian6 to allow remote connections (picture)
  • How to compile and install MySQL 5.5 under Debian 6.02 (squeeze)
  • The ultimate solution to the problem that Mysql cannot insert Chinese characters in the Debian system
  • How to uninstall MySQL on a server running Ubuntu or Debian
  • Tutorial on configuring Python+Django+Nginx+uWSGI+MySQL on Debian

<<:  Detailed steps for deploying https websites and configuring address rewriting in Nginx

>>:  React example showing file upload progress

Recommend

Detailed explanation of mkdir command in Linux learning

Table of contents Preface 1. Basic knowledge of f...

A simple method to implement Linux timed log deletion

Introduction Linux is a system that can automatic...

Configure Mysql master-slave service implementation example

Configure Mysql master-slave service implementati...

HTML page common style (recommended)

As shown below: XML/HTML CodeCopy content to clip...

Detailed steps for porting busybox to build a minimal root file system

Busybox: A Swiss Army knife filled with small com...

Web Design Summary

<br />From the birth of my first personal pa...

nuxt.js multiple environment variable configuration

Table of contents 1. Introduction 2. Scenario 3. ...

Summary of react basics

Table of contents Preface start React Lifecycle R...

Navicat connection MySQL error description analysis

Table of contents environment Virtual Machine Ver...

How to install iso file in Linux system

How to install iso files under Linux system? Inst...

Summary of the use of vue Watch and Computed

Table of contents 01. Listener watch (1) Function...

Complete steps for using Echarts and sub-packaging in WeChat Mini Program

Preface Although the holiday is over, it shows up...

React Hooks Usage Examples

Table of contents A simple component example More...

Use of vuex namespace

Table of contents Since Vuex uses a single state ...