Install MySQL database on Ubuntu server version (reproduced) and configure remote connection

This article is reproduced from: https://blog.csdn.net/yhjahjj1314/article/details/80998807

Practical content, reprint and save


The first step is to log in to the Ubuntu server

Update source: sudo apt-get update

Installation source: sudo apt-get upgrade

MySQL server installed in the second step

Execution: sudo apt-get install mysql-server

Execution: sudo apt-get install mysql-client

Execution: sudo apt install libmysqlclient-dev

After the installation is successful, you can use the following command to test whether the installation is successful:

sudo netstat -tap | grep mysql

The following information appears to prove that the installation is successful:

Insert picture description here
The user name and password of this version of the database are in a configuration file by default

sudo vim /etc/mysql/debian.cnf

Username and password are as follows

In this file, there are MySQL default user name and user password, the
most important thing is: the default user name is not root, but debian-sys-maint, as shown below

# Automatically generated for Debian scripts. DO NOT TOUCH!
[client]
host     = localhost
user     = debian-sys-maint
password = hGu99nJgoWcmCDKT
socket   = /var/run/mysqld/mysqld.sock
[mysql_upgrade]
host     = localhost
user     = debian-sys-maint
password = hGu99nJgoWcmCDKT
socket   = /var/run/mysqld/mysqld.sock
basedir  = /usr

Log in directly, then change the root password

After Du Niang's guidance, the version I installed is 5.7, so the password field has been deleted and replaced by the authentication_string field, so I need to change the password:

mysql> update mysql.user set authentication_string=password('password') where user='root';

If it shows:

Query OK, 1 row affected, 1 warning (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 1

It means the modification is successful, and then you need to *restart** MySQL to log in successfully.

You should be able to enter MySQL here, continue to operate

> use mysql;
 
> update user set authentication_string=PASSWORD("这里输入你要改的密码") where User='root'; #更改密码
> update user set plugin="mysql_native_password"; #如果没这一行可能也会报一个错误,因此需要运行这一行
 
> flush privileges; #更新所有操作权限
> quit;

Start the mysql database

sudo /etc/init.d/mysql start

Reboot

sudo /etc/init.d/mysql restart

shut down

sudo /etc/init.d/mysql stop

**

Remote connection configuration

**

Log in to the mysql server:

mysql -u 用户名 -p

Authorize the specified ip (specify a remote ip address)

grant all privileges on *.* to 'root'@'IP地址' identified by '密码';

Authorize all ips (all ips can be connected remotely)

grant all privileges on *.* to root@"%" identified by 'root' with grant option; 

Effective immediately

flush privileges;

Restart the database

service mysqld restart 

Copyright statement: This article is the original article of the CSDN blogger "Wandering Photographer". It follows the CC 4.0 by-sa copyright agreement. Please attach the original source link and this statement for reprinting.
Original link: https://blog.csdn.net/yhjahjj1314/article/details/80998807

Guess you like

Origin blog.csdn.net/weixin_42656358/article/details/99460887