Ubuntu installation mysql5.7 (applicable to most ubuntu versions)

Preface: The installation methods of MySQL on the Internet are uneven. Some are installed with missing configuration files, and some are installed with few databases and tables. So now we have a complete MySQL installation plan.

There are currently three installation methods:

  1. There is no password after installation. You need to go in and set the password yourself.
  2. There is a default password after installation, you need to check it and change it yourself.
  3. Enter the password during installation and use it directly after installation is completed.

This article uses the third type

Officially begin

1. Mysql download

mysql official website download address : https://dev.mysql.com/downloads/mysql/

After entering, click the link circled in red

Insert image description here

You will enter the 5.7 download interface. You can download the packages required by the corresponding system as needed.

Insert image description here

Here we download the tar package corresponding to ubuntu and upload it to ubuntu

Insert image description here

Unzip

root@wdr:/opt# mkdir /opt/mysql
root@wdr:~# tar -xvf mysql-server_5.7.42-1ubuntu18.04_amd64.deb-bundle.tar -C /opt/mysql/
libmysqlclient20_5.7.42-1ubuntu18.04_amd64.deb
libmysqlclient-dev_5.7.42-1ubuntu18.04_amd64.deb
libmysqld-dev_5.7.42-1ubuntu18.04_amd64.deb
mysql-client_5.7.42-1ubuntu18.04_amd64.deb
mysql-common_5.7.42-1ubuntu18.04_amd64.deb
mysql-community-client_5.7.42-1ubuntu18.04_amd64.deb
mysql-community-server_5.7.42-1ubuntu18.04_amd64.deb
mysql-community-source_5.7.42-1ubuntu18.04_amd64.deb
mysql-community-test_5.7.42-1ubuntu18.04_amd64.deb
mysql-server_5.7.42-1ubuntu18.04_amd64.deb
mysql-testsuite_5.7.42-1ubuntu18.04_amd64.deb
root@wdr:~# 

Check

root@wdr:~# cd /opt/mysql/
root@wdr:/opt/mysql# ls
libmysqlclient20_5.7.42-1ubuntu18.04_amd64.deb        mysql-community-server_5.7.42-1ubuntu18.04_amd64.deb
libmysqlclient-dev_5.7.42-1ubuntu18.04_amd64.deb      mysql-community-source_5.7.42-1ubuntu18.04_amd64.deb
libmysqld-dev_5.7.42-1ubuntu18.04_amd64.deb           mysql-community-test_5.7.42-1ubuntu18.04_amd64.deb
mysql-client_5.7.42-1ubuntu18.04_amd64.deb            mysql-server_5.7.42-1ubuntu18.04_amd64.deb
mysql-common_5.7.42-1ubuntu18.04_amd64.deb            mysql-testsuite_5.7.42-1ubuntu18.04_amd64.deb
mysql-community-client_5.7.42-1ubuntu18.04_amd64.deb
root@wdr:/opt/mysql# 

Use the dpkg -i command to install the last mysql-community-server package in sequence, but you may get an error, but don’t panic.

dpkg -i mysql-common_5.7.42-1ubuntu18.04_amd64.deb 
dpkg -i libmysqlclient20_5.7.42-1ubuntu18.04_amd64.deb 
dpkg -i libmysqlclient-dev_5.7.42-1ubuntu18.04_amd64.deb 
dpkg -i libmysqld-dev_5.7.42-1ubuntu18.04_amd64.deb 
dpkg -i mysql-community-server_5.7.42-1ubuntu18.04_amd64.deb

When installing the mysql server package, a dependency error will be reported, telling us that mysql-client is missing and libmecab is missing. For the time being, we will solve the problem uniformly regardless of the subsequent commands for libmecab.

root@wdr:/opt/mysql# dpkg -i mysql-community-server_5.7.42-1ubuntu18.04_amd64.deb 
Selecting previously unselected package mysql-community-server.
(Reading database ... 74128 files and directories currently installed.)
Preparing to unpack mysql-community-server_5.7.42-1ubuntu18.04_amd64.deb ...
Unpacking mysql-community-server (5.7.42-1ubuntu18.04) ...
dpkg: dependency problems prevent configuration of mysql-community-server:
mysql-community-server depends on mysql-client (= 5.7.42-1ubuntu18.04); however:
Package mysql-client is not installed.
mysql-community-server depends on libmecab2; however:
Package libmecab2 is not installed.

dpkg: error processing package mysql-community-server (--install):
dependency problems - leaving unconfigured
Processing triggers for man-db (2.10.2-1) ...
Errors were encountered while processing:
mysql-community-server

Let's install mysql-client first. Then you will find that the dependency package mysql-community-client is missing and continue to install it.

