mysql8安装和驱动jar包下载

方式一:基于docker安装

下拉镜像

docker pull mysql:8.0.21

mysql8安装和驱动jar包下载_第1张图片

启动镜像
docker run -p 3307:3306 --name mysql -e MYSQL_ROOT_PASSWORD=hadoop -d mysql:8.0.21

启动成功后,进入容器内部拷贝配置文件,到宿主主机
docker cp mysql:/etc/mysql /home/summer/mysql8

拷贝容器的 /etc/mysql目录到 主机目录/home/summer/mysql8

删除mysql容器,重新创建容器
docker stop mysql docker rm mysql

启动mysql ,挂载配置文件,数据持久化到宿主主机
启动脚本 文件名为mysql8.0.21.sh

#!/bin/sh
docker run \
-p 3307:3306 \
--name mysql \
--privileged=true \
--restart unless-stopped \
-v /home/summer/mysql8/mysql:/etc/mysql \
-v /home/summer/mysql8/logs:/logs \
-v /home/summer/mysql8/data:/var/lib/mysql \
-v /etc/localtime:/etc/localtime \
-e MYSQL_ROOT_PASSWORD=hadoop \
-d mysql:8.0.21

命令解释: -p 端口映射

--privileged=true 挂载文件权限设置

--restart unless-stopped 设置 开机后自动重启容器

-v /home/summer/mysql8/mysql:/etc/mysql 挂载配置文件

-v /home/summer/mysql8/logs:/logs \ 挂载日志

-v /home/summer/mysql8/data:/var/lib/mysql \ 挂载数据文件 持久化到主机,

-v /etc/localtime:/etc/localtime 容器时间与宿主机同步

-e MYSQL_ROOT_PASSWORD=hadoop 设置密码

-d mysql:8.0.21 后台启动,mysql

执行脚本 启动镜像

大功告成,挂载出来了数据文件以及配置文件实现数据持久化

ALTER USER "root"@"localhost" IDENTIFIED BY "hadoop";
FLUSH PRIVILEGES;
create user summer@'%' identified  by '123456';
grant all privileges on *.* to summer@'%' with grant option;
exit;
use mysql;
update user set host = '%' where user ='summer'; 
ALTER USER 'summer'@'%' IDENTIFIED BY 'password' PASSWORD EXPIRE NEVER;
ALTER USER 'summer'@'%' IDENTIFIED WITH mysql_native_password BY '123456';
exit;

方式二:正常tar包安装

上传安装包并解压
root in summer in /home/soft 
❯ ll
total 473712
-r-------- 1 root root 485074552 May 17 09:51 mysql-8.0.19-linux-glibc2.12-x86_64.tar.xz
root in summer in /home/soft 
➜ du -sh *
463M    mysql-8.0.19-linux-glibc2.12-x86_64.tar.xz
root in summer in /home/soft 
➜ tar -xvf mysql-8.0.19-linux-glibc2.12-x86_64.tar.xz
移动重命名
root in summer in /home/soft took 2m 
➜ ll
total 473716
drwxr-xr-x 9 root root      4096 May 17 10:43 mysql-8.0.19-linux-glibc2.12-x86_64
-r-------- 1 root root 485074552 May 17 09:51 mysql-8.0.19-linux-glibc2.12-x86_64.tar.xz
root in summer in /home/soft 
➜ mv mysql-8.0.19-linux-glibc2.12-x86_64 /usr/local/
root in summer in /home/soft 
➜ cd /usr/local/ && mv mysql-8.0.19-linux-glibc2.12-x86_64/ mysql
root in summer in /usr/local 
➜ ll
total 60
drwxr-xr-x  9 nobody nobody 4096 Apr 25 10:27 ats
drwxr-xr-x. 3 root   root   4096 Apr 25 12:14 bin
drwxr-xr-x. 4 root   root   4096 Apr 25 12:12 etc
drwxr-xr-x. 2 root   root   4096 Apr 11  2018 games
drwxr-xr-x. 5 root   root   4096 Apr 25 10:51 include
drwxr-xr-x. 5 root   root   4096 Apr 25 10:51 lib
drwxr-xr-x. 2 root   root   4096 Apr 11  2018 lib64
drwxr-xr-x. 2 root   root   4096 Apr 11  2018 libexec
drwxr-xr-x  2 root   root   4096 Apr 25 10:27 man
drwxr-xr-x  9 root   root   4096 May 17 10:43 mysql
lrwxrwxrwx  1 root   root     20 Apr 25 10:52 python374 -> /usr/local/python377
drwxr-xr-x  6 root   root   4096 Apr 25 10:52 python377
drwxr-xr-x. 2 root   root   4096 Apr 25 10:51 sbin
drwxr-xr-x. 7 root   root   4096 Apr 25 10:51 share
drwxr-xr-x. 2 root   root   4096 Apr 11  2018 src
drwxr-xr-x  3 root   root   4096 Apr 25 10:51 var
root in summer in /usr/local 
➜ 
新增mysql用户
root in summer in /usr/local 
➜ cd mysql/
root in summer in /usr/local/mysql 
➜ ll
total 432
drwxr-xr-x  2 7161 31415   4096 Dec 10  2019 bin
drwxr-xr-x  2 7161 31415   4096 Dec 10  2019 docs
drwxr-xr-x  3 7161 31415   4096 Dec 10  2019 include
drwxr-xr-x  6 7161 31415   4096 Dec 10  2019 lib
-rw-r--r--  1 7161 31415 405571 Dec 10  2019 LICENSE
drwxr-xr-x  4 7161 31415   4096 Dec 10  2019 man
-rw-r--r--  1 7161 31415    687 Dec 10  2019 README
drwxr-xr-x 28 7161 31415   4096 Dec 10  2019 share
drwxr-xr-x  2 7161 31415   4096 Dec 10  2019 support-files
root in summer in /usr/local/mysql 
➜ mkdir data
root in summer in /usr/local/mysql 
➜ groupadd mysql
root in summer in /usr/local/mysql 
➜ useradd -g mysql mysql
root in summer in /usr/local/mysql 
➜ chown -R mysql:mysql /usr/local/mysql/
root in iscloud163-200 in /usr/local/etc 
❯ mkdir /var/log/mariadb
root in iscloud163-200 in /usr/local/etc 
➜ touch /var/log/mariadb/mariadb.log
root in iscloud163-200 in /usr/local/etc 
➜ chown -R mysql:mysql /var/log/mariadb/
初始化
root in summer in /usr/local/mysql 
➜ /usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
2021-05-17T02:46:09.950578Z 0 [Warning] [MY-011070] [Server] 'Disabling symbolic links using --skip-symbolic-links (or equivalent) is the default. Consider not using this option as it' is deprecated and will be removed in a future release.
2021-05-17T02:46:09.950757Z 0 [System] [MY-013169] [Server] /usr/local/mysql/bin/mysqld (mysqld 8.0.19) initializing of server in progress as process 1868276
2021-05-17T02:46:18.144914Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: bkXul9__qP*8
修改配置文件
  • 注意skip-grant-tables该参数为修改root密码
