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

MySQL database table partitioning considerations [recommended]

Table partitioning is different from database par...

JavaScript data structure bidirectional linked list

A singly linked list can only be traversed from t...

Understand the use of CSS3's all attribute

1. Compatibility As shown below: The compatibilit...

Summary of English names of Chinese fonts

When using the font-family property in CSS to ref...

Detailed analysis of SQL execution steps

Detailed analysis of SQL execution steps Let'...

The use of vue directive v-bind and points to note

Table of contents 1. v-bind: can bind some data t...

Conflict resolution when marquee and flash coexist in a page

The main symptom of the conflict is that the FLASH...

Vue uses plug-ins to cut pictures in proportion

This article shares the specific code of Vue usin...

What is ZFS? Reasons to use ZFS and its features

History of ZFS The Z File System (ZFS) was develo...

A brief discussion on Mysql specified order sorting query

Recently, I have been working on a large-screen d...

Hover zoom effect made with CSS3

Result:Implementation code: html <link href=&#...

How to build a complete samba server in Linux (centos version)

Preface smb is the name of a protocol that can be...

Vue implements a shopping cart that can change the shopping quantity

This article shares with you how to use Vue to ch...

Some suggestions for HTML beginners and novices, experts can ignore them

Feelings: I am a backend developer. Sometimes when...