Ubuntu安装MySQL5.7

Ubuntu安装MySQL5.7

MySQL的下载

mysql官网下载地址:https://dev.mysql.com/downloads/mysql/

1、点击 Archives

XiaoWang11714653411520397.png

2、这里我们选择对应Ubuntu的tar包,右键复制链接地址

XiaoWang11714653513358400.png

3、将其下载到Ubuntu内

wget https://downloads.mysql.com/archives/get/p/23/file/mysql-server_5.7.42-1ubuntu18.04_amd64.deb-bundle.tar

4、解压

root@haiyang:~# mkdir /opt/mysql
root@haiyang:~# 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@haiyang:~# cd /opt/mysql/
root@haiyang:/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@haiyang:/opt/mysql# 

MySQL的安装

1、使用dpkg -i命令顺序安装 安装最后 mysql-community-server 这个包的时候可能会报错 但是不要惊慌

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

2、在安装 mysql-community-server 这个包的时候 会报依赖错误 告诉我们缺少 mysql-client 而且还少 libmecab 我们暂时先不管 后面有命令统一解决

root@haiyang:/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

3、我们先安装 mysql-client 然后此时你会发现 又提示缺少 mysql-community-client 这个依赖包 继续装

root@haiyang:/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# 

4、现在他只告诉你缺少 libmecab 这个包了 在不同的Ubuntu版本下 缺少的版本并不相同 比如这里缺少 libtinfo5 然而在有的环境下缺 libtinfo1 libtinfo2 等等

root@haiyang:/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 

5、下面我们只需要使用 apt --fix-broken install 这条命令来自动解决当前所出现的依赖 就可以完美解决问题了 选择Y同意

root@haiyang:/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] 

6、同意继续后 安装一会就会提示你输入MySQL的root密码了

7、我们输入完两次密码后MySQL的安装也就完成了

root@haiyang:/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> 

修改MySQL远程连接权限

1、首先 进入mysql库 查看user表 会发现我们的root用户是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> 

2、将其修改 并使其立即生效

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> 

3、修改MySQL的配置文件

vim /etc/mysql/mysql.conf.d/mysqld.cnf
# 将其bind-address改为0.0.0.0

4、保存退出 重启MySQL服务

root@haiyang:/opt/mysql# systemctl restart mysql
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

运维小王

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值