Ubuntu 18.04离线安装数据库
Ubuntu离线安装MySQL8.0.26数据库
Ubuntu 18.04离线安装Mysql 8.0.26
Ubuntu 18.04离线安装Mysql 8.0.26
一、准备
mysql下载
mysql官网-->download-->社区版,选择对应操作系统版本的mysql安装文件,如下,网页下载太慢,只好用Linux服务器连外网下载:
Libmecab2 下载
到kpgs.org 选择对应的 Libmecab2
二、安装
上面两个文件下载完成后,手动扔到对应的服务器的目录下,如/home/mysql/
进入目录,并解压
tar -xf mysql-server_5.7.22-1ubuntu16.04_amd64.deb-bundle.tar
得到如下安装包:
libmecab2_0.996-5_amd64.deb
-rwxr--r-- 1 7155 31415 1301712 Jul 1 15:24 libmysqlclient21_8.0.26-1ubuntu18.04_amd64.deb
-rwxr--r-- 1 7155 31415 1622012 Jul 1 15:24 libmysqlclient-dev_8.0.26-1ubuntu18.04_amd64.deb
-rwxr--r-- 1 7155 31415 65012 Jul 1 15:24 mysql-client_8.0.26-1ubuntu18.04_amd64.deb
-rwxr--r-- 1 7155 31415 68672 Jul 1 15:24 mysql-common_8.0.26-1ubuntu18.04_amd64.deb
-rwxr--r-- 1 7155 31415 2799440 Jul 1 15:24 mysql-community-client_8.0.26-1ubuntu18.04_amd64.deb
-rwxr--r-- 1 7155 31415 1689600 Jul 1 15:24 mysql-community-client-core_8.0.26-1ubuntu18.04_amd64.deb
-rwxr--r-- 1 7155 31415 1104956 Jul 1 15:24 mysql-community-client-plugins_8.0.26-1ubuntu18.04_amd64.deb
-rwxr--r-- 1 7155 31415 76312 Jul 1 15:24 mysql-community-server_8.0.26-1ubuntu18.04_amd64.deb
-rwxr--r-- 1 7155 31415 20275952 Jul 1 15:24 mysql-community-server-core_8.0.26-1ubuntu18.04_amd64.deb
-rwxr--r-- 1 7155 31415 35801880 Jul 1 15:24 mysql-community-server-debug_8.0.26-1ubuntu18.04_amd64.deb
-rwxr--r-- 1 7155 31415 226301924 Jul 1 15:24 mysql-community-test_8.0.26-1ubuntu18.04_amd64.deb
-rwxr--r-- 1 7155 31415 9374376 Jul 1 15:24 mysql-community-test-debug_8.0.26-1ubuntu18.04_amd64.deb
-rwxr--r-- 1 7155 31415 65004 Jul 1 15:24 mysql-server_8.0.26-1ubuntu18.04_amd64.deb
-rwxr--r-- 1 7155 31415 65012 Jul 1 15:24 mysql-testsuite_8.0.26-1ubuntu18.04_amd64.deb
按顺序执行以下指令
sudo dpkg -i mysql-common_8.0.26-1ubuntu18.04_amd64.deb
sudo dpkg-preconfigure mysql-community-server_8.0.26-1ubuntu18.04_amd64.debd
sudo dpkg -i mysql-community-client-plugins_8.0.26-1ubuntu18.04_amd64.deb
sudo dpkg -i libmysqlclient21_8.0.26-1ubuntu18.04_amd64.deb
sudo dpkg -i libmysqlclient-dev_8.0.26-1ubuntu18.04_amd64.deb
sudo dpkg -i mysql-community-client-core_8.0.26-1ubuntu18.04_amd64.deb
sudo dpkg -i mysql-community-client_8.0.26-1ubuntu18.04_amd64.deb
sudo dpkg -i mysql-client_8.0.26-1ubuntu18.04_amd64.deb
sudo dpkg -i libmecab2_0.996-5_amd64.deb
sudo dpkg -i mysql-community-server-core_8.0.26-1ubuntu18.04_amd64.deb
sudo dpkg -i mysql-community-server_8.0.26-1ubuntu18.04_amd64.deb
注意按顺序哦,要不然安装失败,也可以把指令拷贝到创建的install.sh可执行文件中,执行指令进行安装
./install.sh
执行此安装脚本,按顺序来:
安装过程中,需要收入密码,密码要记下来
设置密码:
补上依赖包,,可以直接执行补依赖包和执行bushu.sh脚本
三、验证并登陆查看
验证
安装完成后,可以通过下面的命令来查看时候安装成功:
systemctl status mysql
mysql10.png
看到上面的信息就说明MySQL已经安装好并运行起来了。
登陆MySQL
以root用户登陆
# -u 指定用户名 -p输入安装时,输入的密码
sudo mysql -u root -p
#或者:
sudo mysql #可以不需要指定用户名密码
mysql11.png
已经成功连接到数据库服务器了。那接下来我们看看这里都有哪些databases.
mysql>show databases;
mysql12.png
其它信息
MySQL安装好后有默认的这几个数据库。其中mysql里有user表,这个表里放了user、host相关的一些信息。通过下面的命令看到这个表。
mysql> show tables from mysql;+---------------------------+| Tables_in_mysql |+---------------------------+| columns_priv || component || db || default_roles || engine_cost || func || general_log || global_grants || gtid_executed || help_category || help_keyword || help_relation || help_topic || innodb_index_stats || innodb_table_stats || password_history || plugin || procs_priv || proxies_priv || role_edges || server_cost || servers || slave_master_info || slave_relay_log_info || slave_worker_info || slow_log || tables_priv || time_zone || time_zone_leap_second || time_zone_name || time_zone_transition || time_zone_transition_type || user |+---------------------------+33 rows in set (0.00 sec)
设置允许远程登录和开启防火墙
ysql默认不允许远程登录,所以需要开启远程访问权限
可以先查看user表
mysql> select User, Host from mysql.user;+------------------+-----------+| User | Host |+------------------+-----------+| mysql.infoschema | localhost || mysql.session | localhost || mysql.sys | localhost || root | localhost |+------------------+-----------+4 rows in set (0.00 sec)
默认都是localhost, 把root调整为远程登陆用户
use mysql;
update user set host = '%' where user = 'root';
此时root的host是所有都可以了
mysql> select User, Host from mysql.user;+------------------+-----------+| User | Host |+------------------+-----------+| root | % || mysql.infoschema | localhost || mysql.session | localhost || mysql.sys | localhost |+------------------+-----------+4 rows in set (0.00 sec)
然后刷新修改
mysql> FLUSH PRIVILEGES;
开启防火墙
[root@localhost ~]# firewall-cmd --zone=public --add-port=3306/tcp --permanent
success[root@localhost ~]# firewall-cmd --reload
success
优化配置
sql> set global max_connections=3000 ##最大连接数
sql> set global thread_cache_size=60; ##最大并发数
卸载
卸载mysql(能卸载5.7和8.0)
sudo apt-get remove mysql-*
然后清理残留的数据
dpkg -l |grep ^rc|awk '{print $2}' |sudo xargs dpkg -P
开启关闭
开启 service mysql start
关闭 service mysql stop