当前位置:网站首页>Install MySQL in docker and modify my CNF profile
Install MySQL in docker and modify my CNF profile
2022-06-24 12:20:00 【Full stack development dream】
Preface
Previous experience MySQL After master-slave replication , Find out database Is very slow to read and write , And it happens all the time MySQL Too few connections , A situation that causes the entire database to crash . By modifying the MySQL Medium my.cnf Profile parameters , In order to achieve MySQL Rational use of the maximum performance of relational database .
This article is divided into three aspects to tell :
One 、Docker install MySQL
see mysql Mirror image
sudo docker search mysql
Pull mysql
sudo docker pull mysql
# Default to the latest version ( Customizable 5.7)
Create a container , And test the , Reference link
sudo docker run --name mysql -e MYSQL\_ROOT\_PASSWORD=123456 -p 3306:3306 -d mysqlTwo 、 Connect MySQL
docker Into mysql Container method
1)sudo docker exec -it Container name bash
2)mysql -uroot -p
3)use mysql
4)select host, user from user; see root user
Judge root Is there a , If there are two, delete them first delete from user where host="%" and user="root";
Revise update user set host = '%' where user = 'root';
Refresh the permissions FLUSH PRIVILEGES;
Grant remote access alter user 'root'@'%' identified with mysql\_native\_password by '123456';3、 ... and 、 Modify configuration file parameters
1. Once the download is complete , Input docker ps Look at the mirror image
2. Start the container :docker run -p 3307:3306 --name mysql -e MYSQL\_ROOT\_PASSWORD=root -d mysql,docker ps You can view the status
3. Get into MySQL In container :docker exec -it Container name /bin/bash(PS: In fact, this one follows Linux It's the same as modifying a file , There are many ways , I use the most stupid one .) Replace local file with container file
4. What I want to change here is MySQL Inside my.cnf file . You can use it first ls Look at the catalog file (PS: ls Command to display the contents of the current directory )
5.tail my.cnfPS:tail The command can be used to view the contents of a file )
6. function vim Code
vim /etc/mysql/my.cnf
7. Run the above vim After the code, you may find that it did not execute successfully , because docker There is no... In the container vim Editor , So you have to install it yourself vim Editor (vim Details of installation methods can be found at the end of the article appendix )
8. Get into my.cnf file
9. Add or modify the configuration according to your own needs , My modified configuration is as follows ( For reference )
10. Enclosed MySQL Some key parameters of database performance optimization
Key parameter one :back\_log
requirement MySQL The number of connections you can have . Be the main MySQL Threads get a lot of connection requests in a short time , It works , Then the main thread takes some time ( Short as it is ) Check the connection and start a new thread .
back_log The value is in MySQL How many requests can be stored in the stack in a short period of time before you temporarily stop answering new requests . Only if you expect a lot of connections in a short time , You need to add it , let me put it another way , It's worth the coming TCP/IP The size of the listening queue for the connection . Your operating system has its own limit on the size of this queue . Try to set back_log Higher than the limit of your operating system will be invalid .
When you look at your host process list , Find a lot 264084 | unauthenticated user | xxx.xxx.xxx.xxx | NULL | Connect | NULL | login | NULL To connect to the process , It's going to increase back_log The value of the . The default value is 50, I changed it to 500.
Key parameter 2 :interactive\_timeout
The number of seconds the server waits for action on an interactive connection before shutting it down . An interactive client is defined as being right mysql_real_connect() Use CLIENT_INTERACTIVE Option customers . The default value is 28800, I changed it to 7200.
Key parameter three :key\_buffer\_size
The index block is buffered and shared by all threads .key_buffer_size Is the buffer size for the index block , Add it to get better indexes ( For all read and multiply Write ), To you Can afford that much . If you make it too big , The system will start to change pages and really slow down . The default value is 8388600(8M), my MySQL The main engine has 2GB Memory , So I changed it to 402649088(400MB).
Key parameter four :max\_connections
The number of customers allowed at the same time . Increase this value by mysqld Number of file descriptors required . This number should be increased , otherwise , You will often see Too many connections error . The default value is 100, I changed it to 1024 .
Key parameter five :record\_buffer
Each thread that performs a sequential scan allocates a buffer of this size for each table it scans . If you do a lot of sequential scanning , You may want to increase the value . The default value is 131072(128K), I changed it to 16773120 (16M)
Key parameter six :sort\_buffer
Each thread that needs to be sorted allocates a buffer of that size . Increase this value to accelerate ORDER BY or GROUP BY operation . The default value is 2097144(2M), I changed it to 16777208 (16M).
Key parameter 7 :table\_cache
Number of open tables for all threads . Increasing this value increases mysqld Number of file descriptors required .MySQL For each uniquely open table, you need 2 File descriptors . The default value is 64, I changed it to 512.
Key parameter eight :thread\_cache\_size
The number of threads that can be reused in . If there is , The new thread gets... From the cache , When disconnected, if there is space , The customer's line is in the cache . If there are many new threads , In order to improve the Performance is acceptable With this variable value . By comparison Connections and Threads_created Variables of state , You can see the effect of this variable . I set it to 80.
Key parameter 9 :wait\_timeout
The number of seconds the server waits for action on a connection before shutting it down . The default value is 28800, I changed it to 7200.
notes : Parameters can be adjusted by modifying /etc/my.cnf File and restart MySQL Realization . This is a more cautious job , The above results are just my opinions , According to the hardware of your own host ( Especially the memory size ) Further modification .
11. Use after modification :wq Preservation
12. Reuse tail Check whether the file is modified correctly
tail /etc/mysql/my.cnf
13. After the configuration file is modified successfully , You can use it to your heart's content MySQL La !(PS: Because of the limitation of the original design intention of the relational database , In massive data processing and multi table function query, we will encounter I/O Performance bottleneck . So it has distributed 、 High performance 、 High reliability and other characteristics of non relational database (NoSQL) Gradually understood and used by people , It makes up for the congenital deficiency of relational database performance , There's a huge advantage in storing unstructured data . Main stream NoSQL The database has :Redis、MongoDB and HBase etc. )
appendix
vim Download and install the editor
In the use of docker When the container , Sometimes it's not installed inside vim, function vim The prompt says :vim: command not found, This is the time to install vim, When you run the following installation command :
apt-get install vim
Error Wrong presentation :
Reading package lists… Done Building dependency tree Reading state information… Done E: Unable to locate package vim
according to apt Command to download and install software , We need to be right about apt updated !!!
apt-get update
The above command is to synchronize /etc/apt/sources.list and /etc/apt/sources.list.d Index of the source listed in , In this way, we can get the latest software package .
Wait for the update to complete before running the command :
apt-get install vim
vim /etc/mysql/mysql.conf.d/mysqld.cnf
1.apt-get install vim
2.apt-get update
3. complete vim Editor installation
边栏推荐
- Deep parsing and implementation of redis pub/sub publish subscribe mode message queue
- GLOG from getting started to getting started
- Embedded must learn! Detailed explanation of hardware resource interface - based on arm am335x development board (Part 1)
- How to develop hospital information system (his) with SMS notification and voice function
- 《梦华录》要大结局了,看超前点映不如先来学学它!
- 《opencv学习笔记》-- 离散傅里叶变换
- 【206】使用php语言去生成go语言的代码
- qt -- QTabWidget 中支持拖拽TabBar项
- What code did the full stack programmer write this month?
- What are the low threshold financial products in 2022? Not much money
猜你喜欢

