Linux installs mysql and uses navicat to connect to mysql

Table of contents

1. Download mysql

 Two, install mysql

3. Use Navicat to connect to MySQL

4. Frequently asked questions

1. The solution to the error Failed to start mysql.service: Unit not found. when starting the service.

2. The login process appears: access denied for user'root'@'localhost'(using password: Yes) solution.

Source code and other data acquisition methods


1. Download mysql

1. Obtain the download link

Enter the official website: https://www.mysql.com

Click downloads --> MySQL Community (GPL) Downloads --> MySQL Community Server to enter the download interface, select the linux system, find the version you want, right click and copy the link address.

For example, I get the download link of version 5.7.28: https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.28-linux-glibc2.12-x86_64.tar.gz

 2. Use wget to download in linux

 Two, install mysql

Unzip and rename

tar -xvf mysql-5.7.28-linux-glibc2.12-i686.tar.gz 
mv mysql-5.7.28-linux-glibc2.12-i686 mysql 

Add users and groups

groupadd mysql 
useradd -r -g mysql mysql 

Create an initialization directory and modify directory permissions

mkdir - p /data/mysql 
chown mysql:mysql -R /data/mysql 

Modify the configuration file /etc/my.cnf

[mysqld]
bind-address=0.0.0.0
user=mysql
basedir=/usr/local/mysql
datadir=/data/mysql
log-error=/data/mysql/mysql.err
pid-file=/data/mysql/mysql.pid
character_set_server=utf8mb4  # 设置创建数据库时的默认字符类型
symbolic-links=0

[client]
port=3306
socket=/tmp/mysql.sock

initialize mysql

cd /usr/local/mysql/bin/
./mysqld --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql --datadir=/data/mysql/ --user=mysql --initialize

Set the mysql command as a global command: copy mysql.server to init.d

[root@localhost support-files]# pwd
/usr/local/mysql/support-files
[root@localhost support-files]# cp mysql.server /etc/init.d/mysql

start service

service mysql start

Set to start automatically at boot

chkconfig mysql on

log in to mysql

mysql -u root -p

At this point, mysql is installed and successfully logged in using

3. Use Navicat to connect to MySQL

1. The linux firewall opens port 3306

[root@node1 ~]# firewall-cmd --add-port=3306/tcp --permanent
[root@node1 ~]# firewall-cmd --reload

 If the port is not opened, an error 10060 "Unknown error" will be reported:

2. Open the remote access permission of the mysql root user

Log in to mysql in linux and enter the mysql library

View the data in the user table, and modify the value of the root user host field to "%"

MySQL [mysql]> select host,user from user;
MySQL [mysql]> update user set host="%" where user="root";
MySQL [mysql]> flush privileges;

 

 Use Navicat to connect to the database

 If the root user access permission is not opened, an error not allowed to connect will be reported:

 

4. Frequently asked questions

1. The solution to the error Failed to start mysql.service: Unit not found. when starting the service.

2. The login process appears: access denied for user'root'@'localhost'(using password: Yes) solution.

1. Stop the mysql service:
service mysql stop

2 Log in to mysql in background security mode;

find / -name mysqld_safe

cd to the directory where the file is located./mysqld_safe
--user=mysql --skip-grant-tables --skip-networking

3. Open a new window, enter mysql directly on the command line, and log in

4. Modify root user password:

use mysql

update user set authentication_string=password('123456') where user="root";

Note: The field for storing passwords above 5.7 becomes authentication_string, if the above statement is not executed successfully, execute the following statement

update mysql.user set password=PASSWORD(‘123456’)where user=‘root’;

 

5. Set Password Expiration to No

update user set password_expired='N' where user="root"

6. Refresh and exit:
flush privileges;
quit;

7. Restart the mysql service
service mysql restart;

  • When logging in, it prompts -bash: mysql: command not found

 Use yum install -y mysql to install

Source code and other data acquisition methods

Friends who want to get source code and other tutorial materials, please like + comment + bookmark , triple!

After three times in a row , I will send you private messages one by one in the comment area~

 

Guess you like

Origin blog.csdn.net/GDYY3721/article/details/131791038
Recommended