1 MySQL8绿色版

本文目标

制作一个MySQL8的绿色版,以后解压即用,方便进行测试部署。
默认用户名root,密码root,仅限本机登录
默认用户名test,密码test,任意机器登录
默认数据库test
注意弱口令风险

下载原版MySQL8

mysql-8.0.31-el7-x86_64.tar.gz
https://dev.mysql.com/downloads/mysql/

解压文件

tar xfz mysql-8.0.31-el7-x86_64.tar.gz
drwxr-xr-x.  2 yinyx yinyx   4096 Dec  2 07:09 bin
drwxr-xr-x.  2 yinyx yinyx     55 Sep 14 01:50 docs
drwxr-xr-x.  3 yinyx yinyx   4096 Sep 14 01:50 include
drwxr-xr-x.  6 yinyx yinyx    201 Sep 14 01:50 lib
-rw-r--r--.  1 yinyx yinyx 287627 Sep 14 00:15 LICENSE
drwxr-xr-x.  4 yinyx yinyx     30 Sep 14 01:50 man
-rw-r--r--.  1 yinyx yinyx    666 Sep 14 00:15 README
drwxr-xr-x. 28 yinyx yinyx   4096 Sep 14 01:50 share
drwxr-xr-x.  2 yinyx yinyx     77 Sep 14 01:50 support-files

文件瘦身

进入bin目录执行

[yinyx@localhost bin]$ strip *
strip:mysql_config: File format not recognized
strip:mysqld_multi: File format not recognized
strip:mysqld_safe: File format not recognized
strip:mysqldumpslow: File format not recognized
[yinyx@localhost bin]$ du -sh *
6.5M	ibd2sdi
6.4M	innochecksum
6.3M	lz4_decompress
6.6M	myisamchk
6.5M	myisam_ftdump
6.5M	myisamlog
6.5M	myisampack
6.3M	my_print_defaults
7.5M	mysql
7.2M	mysqladmin
7.6M	mysqlbinlog
7.2M	mysqlcheck
8.0K	mysql_config
6.3M	mysql_config_editor
61M	mysqld
104M	mysqld-debug
28K	mysqld_multi
32K	mysqld_safe
7.3M	mysqldump
8.0K	mysqldumpslow
7.2M	mysqlimport
7.3M	mysql_migrate_keyring
7.8M	mysqlpump
7.2M	mysql_secure_installation
7.2M	mysqlshow
7.2M	mysqlslap
6.3M	mysql_ssl_rsa_setup
6.2M	mysql_tzinfo_to_sql
7.3M	mysql_upgrade
7.0M	perror
6.2M	zlib_decompress
[yinyx@localhost bin]$ pwd
/home/yinyx/mysql-8.0.31-el7-x86_64/bin
[yinyx@localhost bin]$ rm -f mysqld-debug 

strip 是用来清除C程序调试信息的。
mysqld-debug是调试MySQL用的,平时用不到,并且很大,删除掉。

初始化数据库

./bin/mysqld --defaults-file=./my.cnf --initialize-insecure --basedir="./" --datadir="./data" --socket="./bin/mysql.sock" --pid-file="./bin/mysql.pid" --console
2022-12-01T23:25:46.849158Z 0 [Warning] [MY-010139] [Server] Changed limits: max_open_files: 1024 (requested 9010)
2022-12-01T23:25:46.849166Z 0 [Warning] [MY-010141] [Server] Changed limits: max_connections: 214 (requested 1000)
2022-12-01T23:25:46.849174Z 0 [Warning] [MY-010142] [Server] Changed limits: table_open_cache: 400 (requested 4000)
2022-12-01T23:25:46.852398Z 0 [Warning] [MY-010918] [Server] 'default_authentication_plugin' is deprecated and will be removed in a future releuse authentication_policy instead.
2022-12-01T23:25:46.852425Z 0 [System] [MY-013169] [Server] /home/yinyx/mysql-8.0.31-el7-x86_64-green/bin/mysqld (mysqld 8.0.31) initializing oprogress as process 19432
2022-12-01T23:25:46.887651Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2022-12-01T23:25:47.547489Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2022-12-01T23:25:49.142124Z 6 [Warning] [MY-010453] [Server] root@localhost is created with an empty password ! Please consider switching off tize-insecure option.

配置my.cnf

