前言:網(wǎng)上mysql的安裝方式參差不齊,有的裝了缺少配置文件,有的裝了少庫少表 所以現(xiàn)在出一個完整的mysql安裝方案
目前安裝方式無外乎有下面三種:
- 裝完沒有密碼,需要自己進去設(shè)置密碼
- 裝完有默認密碼,需要查看并進去在自己修改
- 安裝的時候輸入密碼,安裝完成后直接使用
本文使用的正是第三種
正式開始
1、mysql的下載
mysql官網(wǎng)下載地址:https://dev.mysql.com/downloads/mysql/
進入后 點擊紅圈的鏈接
就會進入到5.7的下載界面了 可以根據(jù)需要下載對應系統(tǒng)所需要的包
這里我們下載對應ubuntu的tar包 并且將其上傳到ubuntu內(nèi)
解壓
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:~#
查看
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#
使用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
在安裝mysql server這個包的時候 會報依賴錯誤 告訴我們?nèi)鄙賛ysql-client 而且還少libmecab libmecab我們暫時先不管 后面有命令統(tǒng)一解決
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
我們先安裝mysql-client 然后此時你會發(fā)現(xiàn) 又提示缺少mysql-community-client這個依賴包 繼續(xù)裝
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#
現(xiàn)在他只告訴你缺少libmecab這個包了 在不同的ubuntu版本下 缺少的版本并不相同 比如這里缺少libtinfo5 然而在有的環(huán)境下缺libtinfo1 libtinfo2 等等
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
下面我們只需要使用 apt --fix-broken install 這條命令來自動解決當前所出現(xiàn)的依賴 就可以完美解決問題了 選擇Y同意
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]
同意繼續(xù)后 安裝一會就會提示你輸入mysql的root密碼了
文章來源:http://www.zghlxwxcb.cn/news/detail-591879.html
我們輸入完兩次密碼后 mysql的安裝也就完成了
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>
當然 mysql的安裝是完成了 但是此時它并不能為我們的程序提供服務(wù)(使用連接工具現(xiàn)在是連接不上的) 因為還需要配置遠程連接 使我們可以遠程登錄才可以
首先 進入mysql庫 查看user表 會發(fā)現(xiàn)我們的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>
將其修改 并使其立即生效
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>
此時到這里并未結(jié)束 我們還需要修改mysql的配置文件 我們需要修改位于/etc/mysql/mysql.conf.d/mysqld.cnf 的配置文件
root@wdr:/opt/mysql# vim /etc/mysql/mysql.conf.d/mysqld.cnf
將其bind-address改為0.0.0.0
文章來源地址http://www.zghlxwxcb.cn/news/detail-591879.html
保存退出 重啟mysql服務(wù)
root@wdr:/opt/mysql# systemctl restart mysql
root@wdr:/opt/mysql#
重啟成功 現(xiàn)在我們可以使用連接工具連接了
保存退出 重啟mysql服務(wù)
root@wdr:/opt/mysql# systemctl restart mysql
root@wdr:/opt/mysql#
重啟成功 現(xiàn)在我們可以使用連接工具連接了
至此 mysql的安裝已全部完成 如果有部署在云服務(wù)器上的經(jīng)過上列操作無法訪問的話 記得查看后臺防火墻端口是否開啟
到了這里,關(guān)于Ubuntu安裝mysql5.7(適用于大多數(shù)ubuntu版本)的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!