root in summer in ~ 
➜ cat /etc/my.cnf
[mysqld]
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
port=23306
user=mysql
socket=/tmp/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd
#skip-grant-tables
 
[mysqld_safe]
log-error=/var/log/mariadb/mariadb.log
pid-file=/var/run/mariadb/mariadb.pid
 
#
# include all files from the config directory
#
!includedir /etc/my.cnf.d
添加系统服务
root in summer in /usr/local/mysql 
❯ cp -a /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
root in summer in /usr/local/mysql 
➜ chmod +x /etc/rc.d/init.d/mysqld
root in summer in /usr/local/mysql 
➜ chkconfig --add mysqld
配置环境变量
❯ vim /etc/profile
root in summer in /usr/local/mysql took 16s 
➜ source /etc/profile
root in summer in /usr/local/mysql 
❯ ln -s /usr/local/mysql/bin/mysql /usr/bin
root in summer in /usr/local/mysql 
➜ ln -s /usr/local/mysql/bin/mysqld /usr/bin
定义root密码
root in summer in /usr/local/mysql 
➜ /etc/init.d/mysqld restart
MySQL server PID file could not be found!                  [FAILED]
Starting MySQL.....                                        [  OK  ]
root in summer in /usr/local/mysql 
➜ mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 8.0.19 MySQL Community Server - GPL
 
Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
 
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> 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> update user set authentication_string='' where user='root';
Query OK, 1 row affected (0.01 sec)
Rows matched: 1  Changed: 1  Warnings: 0
 
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
 
mysql> ALTER user 'root'@'localhost' IDENTIFIED BY 'hadoop';
Query OK, 0 rows affected (0.18 sec)
 
mysql> \q
Bye
 
root in summer in /usr/local/mysql took 2m37s 
➜ vim /etc/my.cnf  ##这里注释掉skip-grant-tables
root in summer in /usr/local/mysql took 10s 
➜ /etc/init.d/mysqld restart
Shutting down MySQL..                                      [  OK  ]
Starting MySQL...                                          [  OK  ]
验证版本并登录
root in summer in local/mysql/data 
➜ ps -ef | grep mysql
root     1945961       1  0 11:01 ?        00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/usr/local/mysql/data --pid-file=/usr/local/mysql/data/summer.pid
mysql    1946194 1945961  0 11:01 ?        00:00:10 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/var/log/mariadb/mariadb.log --pid-file=/usr/local/mysql/data/summer.pid --socket=/tmp/mysql.sock --port=23306
root     2075003 2049242  0 11:39 pts/3    00:00:00 grep --color=auto mysql
root in summer in /usr/local/mysql 
❯ mysql -V
mysql  Ver 8.0.19 for linux-glibc2.12 on x86_64 (MySQL Community Server - GPL)
root in summer in /usr/local/mysql took 6s 
➜ mysql -u root -p 
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.19 MySQL Community Server - GPL
 
Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
 
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驱动jar包

进入官网 MySQL 点击DOWNLOADS

mysql8安装和驱动jar包下载_第2张图片

然后拉到最下面,点击MySQL Community(GPL) Downloads

mysql8安装和驱动jar包下载_第3张图片

然后选择Connector/J,这里的J是Java的意思

mysql8安装和驱动jar包下载_第4张图片

这里如果是windows用户的话,选择Platform Independent,如果是其他用户就选其他版本

mysql8安装和驱动jar包下载_第5张图片

点击Download

mysql8安装和驱动jar包下载_第6张图片

mysql8安装和驱动jar包下载_第7张图片

最后感谢每一个认真阅读我文章的人,礼尚往来总是要有的,虽然不是什么很值钱的东西,如果你用得到的话可以直接拿走:

这些资料,对于【软件测试】的朋友来说应该是最全面最完整的备战仓库,这个仓库也陪伴上万个测试工程师们走过最艰难的路程,希望也能帮助到你!

你可能感兴趣的:(软件测试,软件测试工程师,自动化测试,jar,java,职场和发展,软件测试,功能测试,自动化测试,程序人生)