root@wdr:/opt/mysql# dpkg -i mysql-client_5.7.42-1ubuntu18.04_amd64.deb 
Selecting previously unselected package mysql-client.
(Reading database ... 74290 files and directories currently installed.)
Preparing to unpack mysql-client_5.7.42-1ubuntu18.04_amd64.deb ...
Unpacking mysql-client (5.7.42-1ubuntu18.04) ...
dpkg: dependency problems prevent configuration of mysql-client:
mysql-client depends on mysql-community-client (= 5.7.42-1ubuntu18.04); however:
Package mysql-community-client is not installed.

dpkg: error processing package mysql-client (--install):
dependency problems - leaving unconfigured
Errors were encountered while processing:
mysql-client
root@wdr:/opt/mysql# 

Now he only tells you that the libmecab package is missing. The missing versions are different in different Ubuntu versions. For example, libtinfo5 is missing here. However, libtinfo1, libtinfo2, etc. are missing in some environments.

root@wdr:/opt/mysql# dpkg -i mysql-community-client_5.7.42-1ubuntu18.04_amd64.deb 
Selecting previously unselected package mysql-community-client.
(Reading database ... 74296 files and directories currently installed.)
Preparing to unpack mysql-community-client_5.7.42-1ubuntu18.04_amd64.deb ...
Unpacking mysql-community-client (5.7.42-1ubuntu18.04) ...
dpkg: dependency problems prevent configuration of mysql-community-client:
mysql-community-client depends on libtinfo5 (>= 6); however:
Package libtinfo5 is not installed.

dpkg: error processing package mysql-community-client (--install):
dependency problems - leaving unconfigured
Processing triggers for man-db (2.10.2-1) ...
Errors were encountered while processing:
mysql-community-client 

Next, we only need to use apt --fix-broken install this command to automatically solve the current dependencies, which will perfectly solve the problem. Select Y to agree.

root@wdr:/opt/mysql# apt --fix-broken install
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Correcting dependencies... Done
The following additional packages will be installed:
libmecab2 libtinfo5
The following NEW packages will be installed:
libmecab2 libtinfo5
0 upgraded, 2 newly installed, 0 to remove and 50 not upgraded.
3 not fully installed or removed.
Need to get 298 kB of archives.
After this operation, 1,432 kB of additional disk space will be used.
Do you want to continue? [Y/n] 

After agreeing to continue the installation, you will be prompted to enter the root password of mysql after a while.

Insert image description here

After we enter the password twice, the installation of mysql is completed.

root@wdr:/opt/mysql# mysql -u root -p123456
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.42 MySQL Community Server (GPL)

Copyright (c) 2000, 2023, Oracle and/or its affiliates.

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> 

Of course, the installation of mysql is completed, but it cannot provide services for our program at this time (it is impossible to connect using the connection tool) because we still need to configure the remote connection so that we can log in remotely.

First, enter the mysql library to view the user table and you will find that our root user is localhost.

mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> 
mysql> select User,Host from user;
+---------------+-----------+
| User          | Host      |
+---------------+-----------+
| mysql.session | localhost |
| mysql.sys     | localhost |
| root          | localhost |
+---------------+-----------+
3 rows in set (0.00 sec)

mysql> 

Modify it and make it effective immediately

mysql> update user set host = '%' where user = 'root'; 
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> select User,Host from user;
+---------------+-----------+
| User          | Host      |
+---------------+-----------+
| root          | %         |
| mysql.session | localhost |
| mysql.sys     | localhost |
+---------------+-----------+
3 rows in set (0.00 sec)

mysql> flush privileges; 
Query OK, 0 rows affected (0.00 sec)

mysql> 

This is not the end here. We still need to modify the mysql configuration file. We need to modify the configuration file located at /etc/mysql/mysql.conf.d/mysqld.cnf.

root@wdr:/opt/mysql# vim /etc/mysql/mysql.conf.d/mysqld.cnf 

Change its bind-address to 0.0.0.0

Insert image description here

Save, exit and restart the mysql service

root@wdr:/opt/mysql# systemctl restart mysql
root@wdr:/opt/mysql# 

Restart successful now we can use the connection tool to connect

Save, exit and restart the mysql service

root@wdr:/opt/mysql# systemctl restart mysql
root@wdr:/opt/mysql# 

Restart successful now we can use the connection tool to connectInsert image description here

At this point, the installation of mysql has been completed. If there is any server deployed on the cloud server that cannot be accessed after the above operations, remember to check whether the background firewall port is open.

Guess you like

Origin blog.csdn.net/qq_41265137/article/details/130644812
Recommended