How to configure mysql on ubuntu server and implement remote connection

How to configure mysql on ubuntu server and implement remote connection

Server: Ubuntu Server 16.04 LSS

Client: Ubuntu 16.04 LTS

Server Configuration

Install mysql on the server

# eric @ userver in ~ [14:00:31] 
$ sudo apt install mysql-server install mysql-client libmysqlclient-dev

Check if it is successful SET PASSWORD FOR 'pig'@'%' = PASSWORD("123456");

# eric @ userver in ~ [14:10:55] 
$ sudo netstat -tap | grep mysql
tcp 0 0 localhost:mysql *:* LISTEN 5287/mysqld  

Modify the remote connection configuration file

# eric @ userver in ~ [14:16:26] 
$ sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf 
#Comment out bind-address = 127.0.0.1
#bind-address = 127.0.0.1

Set the server database character set to utf-8

# eric @ userver in ~ [14:16:26] 
$ sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf 
#Add in [mysqld]: character-set-server=utf8
[mysqld]
#
# * Basic Settings
#
user = mysql
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
port = 3306
basedir = /usr
datadir = /var/lib/mysql
tmpdir = /tmp
lc-messages-dir = /usr/share/mysql
skip-external-locking
character-set-server=utf8 #Newly added#Login to mysql to view characters# eric @ userver in ~ [14:21:26]
$ mysql -u root -p
Enter password: 
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.20-0ubuntu0.16.04.1 (Ubuntu)
Copyright (c) 2000, 2017, 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.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show variables like '%char%';
+--------------------------+----------------------------+
| Variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | utf8 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | utf8 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.00 sec)

Create a new remote login user and authorize

mysql> create user 'eric'@'%' identified by 'lyd2017';
Query OK, 0 rows affected (0.01 sec)
mysql> grant all on *.* to 'eric'@'%';--All permissions Query OK, 0 rows affected (0.00 sec)

About authorization:

Command: GRANT privileges ON databasename.tablename TO 'username'@'host'

Note: privileges-user operation permissions, such as select, insert, update, etc. If you want to grant ownership, use all

If you want to grant the user the permission to operate all databases and tables, use * to indicate it, such as *.*

For example:

GRANT SELECT, INSERT ON mysql.tables TO 'eric'@'%';
GRANT ALL ON *.* TO 'eric'@'%';

However, users authorized by these commands cannot authorize other users. If you want to allow the user to have permissions, use

GRANT privileges ON databasename.tablename TO 'username'@'host' WITH GRANT OPTION;

Restart the server

# eric @ userver in ~ [14:35:49] 
$ /etc/init.d/mysql restart 
[....] Restarting mysql (via systemctl): mysql.service==== AUTHENTICATING FOR org.freedesktop.systemd1.manage-units ===
Authentication is required to restart 'mysql.service'.
Authenticating as: eric,,, (eric)
Password: 
==== AUTHENTICATION COMPLETE ===

Client

Install mysql client

# eric @ ray in ~ [14:32:12] C:127
$ sudo apt install mysql-client
[sudo] password for eric: 
Reading package lists... Done

Connect to mysql server

# eric @ ray in ~ [14:37:13] C:1
$ mysql -h 192.168.122.58 -u eric -p #
Enter password: 
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 15
Server version: 5.7.20-0ubuntu0.16.04.1 (Ubuntu)
Copyright (c) 2000, 2017, 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.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>

About the error problem of connecting directly with the root user

# eric @ ray in ~ [14:35:22] C:1
$ mysql -h 192.168.122.58 -u root -p
Enter password: 
ERROR 1045 (28000): Access denied for user 'root'@'192.168.122.1' (using password: YES)

#If you log in directly as the root user at the beginning, an error will be reported. You can modify the root password to solve this problem. mysql>SET PASSWORD FOR 'root'@'%' = PASSWORD("123456"); 

The above article on how to configure MySQL on Ubuntu Server and realize remote connection is all I have to share with you. I hope it can give you a reference. I also hope that you will support 123WORDPRESS.COM.

You may also be interested in:
  • Solve the problem that SQL Server 2008 cannot use "." local to connect to the database
  • Summary of five methods of connecting PHP to MSSQL server
  • How to connect to SQL Server 2012 database and execute SQL statements in C#
  • C# code example using SqlConnection to connect to SQL Server

<<:  vmware workstation12 installation centos prompts VMware Player and Device/Credential Guard are incompatible, reasons and solutions

>>:  Native JS encapsulation vue Tab switching effect

Recommend

Detailed explanation of how components communicate in React

1. What is We can split the communication between...

Preventing SQL injection in web projects

Table of contents 1. Introduction to SQL Injectio...

Summary of flex layout compatibility issues

1. W3C versions of flex 2009 version Flag: displa...

Angular Cookie read and write operation code

Angular Cookie read and write operations, the cod...

MySQL uses events to complete scheduled tasks

Events can specify the execution of SQL code once...

How to use rem adaptation in Vue

1. Development environment vue 2. Computer system...

A brief discussion on the problem of forgotten mysql password and login error

If you forget your MySQL login password, the solu...

js implements table drag options

This article example shares the specific code of ...

JavaScript - Using slots in Vue: slot

Table of contents Using slots in Vue: slot Scoped...

js implementation of verification code case

This article example shares the specific code of ...

How to configure nginx to limit the access frequency of the same IP

1. Add the following code to http{} in nginx.conf...