Full stack development practice - MySql

Because some fields need to use json format, MySql 8 is required!

  • linux:Debian 10
  • mysql:8.0.17

Completely uninstall mariaDB

sudo apt-get purge mariadb-*

This is to uninstall mysqlsudo apt-get purge mysql-\*

A prompt pops up to keep the MariaDB database. If it is completely uninstalled, it can be removed together.

There may be various problems when uninstalling, and some problems may require killing the process directly.

# 查看进程
ps aux | grep amoeba
# 杀死进程
kill -s 9 pid

install mysql

First, add the MySQL APT repository to the system, wget(不是安装方式,它是一种下载工具,类似于迅雷)download the latest release package using the command: http://repo.mysql.com/

wget http://repo.mysql.com/mysql-apt-config_0.8.17-1_all.deb

After the download is complete, install it with the following command:

sudo dpkg -i mysql-apt-config_0.8.17-1_all.deb

You will see the MySQL configuration installation menu, select the version you want to install.

MySQL 8.0 is selected by default. If you want to install MySQL 5.7, please select MySQL Server & Cluster (current selection: mysql-8.0), and then select the corresponding MySQL version.

We will install MySQL version 8.0 by pressing the Tab key to select OK and then pressing the Enter key (as shown above).

Use the following commands to update the package and install MySQL.

sudo apt update
sudo apt install mysql-server

During the installation process, a dialog box for setting the MySQL root password will pop up, and set a strong password.

Next, a message is displayed informing you about the new MySQL 8 authentication. Before choosing the default MySQL 8 authentication plugin, make sure your application supports it.

Here we select the default first item, then switch the Tab key to "OK", and press Enter to continue.

After the installation is complete, the MySQL service will run automatically by default. We can check the service running status with the following command:

sudo systemctl status mysql

Connect to MySQL server

In the terminal, you can enter the mysql client command to connect to the mysql service:

Select the default authentication method to log in to the MySQL server as the root user:

mysql

To choose the traditional authentication method to log in, enter:

mysql -uroot -p

This is to enter the MySQL root account password set earlier.

After a successful connection you will see something similar to the following:

Now you can execute MySQL database SQL statements to operate.

Set up remote login

  1. Login to MySQL

mysql -u root -p

enter your password

  1. Select the mysql database (be careful not to drop the semicolon)

mysql> use mysql;

Because the user table of user information is stored in the mysql database.

  1. View information about the current root user in the user table of the mysql database

mysql> select host, user, authentication_string, plugin from user;

Check the host of the root user in the table, the localhost should be displayed by default, only local access is supported, and remote access is not allowed.

  1. Grant all privileges to root user and set up remote access

Update the domain attribute, '%' means allow external access, and then re-execute the above command.

mysql> update user set host='%' where user='root';

Execute refresh permissions:

mysql> flush privileges;

Execute authorization:

mysql> grant all privileges on *.* to root@'%';

What the FLUSH PRIVILEGES; command essentially does is:

Extract the user information/privilege settings in the current user and privilege tables from the mysql library (the built-in library of the MySQL database) into memory.

After the MySQL user data and permissions are modified, if you want to take effect directly without restarting the MySQL service, you need to execute this command.

Usually, after modifying the settings of the ROOT account, if you are afraid that you will not be able to log in after restarting, you can check whether the permission settings take effect after a direct flush.

without taking too much risk.

  1. View the host of the root user

Execute step 2 again, you will find that the root user's host has become %, indicating that our modification has been successful and can be accessed remotely.

Note that at the red mark, the root host has been replaced by %

  1. access database

Don't forget to open the server port

There are many visualization tools for remote access to the database, such as: Navicat, SQLyog, MySQL workbench, etc. I use Navicat to enter the host and password of the access, and report errors such as 2059 and 1698. The high probability is the reason for the plugin: auth_socket , which is because of MySql8. The encryption rules of version 0 and 5.0 are different, and the current visualization tool only supports the old encryption method.

There are two ways to solve this problem, one is to update the Navicat driver to solve this problem, and the other is to modify the encryption rule of MySQL user login to mysql_native_password. a method.

The new version of the tool may already be supported, if it still doesn't work, you need to go through the following process!

  1. Modify encryption rules

mysql> ALTER USER 'root'@'%' IDENTIFIED BY '你的密码' PASSWORD EXPIRE NEVER;

  1. Update root user password

mysql> ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '你的密码';

  1. Refresh permissions

mysql> FLUSH PRIVILEGES;

The final effect is as follows:

Setup is complete, connect Navicat again.

exit mysql

mysql> exit

{{o.name}}
{{m.name}}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324206090&siteId=291194637