How to configure MySQL on Ubuntu 16.04 server and enable remote connection

How to configure MySQL on Ubuntu 16.04 server and enable remote connection

background

I am learning nodejs recently, and I remembered that I had a cloud server, but I haven't used it for a long time. Because I was afraid of trouble, I reinstalled an Ubuntu system on the cloud host. Then configuring MySQL became a part of configuring the service (it doesn't matter whether node uses MySQL or not, I just reconfigure one when I have nothing to do -.-). However, I encountered many problems during the configuration process, so after solving a series of problems, I will leave this blog post for future use.

step

1. Install MySQL

Since the blogger uses Ubuntu Server and the XShell tool instead of the desktop version, there is no high-end graphical interface. You can just use the mysql provided by the software source.

The command is as follows:

sudo apt-get install mysql-server

After running this command, if you are not root, you will be asked to enter the root password. After the password is entered correctly, the system will automatically download MySQL for you, as shown below:

After completing the above steps, you will enter a "graphical interface :)" to create a MySQL root password, as shown in the figure:

After entering the password, press Enter and you will be asked to confirm the password, as shown in the figure:

2. Authorize users and allow remote login

If the password is entered correctly twice, the system will help you download MySQL. However, the default MySQL only has one root account, so you might as well create an account with the same rights as root and authorize remote login permission. Then we log in to MySQL first:

mysql -u root -p

The system will ask you to enter the password. After entering the password correctly, enter MySQL:

First, we authorize an account called Ubuntu (you can choose the name) and grant it the right to connect remotely. The command is as follows:

Copy the code as follows:

GRANT ALL PRIVILEGES ON *.* TO 'Ubuntu'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;

After running, enter immediately to update the database:

FLUSH PRIVILEGES;

The effect is as follows:

Execute quit to exit mysql.

Since MySQL is used locally by default and does not open remote connections, you need to modify the configuration file. Of course, I don’t know why the configuration file of the new version of MySQL is different from the previous one. It used to be placed in: /etc/mysql/my.cnf, but now let’s take a look at what it looks like:

run:

sudo vi /etc/mysql/my.cnf

It turns out that the content in my.cnf is as follows. I personally guess that MySQL has optimized its structure. The effect is shown in the figure:

The original configuration file has become a directory structure, so look in the two directories mentioned above and you will soon find the configuration file: /etc/mysql/mysql.conf.d/mysqld.cnf

Edit it with administrator privileges:

sudo vi /etc/mysql/mysql.conf.d/mysqld.cnf

Add '#' to comment out "bind-address = 127.0.0.1", as shown below:

After commenting: wq save and restart the MySQL service:

service mysql restart

After verifying your Ubuntu password, restart the service successfully!

3. Test verification

I tried using Navicat for MySQL under Windows, the configuration information is as follows (coded to prevent hacking:D):

Take a look at the effect:

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • How to install MySQL and enable remote connection on cloud server Ubuntu_Server_16.04.1
  • How to modify mysql to allow remote connections
  • How to enable MySQL remote connection in Linux server
  • How to enable remote connection (multiple backups) for MySQL database
  • mysql opens remote connection (mysql opens remote access)
  • How to enable remote connection to MySQL database
  • Detailed explanation of MySQL remote connection permission

<<:  Summary of basic usage of js array

>>:  Detailed explanation of the use of vue-resource interceptors

Recommend

How to run .sh files in Linux system

There are two ways to run .sh files in Linux syst...

WeChat applet implements the Record function

This article shares the specific code for the WeC...

Introduction to MySQL method of deleting table data with foreign key constraints

When deleting a table or a piece of data in MySQL...

How to redirect URL using nginx rewrite

I often need to change nginx configuration at wor...

A practical record of an accident caused by MySQL startup

Table of contents background How to determine whe...

MySQL import and export backup details

Table of contents 1. Detailed explanation of MySQ...

Implementation of Nginx load balancing cluster

(1) Experimental environment youxi1 192.168.5.101...

Friendly Alternatives to Find Tool in Linux

The find command is used to search for files in a...

Example of adding attributes using style in html

Add inline styles to the required links: Copy code...

Detailed explanation of how to use several timers in CocosCreator

1. setTimeOut Print abc after 3 seconds. Execute ...

Detailed explanation of the life cycle of Angular components (Part 2)

Table of contents 1. View hook 1. Things to note ...

A brief analysis of MySQL explicit type conversion

CAST function In the previous article, we mention...

How to optimize logic judgment code in JavaScript

Preface The logical judgment statements we use in...

A brief discussion on the principle of Vue's two-way event binding v-model

Table of contents explain: Summarize Replenish Un...

Docker installation and configuration steps for Redis image

Table of contents Preface environment Install Cre...