Navicat connect to MySQL error solution

Connect with Navicat locally

wrong description

2013-Lost connection to MySQL server at'reading initial communication packet', system error:0 “Internal error/check (Not system error)”
wrong description
View

solution

cd /etc/mysql/mysql.conf.d/
sudo vim mysqld.cnf 

Annotate the content of the red box

Annotation

Restart MySQL service

Test the connection again

connection succeeded


View

surroundings

Virtual machine version

Insert picture description here

MySQL version

Insert picture description here

Preliminary preparation

View MySQL running status

sudo systemctl mysql status
Start state


If it is not running, use the sudo systemctl start mysql command to start the mysql service

Change root password

After installing MySQL, the root password is empty by default, modify the root user password

mysqladmin -u root password "yourNewPassword";

Enter MySQL interactive environment

sudo mysql -u root -p
# then input your password
Enter interactive

View all libraries

show databases;
show databases

Switch library

use databaseName;
Insert picture description here

create

create user 'userName'@'%' identified by 'yourPassword';
# 'userName'@'%' @后面的'%'是host的配置
New user

View

You can see that no permissions are assigned

Insert picture description here

assign permissions

grant all privileges on *.* to 'userName'@'%' identified by 'yourPassword';

All permissions on all tables in all libraries are assigned to this user

Insert picture description here
# 使用grant分配权限时不需要执行flush privileges;
# 如果使用insert插入权限需要之心flush privileges; 重读授权表
flush privileges;
flush


View this user again

Assigned permissions