u盘安装kali并且持久化

How to develop hospital information system (his) with SMS notification and voice function

链接器 --- Linker

我真傻,招了一堆只会“谷歌”的程序员!

工具及方法 - 在Source Insight中使用代码格式化工具

Group planning - General Review

How stupid of me to hire a bunch of programmers who can only "Google"!
[mysql_16] variables, process control and cursors

QT -- the qtabwidget supports dragging tabbar items

GTest从入门到入门
随机推荐
怎样购买打新债 开户是安全的吗
【老卫搞机】090期:键盘?主机?全功能键盘主机!
Is it safe to apply for new bonds to open an account
Variable parameter template implements max (accepts multiple parameters, two implementation methods)
Google Earth engine (GEE) - how to add a legend in the map panel
Nacos source code - Interface read configuration
What code did the full stack programmer write this month?
怎样申购打新债 开户是安全的吗
【云驻共创】解读HarmonyOS 应用与服务生态
About the unsupported instruction set SSE 4.2 of CPU in virtualization
5 points + single gene pan cancer pure Shengxin idea!
JVM GC garbage collection detailed introduction quick check of learning notes
【数字IC/FPGA】Booth乘法器
[live review] battle code pioneer phase 7: how third-party application developers contribute to open source
Qt: judge whether the string is in numeric format
Opencv learning notes - loading and saving images
Programmers spend most of their time not writing code, but...
10 zeros of D
怎么可以打新债 开户是安全的吗
9+!通过深度学习从结直肠癌的组织学中预测淋巴结状态