[mysqld]
# 设置3306端口
port=3306
# 设置mysql的安装目录
basedir=/usr/local/mysql
# 设置mysql数据库的数据的存放目录
datadir=/usr/local/mysql/mysqldb
# 允许最大连接数
max_connections=1000
# 允许连接失败的次数。这是为了防止有人从该主机试图攻击数据库系统
max_connect_errors=100
# 服务端使用的字符集默认为UTF8
character-set-server=utf8mb4
# 创建新表时将使用的默认存储引擎
default-storage-engine=INNODB
# 默认使用“mysql_native_password”插件认证
default_authentication_plugin=mysql_native_password
#是否对sql语句大小写敏感,1表示不敏感
lower_case_table_names = 1
#MySQL连接闲置超过一定时间后(单位:秒)将会被强行关闭
#MySQL默认的wait_timeout  值为8个小时, interactive_timeout参数需要同时配置才能生效
interactive_timeout = 1800
wait_timeout = 1800
#Metadata Lock最大时长(秒), 一般用于控制 alter操作的最大时长sine mysql5.6
#执行 DML操作时除了增加innodb事务锁外还增加Metadata Lock,其他alter(DDL)session将阻塞
lock_wait_timeout = 3600
#内部内存临时表的最大值。
#比如大数据量的group by ,order by时可能用到临时表,
#超过了这个值将写入磁盘,系统IO压力增大
tmp_table_size = 64M
max_heap_table_size = 64M
[mysql]
# 设置mysql客户端默认字符集
default-character-set=utf8mb4
[client]
# 设置mysql客户端连接服务端时默认使用的端口
port=3306
default-character-set=utf8mb4

配置启停脚本

上传mysql的shell文件后执行:

[yinyx@localhost mysql-8.0.31-el7-x86_64-green]$ ./mysql start
Starting MySQL ... SUCCESS! 
[yinyx@localhost mysql-8.0.31-el7-x86_64-green]$ netstat -lntp
(Not all processes could be identified, non-owned process info
 will not be shown, you would have to be root to see it all.)
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      -                   
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      -                   
tcp6       0      0 ::1:25                  :::*                    LISTEN      -                   
tcp6       0      0 :::6306                 :::*                    LISTEN      19900/mysqld        
tcp6       0      0 :::33060                :::*                    LISTEN      19900/mysqld        
tcp6       0      0 :::22                   :::*                    LISTEN      -                   

进入MySQL命令行,修改数据库默认设置

./bin/mysql  --defaults-file=./my.cnf --socket=./data/mysql.sock -h localhost -u root -p

默认密码为空,回车直接进入MySQL命令行

mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'root';
Query OK, 0 rows affected (0.00 sec)

mysql> CREATE DATABASE test;
Query OK, 1 row affected (0.01 sec)

mysql> create user 'test'@'%' identified by 'test';
Query OK, 0 rows affected (0.01 sec)

mysql> grant all on *.* to 'test'@'%';
Query OK, 0 rows affected (0.01 sec)

mysql> 

创建cmd.sh

[yinyx@localhost mysql-8.0.31-el7-x86_64-green]$ cat cmd.sh

./bin/mysql  --defaults-file=./my.cnf --socket=./data/mysql.sock -h localhost -u test -ptest test

[yinyx@localhost mysql-8.0.31-el7-x86_64-green]$ ./cmd.sh
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 11
Server version: 8.0.31 MySQL Community Server - GPL

Copyright (c) 2000, 2022, 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 stop

打包绿色版

tar cfz mysql-8.0.31-el7-x86_64-green.tar.gz mysql-8.0.31-el7-x86_64-green

制作轻量版

删除bin目录不常用工具,只保留
mysqld --主程序
mysqld_safe --启动shell
mysql --命令行客户端
my_print_defaults --启动使用
mysqldump --备份数据库

总结

[yinyx@localhost ~]$ du -sh *
945M	mysql-8.0.31-el7-x86_64
493M	mysql-8.0.31-el7-x86_64.tar.gz
663M	mysql-8.0.31-el7-x86_64-green
158M	mysql-8.0.31-el7-x86_64-green.tar.gz
357M	mysql-8.0.31-el7-x86_64-lite
56M	mysql-8.0.31-el7-x86_64-lite.tar.gz

原版493MB

green版158MB,功能一个没少,只是体积变小了,并且带了初始化好的data数据库

lite版56MB,作为测试环境Server已经够用了,数据库启停相关功能都有,只是缺少解决数据库异常情况下的相关工具。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值